Skip to content

Commit a4ec0c0

Browse files
authored
Merge pull request kubernetes#126435 from bart0sh/PR151-Kubelet-devicemanager-stop-using-CDI-annotations
Kubelet: stop using CDI annotations
2 parents 0ce7f7e + ea3c662 commit a4ec0c0

File tree

4 files changed

+0
-412
lines changed

4 files changed

+0
-412
lines changed

pkg/kubelet/cm/devicemanager/pod_devices.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ import (
2121

2222
"k8s.io/klog/v2"
2323

24-
"k8s.io/apimachinery/pkg/types"
2524
"k8s.io/apimachinery/pkg/util/sets"
2625
utilfeature "k8s.io/apiserver/pkg/util/feature"
2726
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1"
2827
kubefeatures "k8s.io/kubernetes/pkg/features"
2928
"k8s.io/kubernetes/pkg/kubelet/cm/devicemanager/checkpoint"
30-
"k8s.io/kubernetes/pkg/kubelet/cm/util/cdi"
3129
kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
3230
)
3331

@@ -352,50 +350,9 @@ func (pdev *podDevices) deviceRunContainerOptions(podUID, contName string) *Devi
352350
}
353351
}
354352

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-
366353
return opts
367354
}
368355

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-
399356
// getCDIDeviceInfo returns CDI devices from an allocate response
400357
func getCDIDeviceInfo(resp *pluginapi.ContainerAllocateResponse, knownCDIDevices sets.Set[string]) []kubecontainer.CDIDevice {
401358
var cdiDevices []kubecontainer.CDIDevice

pkg/kubelet/cm/devicemanager/pod_devices_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,6 @@ func TestDeviceRunContainerOptions(t *testing.T) {
183183
),
184184
},
185185
expected: &DeviceRunContainerOptions{
186-
Annotations: []kubecontainer.Annotation{
187-
{Name: "cdi.k8s.io/devicemanager_pod-container", Value: "vendor1.com/class1=device1,vendor2.com/class2=device2"},
188-
},
189186
CDIDevices: []kubecontainer.CDIDevice{
190187
{Name: "vendor1.com/class1=device1"},
191188
{Name: "vendor2.com/class2=device2"},
@@ -203,9 +200,6 @@ func TestDeviceRunContainerOptions(t *testing.T) {
203200
),
204201
},
205202
expected: &DeviceRunContainerOptions{
206-
Annotations: []kubecontainer.Annotation{
207-
{Name: "cdi.k8s.io/devicemanager_pod-container", Value: "vendor1.com/class1=device1,vendor2.com/class2=device2,vendor3.com/class3=device3,vendor4.com/class4=device4"},
208-
},
209203
CDIDevices: []kubecontainer.CDIDevice{
210204
{Name: "vendor1.com/class1=device1"},
211205
{Name: "vendor2.com/class2=device2"},
@@ -225,9 +219,6 @@ func TestDeviceRunContainerOptions(t *testing.T) {
225219
),
226220
},
227221
expected: &DeviceRunContainerOptions{
228-
Annotations: []kubecontainer.Annotation{
229-
{Name: "cdi.k8s.io/devicemanager_pod-container", Value: "vendor1.com/class1=device1,vendor2.com/class2=device2,vendor3.com/class3=device3"},
230-
},
231222
CDIDevices: []kubecontainer.CDIDevice{
232223
{Name: "vendor1.com/class1=device1"},
233224
{Name: "vendor2.com/class2=device2"},

0 commit comments

Comments
 (0)