Skip to content

Commit 9d3d842

Browse files
committed
fix: nodeadm kubelet config
1 parent da87728 commit 9d3d842

File tree

3 files changed

+36
-33
lines changed

3 files changed

+36
-33
lines changed

bootstrap/eks/controllers/nodeadmconfig_controller.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,15 @@ func (r *NodeadmConfigReconciler) joinWorker(ctx context.Context, cluster *clust
222222
}
223223
if config.Spec.Kubelet != nil {
224224
nodeInput.KubeletFlags = config.Spec.Kubelet.Flags
225-
nodeInput.KubeletConfig = config.Spec.Kubelet.Config
225+
if config.Spec.Kubelet.Config != nil {
226+
nodeInput.KubeletConfig = config.Spec.Kubelet.Config
227+
}
226228
}
227229
if config.Spec.Containerd != nil {
228230
nodeInput.ContainerdConfig = config.Spec.Containerd.Config
229-
nodeInput.ContainerdBaseRuntimeSpec = config.Spec.Containerd.BaseRuntimeSpec
231+
if config.Spec.Containerd.BaseRuntimeSpec != nil {
232+
nodeInput.ContainerdBaseRuntimeSpec = config.Spec.Containerd.BaseRuntimeSpec
233+
}
230234
}
231235
if config.Spec.FeatureGates != nil {
232236
nodeInput.FeatureGates = config.Spec.FeatureGates
@@ -328,21 +332,21 @@ func (r *NodeadmConfigReconciler) storeBootstrapData(ctx context.Context, cluste
328332
}, secret); err != nil {
329333
if apierrors.IsNotFound(err) {
330334
if secret, err = r.createBootstrapSecret(ctx, cluster, config, data); err != nil {
331-
return errors.Wrap(err, "failed to create bootstrap data secret for EKSConfig")
335+
return errors.Wrap(err, "failed to create bootstrap data secret for NodeadmConfig")
332336
}
333-
log.Info("created bootstrap data secret for EKSConfig", "secret", klog.KObj(secret))
337+
log.Info("created bootstrap data secret for NodeadmConfig", "secret", klog.KObj(secret))
334338
} else {
335-
return errors.Wrap(err, "failed to get data secret for EKSConfig")
339+
return errors.Wrap(err, "failed to get data secret for NodeadmConfig")
336340
}
337341
} else {
338342
updated, err := r.updateBootstrapSecret(ctx, secret, data)
339343
if err != nil {
340-
return errors.Wrap(err, "failed to update data secret for EKSConfig")
344+
return errors.Wrap(err, "failed to update data secret for NodeadmConfig")
341345
}
342346
if updated {
343-
log.Info("updated bootstrap data secret for EKSConfig", "secret", klog.KObj(secret))
347+
log.Info("updated bootstrap data secret for NodeadmConfig", "secret", klog.KObj(secret))
344348
} else {
345-
log.Trace("no change in bootstrap data secret for EKSConfig", "secret", klog.KObj(secret))
349+
log.Trace("no change in bootstrap data secret for NodeadmConfig", "secret", klog.KObj(secret))
346350
}
347351
}
348352

bootstrap/eks/internal/userdata/nodeadm.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ spec:
9898
kubelet:
9999
{{- if .KubeletConfig }}
100100
config: |
101-
{{ Indent 6 .KubeletConfigRaw }}
101+
{{ Indent 6 .KubeletConfig }}
102102
{{- end }}
103103
flags:
104104
{{- range $flag := .KubeletFlags }}
@@ -112,7 +112,7 @@ spec:
112112
{{- end }}
113113
{{- if .ContainerdBaseRuntimeSpec }}
114114
baseRuntimeSpec: |
115-
{{ Indent 6 .ContainerdBaseRuntimeSpecRaw }}
115+
{{ Indent 6 .ContainerdBaseRuntimeSpec}}
116116
{{- end }}
117117
{{- end }}
118118
{{- if .Instance }}
@@ -224,28 +224,6 @@ func (input *NodeadmInput) getCapacityTypeString() string {
224224
}
225225
}
226226

227-
// ContainerdBaseRuntimeSpecRaw returns the raw JSON/YAML for inclusion into templates.
228-
func (input *NodeadmInput) ContainerdBaseRuntimeSpecRaw() string {
229-
if input.ContainerdBaseRuntimeSpec == nil {
230-
return ""
231-
}
232-
if len(input.ContainerdBaseRuntimeSpec.Raw) == 0 {
233-
return ""
234-
}
235-
return string(input.ContainerdBaseRuntimeSpec.Raw)
236-
}
237-
238-
// KubeletConfigRaw returns the raw JSON/YAML for inclusion into templates.
239-
func (input *NodeadmInput) KubeletConfigRaw() string {
240-
if input.KubeletConfig == nil {
241-
return ""
242-
}
243-
if len(input.KubeletConfig.Raw) == 0 {
244-
return ""
245-
}
246-
return string(input.KubeletConfig.Raw)
247-
}
248-
249227
// validateNodeInput validates the input for nodeadm user data generation.
250228
func validateNodeadmInput(input *NodeadmInput) error {
251229
if input.APIServerEndpoint == "" {

bootstrap/eks/internal/userdata/nodeadm_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,28 @@ func TestNodeadmUserdata(t *testing.T) {
160160
strings.Contains(output, "apiVersion: node.eks.aws/v1alpha1")
161161
},
162162
},
163+
{
164+
name: "with kubelet config",
165+
args: args{
166+
input: &NodeadmInput{
167+
ClusterName: "test-cluster",
168+
APIServerEndpoint: "https://example.com",
169+
CACert: "test-ca-cert",
170+
NodeGroupName: "test-nodegroup",
171+
KubeletConfig: `
172+
evictionHard:
173+
memory.available: "2000Mi"
174+
175+
`,
176+
},
177+
},
178+
expectErr: false,
179+
verifyOutput: func(output string) bool {
180+
return strings.Contains(output, "evictionHard:") &&
181+
strings.Contains(output, "memory.available: \"2000Mi\"") &&
182+
strings.Contains(output, "apiVersion: node.eks.aws/v1alpha1")
183+
},
184+
},
163185
{
164186
name: "with pre bootstrap commands",
165187
args: args{
@@ -365,7 +387,6 @@ func TestNodeadmUserdata(t *testing.T) {
365387
expectErr: false,
366388
verifyOutput: func(output string) bool {
367389
boundary := "//" // default boundary
368-
fmt.Println(output)
369390
return strings.Contains(output, fmt.Sprintf(`boundary=%q`, boundary)) &&
370391
strings.Contains(output, "Content-Type: application/node.eks.aws") &&
371392
strings.Contains(output, "Content-Type: text/x-shellscript") &&

0 commit comments

Comments
 (0)