Skip to content

Commit 9380fe7

Browse files
committed
Do not remove false bool values
1 parent 93c4268 commit 9380fe7

File tree

3 files changed

+157
-7
lines changed

3 files changed

+157
-7
lines changed

patch/deletenull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func isZero(v reflect.Value) bool {
257257
default:
258258
z := reflect.Zero(v.Type())
259259
return v.Interface() == z.Interface()
260-
case reflect.Float64, reflect.Int64:
260+
case reflect.Float64, reflect.Int64, reflect.Bool:
261261
return false
262262
case reflect.Func, reflect.Map, reflect.Slice:
263263
return v.IsNil()

tests/integration_test.go

Lines changed: 152 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,148 @@ func TestIntegration(t *testing.T) {
5959
},
6060
},
6161
}),
62+
NewTestDiff("pod does not match if a bool pointer value is explicitly set locally (false)",
63+
&v1.Pod{
64+
ObjectMeta: standardObjectMeta(),
65+
Spec: v1.PodSpec{
66+
Containers: []v1.Container{
67+
{
68+
Name: "test-container", Image: "test-image",
69+
},
70+
},
71+
Volumes: []v1.Volume{
72+
{
73+
Name: "empty",
74+
VolumeSource: v1.VolumeSource{
75+
EmptyDir: &v1.EmptyDirVolumeSource{},
76+
},
77+
},
78+
},
79+
},
80+
}).
81+
withLocalChange(func(i interface{}) {
82+
pod := i.(*v1.Pod)
83+
pod.Spec.AutomountServiceAccountToken = boolRef(false)
84+
}),
85+
NewTestMatch("pod does match if a bool pointer value is set only remotely, since we don't set it locally (true)",
86+
&v1.Pod{
87+
ObjectMeta: standardObjectMeta(),
88+
Spec: v1.PodSpec{
89+
Containers: []v1.Container{
90+
{
91+
Name: "test-container", Image: "test-image",
92+
},
93+
},
94+
Volumes: []v1.Volume{
95+
{
96+
Name: "empty",
97+
VolumeSource: v1.VolumeSource{
98+
EmptyDir: &v1.EmptyDirVolumeSource{},
99+
},
100+
},
101+
},
102+
},
103+
}).
104+
withRemoteChange(func(i interface{}) {
105+
pod := i.(*v1.Pod)
106+
pod.Spec.AutomountServiceAccountToken = boolRef(true)
107+
}),
108+
NewTestMatch("pod does match if a bool pointer value is set only remotely, since we don't set it locally (false)",
109+
&v1.Pod{
110+
ObjectMeta: standardObjectMeta(),
111+
Spec: v1.PodSpec{
112+
Containers: []v1.Container{
113+
{
114+
Name: "test-container", Image: "test-image",
115+
},
116+
},
117+
Volumes: []v1.Volume{
118+
{
119+
Name: "empty",
120+
VolumeSource: v1.VolumeSource{
121+
EmptyDir: &v1.EmptyDirVolumeSource{},
122+
},
123+
},
124+
},
125+
},
126+
}).
127+
withRemoteChange(func(i interface{}) {
128+
pod := i.(*v1.Pod)
129+
pod.Spec.AutomountServiceAccountToken = boolRef(false)
130+
}),
131+
NewTestDiff("pod does not match if a bool pointer value is set remotely by a defaulter but a different value locally",
132+
&v1.Pod{
133+
ObjectMeta: standardObjectMeta(),
134+
Spec: v1.PodSpec{
135+
Containers: []v1.Container{
136+
{
137+
Name: "test-container", Image: "test-image",
138+
},
139+
},
140+
Volumes: []v1.Volume{
141+
{
142+
Name: "empty",
143+
VolumeSource: v1.VolumeSource{
144+
EmptyDir: &v1.EmptyDirVolumeSource{},
145+
},
146+
},
147+
},
148+
},
149+
}).
150+
withRemoteChange(func(i interface{}) {
151+
pod := i.(*v1.Pod)
152+
pod.Spec.AutomountServiceAccountToken = boolRef(true)
153+
}).
154+
withLocalChange(func(i interface{}) {
155+
pod := i.(*v1.Pod)
156+
pod.Spec.AutomountServiceAccountToken = boolRef(false)
157+
}),
158+
NewTestDiff("pod does not match if a bool value is set locally (true)",
159+
&v1.Pod{
160+
ObjectMeta: standardObjectMeta(),
161+
Spec: v1.PodSpec{
162+
Containers: []v1.Container{
163+
{
164+
Name: "test-container", Image: "test-image",
165+
},
166+
},
167+
Volumes: []v1.Volume{
168+
{
169+
Name: "empty",
170+
VolumeSource: v1.VolumeSource{
171+
EmptyDir: &v1.EmptyDirVolumeSource{},
172+
},
173+
},
174+
},
175+
},
176+
}).
177+
withLocalChange(func(i interface{}) {
178+
pod := i.(*v1.Pod)
179+
pod.Spec.HostIPC = true
180+
}),
181+
NewTestMatch("pod does match if a bool pointer value is set only remotely (true)",
182+
&v1.Pod{
183+
ObjectMeta: standardObjectMeta(),
184+
Spec: v1.PodSpec{
185+
Containers: []v1.Container{
186+
{
187+
Name: "test-container", Image: "test-image",
188+
},
189+
},
190+
Volumes: []v1.Volume{
191+
{
192+
Name: "empty",
193+
VolumeSource: v1.VolumeSource{
194+
EmptyDir: &v1.EmptyDirVolumeSource{},
195+
},
196+
},
197+
},
198+
},
199+
}).
200+
withRemoteChange(func(i interface{}) {
201+
pod := i.(*v1.Pod)
202+
pod.Spec.HostIPC = true
203+
}),
62204
NewTestDiff("pod does not match when a slice item gets removed",
63205
&v1.Pod{
64206
ObjectMeta: standardObjectMeta(),
@@ -732,20 +874,20 @@ func TestIntegration(t *testing.T) {
732874
Spec: v1.PodSpec{
733875
Containers: []v1.Container{
734876
{
735-
Name: "test-container",
736-
Image: "test-image",
877+
Name: "test-container",
878+
Image: "test-image",
737879
},
738880
},
739881
},
740882
}).
741883
withRemoteChange(func(i interface{}) {
742-
pod := i.(*v1.Pod)
743-
pod.Labels = map[string]string{"a": "b"}
744-
}).
884+
pod := i.(*v1.Pod)
885+
pod.Labels = map[string]string{"a": "b"}
886+
}).
745887
withLocalChange(func(i interface{}) {
746888
pod := i.(*v1.Pod)
747889
pod.Labels = map[string]string{"c": "d"}
748-
}),
890+
}),
749891
}
750892
runAll(t, tests)
751893
}
@@ -813,3 +955,7 @@ func scopeRef(scopeType admregv1beta1.ScopeType) *admregv1beta1.ScopeType {
813955
func volumeModeRef(mode v1.PersistentVolumeMode) *v1.PersistentVolumeMode {
814956
return &mode
815957
}
958+
959+
func boolRef(b bool) *bool {
960+
return &b
961+
}

tests/main_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ func (ctx *IntegrationTestContext) Setup() error {
112112
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigOverride},
113113
&clientcmd.ConfigOverrides{CurrentContext: *kubecontext},
114114
).ClientConfig()
115+
116+
config.Burst = 100
117+
config.QPS = 100
118+
115119
if err != nil {
116120
return err
117121
}

0 commit comments

Comments
 (0)