Skip to content

Commit af5ddf9

Browse files
committed
fixup! fix: Prevent unnecessary rollout
1 parent e026124 commit af5ddf9

File tree

2 files changed

+211
-104
lines changed

2 files changed

+211
-104
lines changed

pkg/handlers/generic/mutation/parallelimagepulls/inject.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,17 @@ func (h *maxParallelImagePullsPerNode) Mutate(
7878
h.variableName,
7979
h.variableFieldPath...,
8080
)
81-
switch {
82-
case err != nil && !variables.IsNotFoundError(err):
81+
if err != nil {
82+
if variables.IsNotFoundError(err) {
83+
log.V(5).Info("max parallel image pulls is not set, skipping mutation")
84+
return nil
85+
}
8386
return err
84-
case variables.IsNotFoundError(err):
85-
log.V(5).Info("max parallel image pulls is not set, using default value of 1")
86-
maxParallelImagePullsPerNode = 1
87+
}
88+
89+
if maxParallelImagePullsPerNode == 1 {
90+
log.V(5).Info("max parallel image pulls is set to 1, skipping mutation resulting in serialized image pulls")
91+
return nil
8792
}
8893

8994
log = log.WithValues(

pkg/handlers/generic/mutation/parallelimagepulls/inject_test.go

Lines changed: 201 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -44,25 +44,14 @@ var _ = DescribeTable("Generate max parallel image pulls patches",
4444
),
4545
},
4646
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
47-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
47+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
4848
{
4949
Operation: "add",
5050
Path: "/spec/template/spec/kubeadmConfigSpec/files",
51-
ValueMatcher: gomega.ConsistOf(
52-
gomega.SatisfyAll(
53-
gomega.HaveKeyWithValue(
54-
"path",
55-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
56-
),
57-
gomega.HaveKeyWithValue("owner", "root:root"),
58-
gomega.HaveKeyWithValue("permissions", "0644"),
59-
gomega.HaveKeyWithValue("content", `---
60-
apiVersion: kubelet.config.k8s.io/v1beta1
61-
kind: KubeletConfiguration
62-
serializeImagePulls: false
63-
maxParallelImagePulls: 1
64-
`,
65-
),
51+
ValueMatcher: gomega.ContainElement(
52+
gomega.HaveKeyWithValue(
53+
"path",
54+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
6655
),
6756
),
6857
},
@@ -76,25 +65,14 @@ maxParallelImagePulls: 1
7665
),
7766
},
7867
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
79-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
68+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
8069
{
8170
Operation: "add",
8271
Path: "/spec/template/spec/kubeadmConfigSpec/files",
83-
ValueMatcher: gomega.ConsistOf(
84-
gomega.SatisfyAll(
85-
gomega.HaveKeyWithValue(
86-
"path",
87-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
88-
),
89-
gomega.HaveKeyWithValue("owner", "root:root"),
90-
gomega.HaveKeyWithValue("permissions", "0644"),
91-
gomega.HaveKeyWithValue("content", `---
92-
apiVersion: kubelet.config.k8s.io/v1beta1
93-
kind: KubeletConfiguration
94-
serializeImagePulls: false
95-
maxParallelImagePulls: 1
96-
`,
97-
),
72+
ValueMatcher: gomega.ContainElement(
73+
gomega.HaveKeyWithValue(
74+
"path",
75+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
9876
),
9977
),
10078
},
@@ -108,25 +86,14 @@ maxParallelImagePulls: 1
10886
),
10987
},
11088
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
111-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
89+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
11290
{
11391
Operation: "add",
11492
Path: "/spec/template/spec/kubeadmConfigSpec/files",
115-
ValueMatcher: gomega.ConsistOf(
116-
gomega.SatisfyAll(
117-
gomega.HaveKeyWithValue(
118-
"path",
119-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
120-
),
121-
gomega.HaveKeyWithValue("owner", "root:root"),
122-
gomega.HaveKeyWithValue("permissions", "0644"),
123-
gomega.HaveKeyWithValue("content", `---
124-
apiVersion: kubelet.config.k8s.io/v1beta1
125-
kind: KubeletConfiguration
126-
serializeImagePulls: false
127-
maxParallelImagePulls: 1
128-
`,
129-
),
93+
ValueMatcher: gomega.ContainElement(
94+
gomega.HaveKeyWithValue(
95+
"path",
96+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
13097
),
13198
),
13299
},
@@ -146,25 +113,14 @@ maxParallelImagePulls: 1
146113
),
147114
},
148115
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
149-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
116+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
150117
{
151118
Operation: "add",
152-
Path: "/spec/template/spec/files",
153-
ValueMatcher: gomega.ConsistOf(
154-
gomega.SatisfyAll(
155-
gomega.HaveKeyWithValue(
156-
"path",
157-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
158-
),
159-
gomega.HaveKeyWithValue("owner", "root:root"),
160-
gomega.HaveKeyWithValue("permissions", "0644"),
161-
gomega.HaveKeyWithValue("content", `---
162-
apiVersion: kubelet.config.k8s.io/v1beta1
163-
kind: KubeletConfiguration
164-
serializeImagePulls: false
165-
maxParallelImagePulls: 1
166-
`,
167-
),
119+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
120+
ValueMatcher: gomega.ContainElement(
121+
gomega.HaveKeyWithValue(
122+
"path",
123+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
168124
),
169125
),
170126
},
@@ -184,25 +140,14 @@ maxParallelImagePulls: 1
184140
),
185141
},
186142
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
187-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
143+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
188144
{
189145
Operation: "add",
190-
Path: "/spec/template/spec/files",
191-
ValueMatcher: gomega.ConsistOf(
192-
gomega.SatisfyAll(
193-
gomega.HaveKeyWithValue(
194-
"path",
195-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
196-
),
197-
gomega.HaveKeyWithValue("owner", "root:root"),
198-
gomega.HaveKeyWithValue("permissions", "0644"),
199-
gomega.HaveKeyWithValue("content", `---
200-
apiVersion: kubelet.config.k8s.io/v1beta1
201-
kind: KubeletConfiguration
202-
serializeImagePulls: false
203-
maxParallelImagePulls: 1
204-
`,
205-
),
146+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
147+
ValueMatcher: gomega.ContainElement(
148+
gomega.HaveKeyWithValue(
149+
"path",
150+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
206151
),
207152
),
208153
},
@@ -222,25 +167,182 @@ maxParallelImagePulls: 1
222167
),
223168
},
224169
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
225-
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
170+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
226171
{
227172
Operation: "add",
228-
Path: "/spec/template/spec/files",
229-
ValueMatcher: gomega.ConsistOf(
230-
gomega.SatisfyAll(
231-
gomega.HaveKeyWithValue(
232-
"path",
233-
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
234-
),
235-
gomega.HaveKeyWithValue("owner", "root:root"),
236-
gomega.HaveKeyWithValue("permissions", "0644"),
237-
gomega.HaveKeyWithValue("content", `---
238-
apiVersion: kubelet.config.k8s.io/v1beta1
239-
kind: KubeletConfiguration
240-
serializeImagePulls: false
241-
maxParallelImagePulls: 1
242-
`,
243-
),
173+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
174+
ValueMatcher: gomega.ContainElement(
175+
gomega.HaveKeyWithValue(
176+
"path",
177+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
178+
),
179+
),
180+
},
181+
},
182+
}),
183+
Entry("max parallel image pulls set to 1 with AWS control plane", capitest.PatchTestDef{
184+
Vars: []runtimehooksv1.Variable{
185+
capitest.VariableWithValue(
186+
v1alpha1.ClusterConfigVariableName,
187+
v1alpha1.AWSClusterConfigSpec{
188+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
189+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
190+
},
191+
},
192+
),
193+
},
194+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
195+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
196+
{
197+
Operation: "add",
198+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
199+
ValueMatcher: gomega.ContainElement(
200+
gomega.HaveKeyWithValue(
201+
"path",
202+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
203+
),
204+
),
205+
},
206+
},
207+
}),
208+
Entry("max parallel image pulls set to 1 with Nutanix control plane", capitest.PatchTestDef{
209+
Vars: []runtimehooksv1.Variable{
210+
capitest.VariableWithValue(
211+
v1alpha1.ClusterConfigVariableName,
212+
v1alpha1.NutanixClusterConfigSpec{
213+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
214+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
215+
},
216+
},
217+
),
218+
},
219+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
220+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
221+
{
222+
Operation: "add",
223+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
224+
ValueMatcher: gomega.ContainElement(
225+
gomega.HaveKeyWithValue(
226+
"path",
227+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
228+
),
229+
),
230+
},
231+
},
232+
}),
233+
Entry("max parallel image pulls set to 1 with Docker control plane", capitest.PatchTestDef{
234+
Vars: []runtimehooksv1.Variable{
235+
capitest.VariableWithValue(
236+
v1alpha1.ClusterConfigVariableName,
237+
v1alpha1.DockerClusterConfigSpec{
238+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
239+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
240+
},
241+
},
242+
),
243+
},
244+
RequestItem: request.NewKubeadmControlPlaneTemplateRequestItem(""),
245+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
246+
{
247+
Operation: "add",
248+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
249+
ValueMatcher: gomega.ContainElement(
250+
gomega.HaveKeyWithValue(
251+
"path",
252+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
253+
),
254+
),
255+
},
256+
},
257+
}),
258+
Entry("max parallel image pulls set to 1 with AWS workers", capitest.PatchTestDef{
259+
Vars: []runtimehooksv1.Variable{
260+
capitest.VariableWithValue(
261+
v1alpha1.ClusterConfigVariableName,
262+
v1alpha1.AWSClusterConfigSpec{
263+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
264+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
265+
},
266+
},
267+
),
268+
capitest.VariableWithValue(
269+
runtimehooksv1.BuiltinsName,
270+
apiextensionsv1.JSON{
271+
Raw: []byte(`{"machineDeployment": {"class": "a-worker"}}`),
272+
},
273+
),
274+
},
275+
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
276+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
277+
{
278+
Operation: "add",
279+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
280+
ValueMatcher: gomega.ContainElement(
281+
gomega.HaveKeyWithValue(
282+
"path",
283+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
284+
),
285+
),
286+
},
287+
},
288+
}),
289+
Entry("max parallel image pulls set to 1 with Nutanix workers", capitest.PatchTestDef{
290+
Vars: []runtimehooksv1.Variable{
291+
capitest.VariableWithValue(
292+
v1alpha1.ClusterConfigVariableName,
293+
v1alpha1.NutanixClusterConfigSpec{
294+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
295+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
296+
},
297+
},
298+
),
299+
capitest.VariableWithValue(
300+
runtimehooksv1.BuiltinsName,
301+
apiextensionsv1.JSON{
302+
Raw: []byte(`{"machineDeployment": {"class": "a-worker"}}`),
303+
},
304+
),
305+
},
306+
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
307+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
308+
{
309+
Operation: "add",
310+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
311+
ValueMatcher: gomega.ContainElement(
312+
gomega.HaveKeyWithValue(
313+
"path",
314+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
315+
),
316+
),
317+
},
318+
},
319+
}),
320+
Entry("max parallel image pulls set to 1 with Docker workers", capitest.PatchTestDef{
321+
Vars: []runtimehooksv1.Variable{
322+
capitest.VariableWithValue(
323+
v1alpha1.ClusterConfigVariableName,
324+
v1alpha1.DockerClusterConfigSpec{
325+
KubeadmClusterConfigSpec: v1alpha1.KubeadmClusterConfigSpec{
326+
MaxParallelImagePullsPerNode: ptr.To(int32(1)),
327+
},
328+
},
329+
),
330+
capitest.VariableWithValue(
331+
runtimehooksv1.BuiltinsName,
332+
apiextensionsv1.JSON{
333+
Raw: []byte(`{"machineDeployment": {"class": "a-worker"}}`),
334+
},
335+
),
336+
},
337+
RequestItem: request.NewKubeadmConfigTemplateRequestItem(""),
338+
UnexpectedPatchMatchers: []capitest.JSONPatchMatcher{
339+
{
340+
Operation: "add",
341+
Path: "/spec/template/spec/kubeadmConfigSpec/files",
342+
ValueMatcher: gomega.ContainElement(
343+
gomega.HaveKeyWithValue(
344+
"path",
345+
"/etc/kubernetes/patches/kubeletconfigurationmaxparallelimagepulls+strategic.json",
244346
),
245347
),
246348
},

0 commit comments

Comments
 (0)