@@ -21,13 +21,11 @@ import (
21
21
22
22
"k8s.io/klog/v2"
23
23
24
- "k8s.io/apimachinery/pkg/types"
25
24
"k8s.io/apimachinery/pkg/util/sets"
26
25
utilfeature "k8s.io/apiserver/pkg/util/feature"
27
26
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
28
27
kubefeatures "k8s.io/kubernetes/pkg/features"
29
28
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager/checkpoint"
30
- "k8s.io/kubernetes/pkg/kubelet/cm/util/cdi"
31
29
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
32
30
)
33
31
@@ -352,50 +350,9 @@ func (pdev *podDevices) deviceRunContainerOptions(podUID, contName string) *Devi
352
350
}
353
351
}
354
352
355
- // Although the CDI devices are expected to be empty when this feature is disabled, we still
356
- // guard this with a feature gate to avoid any potential issues.
357
- if utilfeature .DefaultFeatureGate .Enabled (kubefeatures .DevicePluginCDIDevices ) {
358
- // We construct a resource ID from the pod UID and container name.
359
- // This ID has no semantic meaning, and is only used to ensure that the generated CDI annotation key is unique
360
- // for a given container. Since this is only called once per pod-container combination, this should be the case.
361
- resourceID := podUID + "-" + contName
362
- cdiAnnotations := getCDIAnnotations (resourceID , allCDIDevices , annotationsMap )
363
- opts .Annotations = append (opts .Annotations , cdiAnnotations ... )
364
- }
365
-
366
353
return opts
367
354
}
368
355
369
- // getCDIAnnotations returns the cdi annotations for a given container.
370
- // This creates a CDI annotation with a key of the form: devicemanager_{{resourceID}}.
371
- // The value of the annotation is a comma separated list of sorted CDI device IDs.
372
- // If the annotation key is already defined in the provided annotations map, then the existing value is used.
373
- func getCDIAnnotations (resourceID string , cdiDevices sets.Set [string ], annotationsMap map [string ]string ) []kubecontainer.Annotation {
374
- // We sort the CDI devices to ensure that the annotation value is deterministic.
375
- sortedCDIDevices := sets.List [string ](cdiDevices )
376
- annotations , err := cdi .GenerateAnnotations (types .UID (resourceID ), "devicemanager" , sortedCDIDevices )
377
- if err != nil {
378
- klog .ErrorS (err , "Failed to create CDI annotations" )
379
- return nil
380
- }
381
-
382
- var cdiAnnotations []kubecontainer.Annotation
383
- for _ , annotation := range annotations {
384
- if e , ok := annotationsMap [annotation .Name ]; ok {
385
- klog .V (4 ).InfoS ("Skip existing annotation" , "annotationKey" , annotation .Name , "annotationValue" , annotation .Value )
386
- if e != annotation .Value {
387
- klog .ErrorS (nil , "Annotation has conflicting setting" , "annotationKey" , annotation .Name , "expected" , e , "got" , annotation .Value )
388
- }
389
- continue
390
- }
391
- klog .V (4 ).InfoS ("Add annotation" , "annotationKey" , annotation .Name , "annotationValue" , annotation .Value )
392
- annotationsMap [annotation .Name ] = annotation .Value
393
- cdiAnnotations = append (cdiAnnotations , kubecontainer.Annotation {Name : annotation .Name , Value : annotation .Value })
394
- }
395
-
396
- return cdiAnnotations
397
- }
398
-
399
356
// getCDIDeviceInfo returns CDI devices from an allocate response
400
357
func getCDIDeviceInfo (resp * pluginapi.ContainerAllocateResponse , knownCDIDevices sets.Set [string ]) []kubecontainer.CDIDevice {
401
358
var cdiDevices []kubecontainer.CDIDevice
0 commit comments