Skip to content

Commit 446e296

Browse files
committed
Set extraArgs in test extension
Signed-off-by: Stefan Büringer [email protected]
1 parent 3adb251 commit 446e296

File tree

2 files changed

+135
-10
lines changed

2 files changed

+135
-10
lines changed

test/extension/handlers/topologymutation/handler.go

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ func (h *ExtensionHandlers) GeneratePatches(ctx context.Context, req *runtimehoo
114114
// the patchKubeadmConfigTemplate func shows how to implement patches only for KubeadmConfigTemplates
115115
// linked to a specific MachineDeployment class; another option is to check the holderRef value and call
116116
// this func or more specialized func conditionally.
117-
if err := patchKubeadmConfigTemplate(ctx, obj, variables); err != nil {
118-
log.Error(err, "Error patching KubeadmConfigTemplate")
119-
return errors.Wrap(err, "error patching KubeadmConfigTemplate")
120-
}
117+
patchKubeadmConfigTemplate(ctx, obj, variables)
121118
case *infrav1beta1.DockerMachineTemplate, *infrav1.DockerMachineTemplate:
122119
// NOTE: DockerMachineTemplate could be linked to the ControlPlane or one or more of the existing MachineDeployment class;
123120
// the patchDockerMachineTemplate func shows how to implement different patches for DockerMachineTemplate
@@ -170,7 +167,49 @@ func patchDockerClusterTemplate(_ context.Context, obj runtime.Object, templateV
170167
func patchKubeadmControlPlaneTemplate(ctx context.Context, obj runtime.Object, templateVariables map[string]apiextensionsv1.JSON) error {
171168
log := ctrl.LoggerFrom(ctx)
172169

173-
// 1) Patch RolloutStrategy RollingUpdate MaxSurge with the value from the Cluster Topology variable.
170+
// 1) Set extraArgs
171+
switch obj := obj.(type) {
172+
case *controlplanev1beta1.KubeadmControlPlaneTemplate:
173+
if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration == nil {
174+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration = &bootstrapv1beta1.ClusterConfiguration{}
175+
}
176+
177+
if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.APIServer.ExtraArgs == nil {
178+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.APIServer.ExtraArgs = map[string]string{}
179+
}
180+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.APIServer.ExtraArgs["v"] = "2"
181+
182+
if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs == nil {
183+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs = map[string]string{}
184+
}
185+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs["v"] = "2"
186+
187+
if obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Scheduler.ExtraArgs == nil {
188+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Scheduler.ExtraArgs = map[string]string{}
189+
}
190+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Scheduler.ExtraArgs["v"] = "2"
191+
192+
if obj.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration.KubeletExtraArgs == nil {
193+
obj.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration.KubeletExtraArgs = map[string]string{}
194+
}
195+
obj.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration.KubeletExtraArgs["v"] = "2"
196+
197+
if obj.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration.KubeletExtraArgs == nil {
198+
obj.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration.KubeletExtraArgs = map[string]string{}
199+
}
200+
obj.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration.KubeletExtraArgs["v"] = "2"
201+
case *controlplanev1.KubeadmControlPlaneTemplate:
202+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.APIServer.ExtraArgs = append(obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.APIServer.ExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
203+
204+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs = append(obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.ControllerManager.ExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
205+
206+
obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Scheduler.ExtraArgs = append(obj.Spec.Template.Spec.KubeadmConfigSpec.ClusterConfiguration.Scheduler.ExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
207+
208+
obj.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration.KubeletExtraArgs = append(obj.Spec.Template.Spec.KubeadmConfigSpec.InitConfiguration.NodeRegistration.KubeletExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
209+
obj.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration.KubeletExtraArgs = append(obj.Spec.Template.Spec.KubeadmConfigSpec.JoinConfiguration.NodeRegistration.KubeletExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
210+
}
211+
212+
// 2) Patch RolloutStrategy RollingUpdate MaxSurge with the value from the Cluster Topology variable.
174213
// If this is unset continue as this variable is not required.
175214
kcpControlPlaneMaxSurge, err := topologymutation.GetStringVariable(templateVariables, "kubeadmControlPlaneMaxSurge")
176215
if err != nil {
@@ -206,8 +245,17 @@ func patchKubeadmControlPlaneTemplate(ctx context.Context, obj runtime.Object, t
206245
}
207246

208247
// patchKubeadmConfigTemplate patches the ControlPlaneTemplate.
209-
func patchKubeadmConfigTemplate(_ context.Context, _ runtime.Object, _ map[string]apiextensionsv1.JSON) error {
210-
return nil
248+
func patchKubeadmConfigTemplate(_ context.Context, obj runtime.Object, _ map[string]apiextensionsv1.JSON) {
249+
// 1) Set extraArgs
250+
switch obj := obj.(type) {
251+
case *bootstrapv1beta1.KubeadmConfigTemplate:
252+
if obj.Spec.Template.Spec.JoinConfiguration.NodeRegistration.KubeletExtraArgs == nil {
253+
obj.Spec.Template.Spec.JoinConfiguration.NodeRegistration.KubeletExtraArgs = map[string]string{}
254+
}
255+
obj.Spec.Template.Spec.JoinConfiguration.NodeRegistration.KubeletExtraArgs["v"] = "2"
256+
case *bootstrapv1.KubeadmConfigTemplate:
257+
obj.Spec.Template.Spec.JoinConfiguration.NodeRegistration.KubeletExtraArgs = append(obj.Spec.Template.Spec.InitConfiguration.NodeRegistration.KubeletExtraArgs, bootstrapv1.Arg{Name: "v", Value: "2"})
258+
}
211259
}
212260

213261
// patchDockerMachineTemplate patches the DockerMachineTemplate.

test/extension/handlers/topologymutation/handler_test.go

Lines changed: 80 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,29 @@ func Test_patchKubeadmControlPlaneTemplate(t *testing.T) {
129129
},
130130
},
131131
},
132+
KubeadmConfigSpec: bootstrapv1.KubeadmConfigSpec{
133+
ClusterConfiguration: bootstrapv1.ClusterConfiguration{
134+
APIServer: bootstrapv1.APIServer{
135+
ExtraArgs: []bootstrapv1.Arg{{Name: "v", Value: "2"}},
136+
},
137+
ControllerManager: bootstrapv1.ControllerManager{
138+
ExtraArgs: []bootstrapv1.Arg{{Name: "v", Value: "2"}},
139+
},
140+
Scheduler: bootstrapv1.Scheduler{
141+
ExtraArgs: []bootstrapv1.Arg{{Name: "v", Value: "2"}},
142+
},
143+
},
144+
InitConfiguration: bootstrapv1.InitConfiguration{
145+
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
146+
KubeletExtraArgs: []bootstrapv1.Arg{{Name: "v", Value: "2"}},
147+
},
148+
},
149+
JoinConfiguration: bootstrapv1.JoinConfiguration{
150+
NodeRegistration: bootstrapv1.NodeRegistrationOptions{
151+
KubeletExtraArgs: []bootstrapv1.Arg{{Name: "v", Value: "2"}},
152+
},
153+
},
154+
},
132155
},
133156
},
134157
},
@@ -353,9 +376,63 @@ func TestHandler_GeneratePatches(t *testing.T) {
353376
Status: runtimehooksv1.ResponseStatusSuccess,
354377
},
355378
Items: []runtimehooksv1.GeneratePatchesResponseItem{
356-
responseItem("1", `[
357-
{"op":"add","path":"/spec","value":{"template": {"spec":{"rollout": {"strategy": {"type": "RollingUpdate","rollingUpdate":{"maxSurge":3}}}}}}}
358-
]`),
379+
responseItem("1", `
380+
[ {
381+
"op" : "add",
382+
"path" : "/spec",
383+
"value" : {
384+
"template" : {
385+
"spec" : {
386+
"kubeadmConfigSpec" : {
387+
"clusterConfiguration" : {
388+
"apiServer" : {
389+
"extraArgs" : [ {
390+
"name" : "v",
391+
"value" : "2"
392+
} ]
393+
},
394+
"controllerManager" : {
395+
"extraArgs" : [ {
396+
"name" : "v",
397+
"value" : "2"
398+
} ]
399+
},
400+
"scheduler" : {
401+
"extraArgs" : [ {
402+
"name" : "v",
403+
"value" : "2"
404+
} ]
405+
}
406+
},
407+
"initConfiguration" : {
408+
"nodeRegistration" : {
409+
"kubeletExtraArgs" : [ {
410+
"name" : "v",
411+
"value" : "2"
412+
} ]
413+
}
414+
},
415+
"joinConfiguration" : {
416+
"nodeRegistration" : {
417+
"kubeletExtraArgs" : [ {
418+
"name" : "v",
419+
"value" : "2"
420+
} ]
421+
}
422+
}
423+
},
424+
"rollout" : {
425+
"strategy" : {
426+
"rollingUpdate" : {
427+
"maxSurge" : 3
428+
},
429+
"type" : "RollingUpdate"
430+
}
431+
}
432+
}
433+
}
434+
}
435+
} ]`),
359436
responseItem("2", `[
360437
{"op":"add","path":"/spec/template/spec/customImage","value":"kindest/node:v1.23.0"}
361438
]`),

0 commit comments

Comments
 (0)