@@ -35,16 +35,6 @@ const (
3535 kubeletConfigPerm = 0644
3636)
3737
38- func (k * kubelet ) writeKubeletConfig (cfg * api.NodeConfig ) error {
39- // tracking: https://github.com/kubernetes/enhancements/issues/3983
40- // for enabling drop-in configuration
41- if semver .Compare (cfg .Status .KubeletVersion , "v1.29.0" ) < 0 {
42- return k .writeKubeletConfigToFile (cfg )
43- } else {
44- return k .writeKubeletConfigToDir (cfg )
45- }
46- }
47-
4838// kubeletConfig is an internal-only representation of the kubelet configuration
4939// that is generated using sane defaults for EKS. It is a subset of the upstream
5040// KubeletConfiguration types:
@@ -233,8 +223,8 @@ func (ksc *kubeletConfig) withNodeLabels(flags map[string]string, nodeLabelFuncs
233223 }
234224}
235225
236- func (ksc * kubeletConfig ) withNodeIp (cfg * api.NodeConfig , flags map [string ]string ) error {
237- nodeIp , err := getNodeIp (context .TODO (), cfg , imds . DefaultClient () )
226+ func (ksc * kubeletConfig ) withNodeIp (cfg * api.NodeConfig , flags map [string ]string , imdsClient imds. IMDSClient ) error {
227+ nodeIp , err := getNodeIp (context .TODO (), cfg , imdsClient )
238228 if err != nil {
239229 return err
240230 }
@@ -280,8 +270,7 @@ func (ksc *kubeletConfig) withCloudProvider(cfg *api.NodeConfig, flags map[strin
280270 flags ["hostname-override" ] = nodeName
281271}
282272
283- // When the DefaultReservedResources flag is enabled, override the kubelet
284- // config with reserved cgroup values on behalf of the user
273+ // Override the kubelet config with reserved cgroup values on behalf of the user
285274func (ksc * kubeletConfig ) withDefaultReservedResources (cfg * api.NodeConfig , resources system.Resources ) {
286275 ksc .SystemReservedCgroup = ptr .String ("/system" )
287276 ksc .KubeReservedCgroup = ptr .String ("/runtime" )
@@ -298,29 +287,13 @@ func (ksc *kubeletConfig) withDefaultReservedResources(cfg *api.NodeConfig, reso
298287 }
299288}
300289
301- // withPodInfraContainerImage determines whether to add the
302- // '--pod-infra-container-image' flag, which is used to ensure the sandbox image
303- // is not garbage collected.
304- //
305- // TODO: revisit once the minimum supportted version catches up or the container
306- // runtime is moved to containerd 2.0
307- func (ksc * kubeletConfig ) withPodInfraContainerImage (cfg * api.NodeConfig , flags map [string ]string ) error {
308- // the flag is a noop on 1.29+, since the behavior was changed to use the
309- // CRI image pinning behavior and no longer considers the flag value.
310- // see: https://github.com/kubernetes/kubernetes/pull/118544
311- if semver .Compare (cfg .Status .KubeletVersion , "v1.29.0" ) < 0 {
312- flags ["pod-infra-container-image" ] = cfg .Status .Defaults .SandboxImage
313- }
314- return nil
315- }
316-
317290func (ksc * kubeletConfig ) withImageServiceEndpoint (cfg * api.NodeConfig , resources system.Resources ) {
318291 if containerd .UseSOCISnapshotter (cfg , resources ) {
319292 ksc .ImageServiceEndpoint = "unix:///run/soci-snapshotter-grpc/soci-snapshotter-grpc.sock"
320293 }
321294}
322295
323- func (k * kubelet ) GenerateKubeletConfig (cfg * api.NodeConfig ) (* kubeletConfig , error ) {
296+ func (k * kubelet ) generateKubeletConfig (cfg * api.NodeConfig ) (* kubeletConfig , error ) {
324297 kubeletConfig := defaultKubeletSubConfig ()
325298
326299 if err := kubeletConfig .withFallbackClusterDns (& cfg .Spec .Cluster ); err != nil {
@@ -329,10 +302,7 @@ func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, er
329302 if err := kubeletConfig .withOutpostSetup (cfg ); err != nil {
330303 return nil , err
331304 }
332- if err := kubeletConfig .withNodeIp (cfg , k .flags ); err != nil {
333- return nil , err
334- }
335- if err := kubeletConfig .withPodInfraContainerImage (cfg , k .flags ); err != nil {
305+ if err := kubeletConfig .withNodeIp (cfg , k .flags , k .imdsClient ); err != nil {
336306 return nil , err
337307 }
338308
@@ -351,43 +321,11 @@ func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, er
351321 return & kubeletConfig , nil
352322}
353323
354- // WriteConfig writes the kubelet config to a file.
355- // This should only be used for kubelet versions < 1.28.
356- func (k * kubelet ) writeKubeletConfigToFile (cfg * api.NodeConfig ) error {
357- kubeletConfig , err := k .GenerateKubeletConfig (cfg )
358- if err != nil {
359- return err
360- }
361-
362- var kubeletConfigBytes []byte
363- if len (cfg .Spec .Kubelet .Config ) > 0 {
364- mergedMap , err := util .Merge (kubeletConfig , cfg .Spec .Kubelet .Config , json .Marshal , json .Unmarshal )
365- if err != nil {
366- return err
367- }
368- if kubeletConfigBytes , err = json .MarshalIndent (mergedMap , "" , strings .Repeat (" " , 4 )); err != nil {
369- return err
370- }
371- } else {
372- var err error
373- if kubeletConfigBytes , err = json .MarshalIndent (kubeletConfig , "" , strings .Repeat (" " , 4 )); err != nil {
374- return err
375- }
376- }
377-
378- configPath := path .Join (kubeletConfigRoot , kubeletConfigFile )
379- k .flags ["config" ] = configPath
380-
381- zap .L ().Info ("Writing kubelet config to file.." , zap .String ("path" , configPath ))
382- return util .WriteFileWithDir (configPath , kubeletConfigBytes , kubeletConfigPerm )
383- }
384-
385- // WriteKubeletConfigToDir writes nodeadm's generated kubelet config to the
324+ // writeKubeletConfig writes nodeadm's generated kubelet config to the
386325// standard config file and writes the user's provided config to a directory for
387- // drop-in support. This is only supported on kubelet versions >= 1.28. see:
388- // https://kubernetes.io/docs/tasks/administer-cluster/kubelet-config-file/#kubelet-conf-d
389- func (k * kubelet ) writeKubeletConfigToDir (cfg * api.NodeConfig ) error {
390- kubeletConfig , err := k .GenerateKubeletConfig (cfg )
326+ // drop-in support.
327+ func (k * kubelet ) writeKubeletConfig (cfg * api.NodeConfig ) error {
328+ kubeletConfig , err := k .generateKubeletConfig (cfg )
391329 if err != nil {
392330 return err
393331 }
@@ -407,10 +345,10 @@ func (k *kubelet) writeKubeletConfigToDir(cfg *api.NodeConfig) error {
407345 if len (cfg .Spec .Kubelet .Config ) > 0 {
408346 dirPath := path .Join (kubeletConfigRoot , kubeletConfigDir )
409347 k .flags ["config-dir" ] = dirPath
410-
411- zap .L ().Info ("Enabling kubelet config drop-in dir.." )
412- k .environment ["KUBELET_CONFIG_DROPIN_DIR_ALPHA" ] = "on"
413- filePath := path . Join ( dirPath , "40-nodeadm.conf" )
348+ if semver . Compare ( cfg . Status . KubeletVersion , "v1.30.0" ) < 0 {
349+ zap .L ().Info ("Enabling kubelet config drop-in dir.." )
350+ k .environment ["KUBELET_CONFIG_DROPIN_DIR_ALPHA" ] = "on"
351+ }
414352
415353 // merge in default type metadata like kind and apiVersion in case the
416354 // user has not specified this, as it is required to qualify a drop-in
@@ -423,6 +361,7 @@ func (k *kubelet) writeKubeletConfigToDir(cfg *api.NodeConfig) error {
423361 if err != nil {
424362 return err
425363 }
364+ filePath := path .Join (dirPath , "40-nodeadm.conf" )
426365 zap .L ().Info ("Writing user kubelet config to drop-in file.." , zap .String ("path" , filePath ))
427366 if err := util .WriteFileWithDir (filePath , userKubeletConfigBytes , kubeletConfigPerm ); err != nil {
428367 return err
0 commit comments