Skip to content

Commit 233ed4f

Browse files
authored
fix intorstring for strings (#27)
1 parent ef5208c commit 233ed4f

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

integration_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,46 @@ func TestIntegration(t *testing.T) {
305305
Type: v1.ServiceTypeLoadBalancer,
306306
},
307307
}),
308+
NewTestDiff("service with named port diffs with existing",
309+
&v1.Service{
310+
ObjectMeta: standardObjectMeta(),
311+
Spec: v1.ServiceSpec{
312+
Ports: []v1.ServicePort{
313+
{
314+
Name: "http",
315+
Protocol: v1.ProtocolTCP,
316+
Port: 80,
317+
TargetPort: intstr.FromString("http"),
318+
},
319+
},
320+
Selector: map[string]string{
321+
"app": "test",
322+
},
323+
Type: v1.ServiceTypeLoadBalancer,
324+
},
325+
}).
326+
withLocalChange(func(a interface{}) {
327+
b := a.(*v1.Service)
328+
b.Spec.Ports[0].TargetPort = intstr.FromString("https")
329+
}),
330+
NewTestMatch("service with named port matches with original",
331+
&v1.Service{
332+
ObjectMeta: standardObjectMeta(),
333+
Spec: v1.ServiceSpec{
334+
Ports: []v1.ServicePort{
335+
{
336+
Name: "http",
337+
Protocol: v1.ProtocolTCP,
338+
Port: 80,
339+
TargetPort: intstr.FromString("http"),
340+
},
341+
},
342+
Selector: map[string]string{
343+
"app": "test",
344+
},
345+
Type: v1.ServiceTypeLoadBalancer,
346+
},
347+
}),
308348
NewTestMatch("service matches with original even if defaults are not set",
309349
&v1.Service{
310350
ObjectMeta: standardObjectMeta(),

patch/deletenull.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,18 @@ func init() {
7272
func(ptr unsafe.Pointer, stream *json.Stream) {
7373
i := (*intstr.IntOrString)(ptr)
7474
if i.IntValue() == 0 {
75-
stream.WriteNil()
75+
if i.StrVal != "" && i.StrVal != "0" {
76+
stream.WriteString(i.StrVal)
77+
} else {
78+
stream.WriteNil()
79+
}
7680
} else {
7781
stream.WriteInt(i.IntValue())
7882
}
7983
},
8084
func(ptr unsafe.Pointer) bool {
8185
i := (*intstr.IntOrString)(ptr)
82-
return i.IntValue() == 0
86+
return i.IntValue() == 0 && (i.StrVal == "" || i.StrVal == "0")
8387
},
8488
)
8589
}

0 commit comments

Comments
 (0)