@@ -213,6 +213,26 @@ func (ksc *kubeletConfig) withOutpostSetup(cfg *api.NodeConfig) error {
213213 return nil
214214}
215215
216+ func (ksc * kubeletConfig ) withNodeLabels (flags map [string ]string , nodeLabelFuncs map [string ]LabelValueFunc ) {
217+ var nodeLabels []string
218+ for nodeLabelKey , nodeLabelFunc := range nodeLabelFuncs {
219+ nodeLabelValue , ok , err := nodeLabelFunc ()
220+ if err != nil {
221+ zap .L ().Error ("Failed to get node label value" , zap .String ("key" , nodeLabelKey ), zap .Error (err ))
222+ continue
223+ }
224+ if ! ok {
225+ continue
226+ }
227+ nodeLabel := fmt .Sprintf ("%s=%s" , nodeLabelKey , nodeLabelValue )
228+ zap .L ().Info ("Adding node label" , zap .String ("label" , nodeLabel ))
229+ nodeLabels = append (nodeLabels , nodeLabel )
230+ }
231+ if len (nodeLabels ) > 0 {
232+ flags ["node-labels" ] = strings .Join (nodeLabels , "," )
233+ }
234+ }
235+
216236func (ksc * kubeletConfig ) withNodeIp (cfg * api.NodeConfig , flags map [string ]string ) error {
217237 nodeIp , err := getNodeIp (context .TODO (), cfg , imds .DefaultClient ())
218238 if err != nil {
@@ -284,14 +304,13 @@ func (ksc *kubeletConfig) withDefaultReservedResources(cfg *api.NodeConfig, reso
284304//
285305// TODO: revisit once the minimum supportted version catches up or the container
286306// runtime is moved to containerd 2.0
287- func (ksc * kubeletConfig ) withPodInfraContainerImage (cfg * api.NodeConfig , flags map [string ]string ) error {
307+ func (ksc * kubeletConfig ) withPodInfraContainerImage (cfg * api.NodeConfig , flags map [string ]string ) {
288308 // the flag is a noop on 1.29+, since the behavior was changed to use the
289309 // CRI image pinning behavior and no longer considers the flag value.
290310 // see: https://github.com/kubernetes/kubernetes/pull/118544
291311 if semver .Compare (cfg .Status .KubeletVersion , "v1.29.0" ) < 0 {
292312 flags ["pod-infra-container-image" ] = cfg .Status .Defaults .SandboxImage
293313 }
294- return nil
295314}
296315
297316func (ksc * kubeletConfig ) withImageServiceEndpoint (cfg * api.NodeConfig , resources system.Resources ) {
@@ -312,14 +331,15 @@ func (k *kubelet) GenerateKubeletConfig(cfg *api.NodeConfig) (*kubeletConfig, er
312331 if err := kubeletConfig .withNodeIp (cfg , k .flags ); err != nil {
313332 return nil , err
314333 }
315- if err := kubeletConfig .withPodInfraContainerImage (cfg , k .flags ); err != nil {
316- return nil , err
317- }
318334
319335 kubeletConfig .withVersionToggles (cfg )
320336 kubeletConfig .withCloudProvider (cfg , k .flags )
321337 kubeletConfig .withDefaultReservedResources (cfg , k .resources )
322338 kubeletConfig .withImageServiceEndpoint (cfg , k .resources )
339+ kubeletConfig .withNodeLabels (k .flags , map [string ]LabelValueFunc {
340+ // see: https://github.com/NVIDIA/gpu-operator/commit/e25291b86cf4542ac62d8635cda4bd653c4face3
341+ "nvidia.com/gpu.present" : getNvidiaGPULabel ,
342+ })
323343
324344 return & kubeletConfig , nil
325345}
0 commit comments