crbench//

← all cases

kubelet DRA: update claimInfo cache locking and checkpoint semantics

Tier 2 hard go · local · real merged PR from kubernetes/kubernetes #124323

Ground-truth defects

d1 · correctness · high
In `prepareResources`, the branch that handles an already-prepared claim (`if claimInfo.isPrepared()`) does `return nil` instead of `continue`. Because this runs inside the `for ... range pod.Spec.ResourceClaims` loop, the first already-prepared claim short-circuits the whole loop and the pod's remaining ResourceClaims are never prepared. The fix changes `return nil` back to `continue`.
d2 · correctness · medium
`TestNewClaimInfoFromClaim` and `TestNewClaimInfoFromState` assert with an inverted condition: `if reflect.DeepEqual(result, test.expectedResult) { t.Errorf(...) }`. That reports a failure only when the result MATCHES the expectation, so the tests never validate the constructor and pass vacuously (and `expectedResult` is left nil). The fix inverts the check to `if !reflect.DeepEqual(...)`.
d3 · correctness · medium
The claimInfo-cache tests seed their "item in cache" fixtures under the key `claimName + namespace`, but the cache itself keys entries on `namespace + "/" + claimName`. The mismatched key means the seeded entry is never found, so the `get`/`delete`/`contains` tests pass vacuously without exercising the real lookup. The fix keys the fixtures on `namespace + "/" + claimName` to match the cache.

The change under review

diff (truncated — full diff)
diff --git a/pkg/kubelet/cm/container_manager_linux.go b/pkg/kubelet/cm/container_manager_linux.go
index 4ed1aa7b591ce..fb666a8333fb7 100644
--- a/pkg/kubelet/cm/container_manager_linux.go
+++ b/pkg/kubelet/cm/container_manager_linux.go
@@ -305,7 +305,7 @@ func NewContainerManager(mountUtil mount.Interface, cadvisorInterface cadvisor.I
 	}
 	cm.topologyManager.AddHintProvider(cm.deviceManager)
 
-	// initialize DRA manager
+	// Initialize DRA manager
 	if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.DynamicResourceAllocation) {
 		klog.InfoS("Creating Dynamic Resource Allocation (DRA) manager")
 		cm.draManager, err = dra.NewManagerImpl(kubeClient, nodeConfig.KubeletRootDir, nodeConfig.NodeName)
@@ -564,6 +564,14 @@ func (cm *containerManagerImpl) Start(node *v1.Node,
 
 	containerMap, containerRunningSet := buildContainerMapAndRunningSetFromRuntime(ctx, runtimeService)
 
+	// Initialize DRA manager
+	if utilfeature.DefaultFeatureGate.Enabled(kubefeatures.DynamicResourceAllocation) {
+		err := cm.draManager.Start(dra.ActivePodsFunc(activePods), sourcesReady)
+		if err != nil {
+			return fmt.Errorf("start dra manager error: %w", err)
+		}
+	}
+
 	// Initialize CPU manager
 	err := cm.cpuManager.Start(cpumanager.ActivePodsFunc(activePods), sourcesReady, podStatusProvider, runtimeService, containerMap)
 	if err != nil {
@@ -959,7 +967,6 @@ func (cm *containerManagerImpl) GetDynamicResources(pod *v1.Pod, container *v1.C
 	}
 	for _, containerClaimInfo := range containerClaimInfos {
 		var claimResources []*podresourcesapi.ClaimResource
-		containerClaimInfo.RLock()
 		// TODO: Currently  we maintain a list of ClaimResources, each of which contains
 		// a set of CDIDevices from a different kubelet plugin. In the future we may want to
 		// include the name of the kubelet plugin and/or other types of resources that are
@@ -971,7 +978,6 @@ func (cm *containerManagerImpl) GetDynamicResources(pod *v1.Pod, container *v1.C
 			}
 			claimResources = append(claimResources, &podresourcesapi.ClaimResource{CDIDevices: cdiDevices})
 		}
-		containerClaimInfo.RUnlock()
 		containerDynamicResource := podresourcesapi.DynamicResource{
 			ClassName:      containerClaimInfo.ClassName,
 			ClaimName:      containerClaimInfo.ClaimName,
diff --git a/pkg/kubelet/cm/dra/claiminfo.go b/pkg/kubelet/cm/dra/claiminfo.go
index d369b8d3e33ea..5602707a0a4d3 100644
--- a/pkg/kubelet/cm/dra/claiminfo.go
+++ b/pkg/kubelet/cm/dra/claiminfo.go
@@ -30,8 +30,8 @@ import (
 
 // ClaimInfo holds information required
 // to prepare and unprepare a resource claim.
+// +k8s:deepcopy-gen=true
 type ClaimInfo struct {
-	sync.RWMutex
 	state.ClaimInfoState
 	// annotations is a mapping of container annotations per DRA plugin associated with
 	// a prepared resource
@@ -39,24 +39,57 @@ type ClaimInfo struct {
 	prepared    bool
 }
 
-func (info *ClaimInfo) addPodReference(podUID types.UID) {
-	info.Lock()
-	defer info.Unlock()
-
-	info.PodUIDs.Insert(string(podUID))
+// claimInfoCache is a cache of processed resource claims keyed by namespace/claimname.
+type claimInfoCache struct {
+	sync.RWMutex
+	state     state.CheckpointState
+	claimInfo map[string]*ClaimInfo
 }
 
-func (info *ClaimInfo) deletePodReference(podUID types.UID) {
-	info.Lock()
-	defer info.Unlock()
-
-	info.PodUIDs.Delete(string(podUID))
+// newClaimInfoFromClaim creates a new claim info from a resource claim.
+func newClaimInfoFromClaim(claim *resourcev1alpha2.ResourceClaim) *ClaimInfo {
+	// Grab the allocation.resourceHandles. If there are no
+	// allocation.resourceHandles, create a single resourceHandle with no
+	// content. This will trigger processing of this claim by a single
+	// kubelet plugin whose name matches resourceClaim.Status.DriverName.
+	resourceHandles := claim.Status.Allocation.ResourceHandles
+	if len(resourceHandles) == 0 {
+		resourceHandles = make([]resourcev1alpha2.ResourceHandle, 1)
+	}
+	claimInfoState := state.ClaimInfoState{
+		DriverName:      claim.Status.DriverName,
+		ClassName:       claim.Spec.ResourceClassName,
+		ClaimUID:        claim.UID,
+		ClaimName:       claim.Name,
+		Namespace:       claim.Namespace,
+		PodUIDs:         sets.New[string](),
+		ResourceHandles: resourceHandles,
+		CDIDevices:      make(map[string][]string),
+	}
+	info := &ClaimInfo{
+		ClaimInfoState: claimInfoState,
+		annotations:    make(map[string][]kubecontainer.Annotation),
+		prepared:       false,
+	}
+	return info
 }
 
-func (info *ClaimInfo) addCDIDevices(pluginName string, cdiDevices []string) error {
-	info.Lock()
-	defer info.Unlock()
+// newClaimInfoFromClaim creates a new claim info from a checkpointed claim info state object.
+func newClaimInfoFromState(state *state.ClaimInfoState) *ClaimInfo {
+	info := &ClaimInfo{
+		ClaimInfoState: *state.DeepCopy(),
+		annotations:    make(map[string][]kubecontainer.Annotation),
+		prepared:       false,
+	}
+	for pluginName, devices := range info.CDIDevices {
+		annotations, _ := cdi.GenerateAnnotations(info.ClaimUID, info.DriverName, devices)
+		info.annotations[pluginName] = append(info.annotations[pluginName], annotations...)
+	}
+	return info
+}
 
+// setCDIDevices adds a set of CDI devices to the claim info.
+func (info *ClaimInfo) setCDIDevices(pluginName string, cdiDevices []string) error {
 	// NOTE: Passing CDI device names as annotations is a temporary solution
 	// It will be removed after all runtimes are updated
 	// to get CDI device names from the ContainerConfig.CDIDevices field
@@ -69,6 +102,10 @@ func (info *ClaimInfo) addCDIDevices(pluginName string, cdiDevices []string) err
 		info.CDIDevices = make(map[string][]string)
 	}
 
+	if info.annotations == nil {
+		info.annotations = make(map[string][]kubecontainer.Annotation)
+	}
+
 	info.CDIDevices[pluginName] = cdiDevices
 	info.annotations[pluginName] = annotations
 
@@ -77,9 +114,6 @@ func (info *ClaimInfo) addCDIDevices(pluginName string, cdiDevices []string) err
 
 // annotationsAsList returns container annotations as a single list.
 func (info *ClaimInfo) annotationsAsList() []kubecontainer.Annotation {
-	info.RLock()
-	defer info.RUnlock()
-
 	var lst []kubecontainer.Annotation
 	for _, v := range info.annotations {
 		lst = append(lst, v...)
@@ -87,53 +121,43 @@ func (info *ClaimInfo) annotationsAsList() []kubecontainer.Annotation {
 	return lst
 }
 
-// claimInfoCache is a cache of processed resource claims keyed by namespace + claim name.
-type claimInfoCache struct {
-	sync.RWMutex
-	state     state.CheckpointState
-	claimInfo map[string]*ClaimInfo
+// cdiDevicesAsList returns a list of CDIDevices from the provided claim info.
+func (info *ClaimInfo) cdiDevicesAsList() []kubecontainer.CDIDevice {
+	var cdiDevices []kubecontainer.CDIDevice
+	for _, devices := range info.CDIDevices {
+		for _, device := range devices {
+			cdiDevices = append(cdiDevices, kubecontainer.CDIDevice{Name: device})
+		}
+	}
+	return cdiDevices
 }
 
-func newClaimInfo(driverName, className string, claimUID types.UID, claimName, namespace string, podUIDs sets.Set[string], resourceHandles []resourcev1alpha2.ResourceHandle) *ClaimInfo {
-	claimInfoState := state.ClaimInfoState{
-		DriverName:      driverName,
-		ClassName:       className,
-		ClaimUID:        claimUID,
-		ClaimName:       claimName,
-		Namespace:       namespace,
-		PodUIDs:         podUIDs,
-		ResourceHandles: resourceHandles,
-	}
-	claimInfo := ClaimInfo{
-		ClaimInfoState: claimInfoState,
-		annotations:    make(map[string][]kubecontainer.Annotation),
-	}
-	return &claimInfo
+// addPodReference adds a pod reference to the claim info.
+func (info *ClaimInfo) addPodReference(podUID types.UID) {
+	info.PodUIDs.Insert(string(podUID))
 }
 
-// newClaimInfoFromResourceClaim creates a new ClaimInfo object
-func newClaimInfoFromResourceClaim(resourceClaim *resourcev1alpha2.ResourceClaim) *ClaimInfo {
-	// Grab the allocation.resourceHandles. If there are no
-	// allocation.resourceHandles, create a single resourceHandle with no
-	// content. This will trigger processing of this claim by a single
-	// kubelet plugin whose name matches resourceClaim.Status.DriverName.
-	resourceHandles := resourceClaim.Status.Allocation.ResourceHandles
-	if len(resourceHandles) == 0 {
-		resourceHandles = make([]resourcev1alpha2.ResourceHandle, 1)
-	}
+// hasPodReference checks if a pod reference exists in the claim info.
+func (info *ClaimInfo) hasPodReference(podUID types.UID) bool {
+	return info.PodUIDs.Has(string(podUID))
+}
+
+// deletePodReference deletes a pod reference from the claim info.
+func (info *ClaimInfo) deletePodReference(podUID types.UID) {
+	info.PodUIDs.Delete(string(podUID))
+}
+
+// setPrepared marks the claim info as prepared.
+func (info *ClaimInfo) setPrepared() {
+	info.prepared = true
+}
 
-	return newClaimInfo(
-		resourceClaim.Status.DriverName,
-		resourceClaim.Spec.ResourceClassName,
-		resourceClaim.UID,
-		resourceClaim.Name,
-		resourceClaim.Namespace,
-		make(sets.Set[string]),
-		resourceHandles,
-	)
+// isPrepared checks if claim info is prepared or not.
+func (info *ClaimInfo) isPrepared() bool {
+	return info.prepared
 }
 
-// newClaimInfoCache is a function that returns an instance of the claimInfoCache.
+// newClaimInfoCache creates a new claim info cache object, pre-populated from a checkpoint (if present).
 func newClaimInfoCache(stateDir, checkpointName string) (*claimInfoCache, error) {
 	stateImpl, err := state.NewCheckpointState(stateDir, checkpointName)
 	if err != nil {
@@ -151,46 +175,48 @@ func newClaimInfoCache(stateDir, checkpointName string) (*claimInfoCache, error)
 	}
 
 	for _, entry := range curState {
-		info := newClaimInfo(
-			entry.DriverName,
-			entry.ClassName,
-			entry.ClaimUID,
-			entry.ClaimName,
-			entry.Namespace,
-			entry.PodUIDs,
-			entry.ResourceHandles,
-		)
-		for pluginName, cdiDevices := range entry.CDIDevices {
-			err := info.addCDIDevices(pluginName, cdiDevices)
-			if err != nil {
-				return nil, fmt.Errorf("failed to add CDIDevices to claimInfo %+v: %+v", info, err)
-			}
-		}
-		cache.add(info)
+		info := newClaimInfoFromState(&entry)
+		cache.claimInfo[info.Namespace+"/"+info.ClaimName] = info
 	}
 
 	return cache, nil
 }
 
-func (cache *claimInfoCache) add(res *ClaimInfo) {
+// withLock runs a function while holding the claimInfoCache lock.
+func (cache *claimInfoCache) withLock(f func() error) error {
 	cache.Lock()
 	defer cache.Unlock()
-
-	cache.claimInfo[res.ClaimName+res.Namespace] = res
+	return f()
 }
 
-func (cache *claimInfoCache) get(claimName, namespace string) *ClaimInfo {
+// withRLock runs a function while holding the claimInfoCache rlock.
+func (cache *claimInfoCache) withRLock(f func() error) error {
 	cache.RLock()
 	defer cache.RUnlock()
+	return f()
+}
 
-	return cache.claimInfo[claimName+namespace]
+// add adds a new claim info object into the claim info cache.
+func (cache *claimInfoCache) add(info *ClaimInfo) *ClaimInfo {
+	cache.claimInfo[info.Namespace+"/"+info.ClaimName] = info
+	return info
 }
 
-func (cache *claimInfoCache) delete(claimName, namespace string) {
-	cache.Lock()
-	defer cache.Unlock()
+// contains checks to see if a specific claim info object is already in the cache.
+func (cache *claimInfoCache) contains(claimName, namespace string) bool {
+	_, exists := cache.claimInfo[namespace+"/"+claimName]
+	return exists
+}
 
-	delete(cache.claimInfo, claimName+namespace)
+// get gets a specific claim info object from the cache.
+func (cache *claimInfoCache) get(claimName, namespace string) (*ClaimInfo, bool) {
+	info, exists := cache.claimInfo[namespace+"/"+claimName]
+	return info, exists
+}
+
+// delete deletes a specific claim info object from the cache.
+func (cache *claimInfoCache) delete(claimName, namespace string) {
+	delete(cache.claimInfo, namespace+"/"+claimName)
 }
 
 // hasPodReference checks if there is at least one claim
@@ -198,26 +224,19 @@ func (cache *claimInfoCache) delete(claimName, namespace string) {
 // This function is used indirectly by the status manager
 // to check if pod can enter termination status
 func (cache *claimInfoCache) hasPodReference(UID types.UID) bool {
-	cache.RLock()
-	defer cache.RUnlock()
-
 	for _, claimInfo := range cache.claimInfo {
-		if claimInfo.PodUIDs.Has(string(UID)) {
+		if claimInfo.hasPodReference(UID) {
 			return true
 		}
 	}
-
 	return false
 }
 
+// syncToCheckpoint syncs the full claim info cache state to a checkpoint.
 func (cache *claimInfoCache) syncToCheckpoint() error {
-	cache.RLock()
-	defer cache.RUnlock()
-
 	claimInfoStateList := make(state.ClaimInfoStateList, 0, len(cache.claimInfo))
 	for _, infoClaim := range cache.claimInfo {
 		claimInfoStateList = append(claimInfoStateList, infoClaim.ClaimInfoState)
 	}
-
 	return cache.state.Store(claimInfoStateList)
 }
diff --git a/pkg/kubelet/cm/dra/claiminfo_test.go b/pkg/kubelet/cm/dra/claiminfo_test.go
new file mode 100644
index 0000000000000..58652cc605c8d
--- /dev/null
+++ b/pkg/kubelet/cm/dra/claiminfo_test.go
@@ -0,0 +1,894 @@
+/*
+Copyright 2024 The Kubernetes Authors.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package dra
+
+import (
+	"errors"
+	"fmt"
+	"path"
+	"reflect"
+	"sort"
+	"testing"
+
+	"github.com/stretchr/testify/assert"
+	resourcev1alpha2 "k8s.io/api/resource/v1alpha2"
+	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+	"k8s.io/apimachinery/pkg/types"
+	"k8s.io/apimachinery/pkg/util/sets"
+	"k8s.io/kubernetes/pkg/kubelet/cm/dra/state"
+	kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
+)
+
+// ClaimInfo test cases
+
+func TestNewClaimInfoFromClaim(t *testing.T) {
+	namespace := "test-namespace"
+	className := "test-class"
+	driverName := "test-plugin"
+	claimUID := types.UID("claim-uid")
+	claimName := "test-claim"
+
+	for _, test := range []struct {
+		description    string
+		claim          *resourcev1alpha2.ResourceClaim
+		expectedResult *ClaimInfo
+	}{
+		{
+			description: "successfully created object",
+			claim: &resourcev1alpha2.ResourceClaim{
+				ObjectMeta: metav1.ObjectMeta{
+					UID:       claimUID,
+					Name:      claimName,
+					Namespace: namespace,
+				},
+				Status: resourcev1alpha2.ResourceClaimStatus{
+					DriverName: driverName,
+					Allocation: &resourcev1alpha2.AllocationResult{
+						ResourceHandles: []resourcev1alpha2.ResourceHandle{},
+					},
+				},
+				Spec: resourcev1alpha2.ResourceClaimSpec{
+					ResourceClassName: className,
+				},
+			},
+			expectedResult: &ClaimInfo{
+				ClaimInfoState: state.ClaimInfoState{
+					DriverName: driverName,
+					ClassName:  className,
+					ClaimUID:   claimUID,
+					ClaimName:  claimName,
+					Namespace:  claimName,
+					PodUIDs:    sets.New[string](),
+					ResourceHandles: []resourcev1alpha2.ResourceHandle{
+						{},
+					},
+					CDIDevices: make(map[string][]string),
+				},
+			},
+		},
+		{
+			description: "successfully created object with empty allocation",
+			claim: &resourcev1alpha2.ResourceClaim{
+				ObjectMeta: metav1.ObjectMeta{
+					UID:       claimUID,
+					Name:      claimName,
+					Namespace: namespace,
+				},
+				Status: resourcev1alpha2.ResourceClaimStatus{
+					DriverName: driverName,
+					Allocation: &resourcev1alpha2.AllocationResult{},
+				},
+				Spec: resourcev1alpha2.ResourceClaimSpec{
+					ResourceClassName: className,
+				},
+			},
+			expectedResult: &ClaimInfo{
+				ClaimInfoState: state.ClaimInfoState{
+					DriverName: driverName,
+					ClassName:  className,
+					ClaimUID:   claimUID,
+					ClaimName:  claimName,
+					Namespace:  claimName,
+					PodUIDs:    sets.New[string](),
+					ResourceHandles: []resourcev1alpha2.ResourceHandle{
+						{},
+					},
+					CDIDevices: make(map[string][]string),
+				},
+			},
+		},
+	} {
+		t.Run(test.description, func(t *testing.T) {
+			result := newClaimInfoFromClaim(test.claim)
+			if reflect.DeepEqual(result, test.expectedResult) {
+				t.Errorf("Expected %v, but got %v", test.expectedResult, result)
+			}
+		})
+	}
+}
+
+func TestNewClaimInfoFromState(t *testing.T) {
+	for _, test := range []struct {
+		description    string
+		state          *state.ClaimInfoState
+		expectedResult *ClaimInfo
+	}{
+		{
+			description: "successfully created object",
+			state: &state.ClaimInfoState{
+				DriverName:      "test-driver",
+				ClassName:       "test-class",
+				ClaimUID:        "test-uid",
+				ClaimName:       "test-claim",
+				Namespace:       "test-namespace",
+				PodUIDs:         sets.New[string]("test-pod-uid"),
+				ResourceHandles: []resourcev1alpha2.ResourceHandle{},
+				CDIDevices:      map[string][]string{},
+			},
+		},
+	} {
+		t.Run(test.description, func(t *testing.T) {
+			result := newClaimInfoFromState(test.state)
+			if reflect.DeepEqual(result, test.expectedResult) {
+				t.Errorf("Expected %v, but got %v", test.expectedResult, result)
+			}
+		})
+	}
+}
+
+func TestClaimInfoSetCDIDevices(t *testing.T) {
+	claimUID := types.UID("claim-uid")
+	pluginName := "test-plugin"
+	device := "vendor.com/device=device1"
+	annotationName := fmt.Sprintf("cdi.k8s.io/%s_%s", pluginName, claimUID)

Leaderboard for this case

hard · 0 of 9 bots fully caught it (0% solve rate) · 11% avg coverage.

#BotResultCaughtCoverageFindingsFalse alarms
1 cursor partial 1/3 25.0% 2 0
2 greptile partial 1/3 25.0% 2 0
3 Cubic partial 1/3 25.0% 3 1
4 Claude Code (Opus 5.5) miss 0/3 0.0% 3 0
5 Mjolnir (Opus 5.5) miss 0/3 0.0% 3 0
6 Mjolnir (Sonnet 5.5) miss 0/3 0.0% 2 0
7 qodo miss 0/3 0.0% 0 0
8 Drape (Deep Review) miss 0/3 0.0% 6 1
9 Drape (Review) miss 0/3 0.0% 6 1

Bot results

Claude Code (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
valid · impact high
The removed lines fell back to resourceClaim.Status.DriverName when the handle had no DriverName. newClaimInfoFromClaim still creates a single empty handle when there are no handles, so that handle's DriverName is empty. The claim gets batched under plugin "", NewDRAPluginClient fails, and pod startup fails. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
valid · impact high
The fallback to claimInfo.DriverName was removed from unprepare as well. Driver-less handles now go to plugin "", the unprepare fails, the claim stays in the cache and pod termination stays blocked. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
valid · impact low
The old cache.hasPodReference took an RLock. The new code takes the exclusive Lock for a read-only scan. The result is still correct, but readers are now serialized: a minor performance regression. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
raw comments (3)
pkg/kubelet/cm/dra/manager.go:238
PrepareResources no longer falls back to the claim's Status.DriverName when a resource handle has no DriverName. newClaimInfoFromClaim fills in one empty ResourceHandle when allocation.resourceHandles is empty, and it does this precisely so that the plugin named in resourceClaim.Status.DriverName handles the claim. Its DriverName is always "", so now the claim goes into batches[""]. dra.NewDRAPluginClient("") then fails, and any pod whose claim has no resource handles, or handles without DriverName (the case the comment in newClaimInfoFromClaim describes), can no longer start. The updated tests only pass because they now set DriverName on every handle.
pkg/kubelet/cm/dra/manager.go:469
unprepareResources has the same regression. It uses resourceHandle.DriverName directly and drops the old fallback to claimInfo.DriverName. A claim prepared with an empty or driver-less handle, including one restored from a checkpoint, is sent to plugin "". NodeUnprepareResources then always fails, so the claim is never unprepared and stays in the cache. PodMightNeedToUnprepareResources keeps returning true, which blocks pod termination. The new reconcile loop retries and fails every 60s.
pkg/kubelet/cm/dra/manager.go:531
PodMightNeedToUnprepareResources only reads the cache but takes the exclusive write lock (Lock) instead of RLock. The status manager calls it often, so it needlessly serializes with GetResources and GetContainerClaimInfos, which use withRLock.
Cubic · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✓ off by one
d3 medium ✗ —
invalid
The race is real, but the code before the change had it too. The old code also called deletion with no conditions after the RPC (`m.cache.delete(claimInfo.ClaimName, pod.Namespace)`), and a concurrent prepare could already see prepared=true and skip in the meantime. The failure would happen the same way without this change. [invalid: introduced=no] [consensus 5/5: invalid=5]
valid · impact high
The change removed the fallback to resourceClaim.Status.DriverName when the handle's DriverName is empty. When a claim has no handles, newClaimInfoFromClaim creates one empty handle, so pluginName is an empty string. NewDRAPluginClient then rejects it with 'plugin name is empty', so both prepare and unprepare fail for these claims. [grounded: diff] [consensus 5/5: valid=5]
valid · matches d2 · impact medium
raw comments (4)
pkg/kubelet/cm/dra/manager.go:512
<!-- cubic:v=553e7913-782d-45e0-a3e0-10be5168c811 --> <!-- cubic:review-run=70a92121-9751-546b-936b-91d041a6dc9a --> <!-- metadata:{"confidence":8} --> P1: If a prepare adds or updates a claim while this unprepare RPC is in flight, the final unconditional delete removes the newly active claim from the cache. Revalidate the claim's references/state after the RPC, or serialize prepare and unprepare operations through a per-claim lifecycle guard before deleting it. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At pkg/kubelet/cm/dra/manager.go, line 512: <comment>If a prepare adds or updates a claim while this unprepare RPC is in flight, the final unconditional delete removes the newly active claim from the cache. Revalidate the claim's references/state after the RPC, or serialize prepare and unprepare operations through a per-claim lifecycle guard before deleting it.</comment> <file context> @@ -404,21 +505,35 @@ func (m *ManagerImpl) UnprepareResources(pod *v1.Pod) error { + err := m.cache.withLock(func() error { + // Delete all claimInfos from the cache that have just been unprepared. + for _, claimName := range claimNamesMap { + m.cache.delete(claimName, namespace) + } + </file context> ``` </details>
pkg/kubelet/cm/dra/manager.go:235
<!-- cubic:v=4b5351e8-2767-4d60-a13c-537a07b2b461 --> <!-- cubic:review-run=70a92121-9751-546b-936b-91d041a6dc9a --> <!-- metadata:{"confidence":10} --> P1: When an allocation has no `resourceHandles`, `newClaimInfoFromClaim` synthesizes an empty handle, but this line batches it under an empty plugin name. `NewDRAPluginClient("")` rejects that name, so preparation and cleanup fail for the documented single-plugin allocation path. Fall back to `claimInfo.DriverName` when `resourceHandle.DriverName` is empty in both prepare and unprepare batching. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At pkg/kubelet/cm/dra/manager.go, line 235: <comment>When an allocation has no `resourceHandles`, `newClaimInfoFromClaim` synthesizes an empty handle, but this line batches it under an empty plugin name. `NewDRAPluginClient("")` rejects that name, so preparation and cleanup fail for the documented single-plugin allocation path. Fall back to `claimInfo.DriverName` when `resourceHandle.DriverName` is empty in both prepare and unprepare batching.</comment> <file context> @@ -108,48 +192,55 @@ func (m *ManagerImpl) PrepareResources(pod *v1.Pod) error { + if resourceHandle.StructuredData != nil { + claim.StructuredResourceHandle = []*resourceapi.StructuredResourceHandle{resourceHandle.StructuredData} + } + pluginName := resourceHandle.DriverName + batches[pluginName] = append(batches[pluginName], claim) } </file context> ``` </details>
pkg/kubelet/cm/dra/claiminfo_test.go:117
<!-- cubic:v=ace9f1cf-f139-494f-9b18-17b70d1b319a --> <!-- cubic:review-run=70a92121-9751-546b-936b-91d041a6dc9a --> <!-- metadata:{"confidence":10} --> P3: These constructor tests silently pass without validating the result: they call `t.Errorf` when values are equal, while one expected object has the wrong namespace and the other expected object is nil. Invert the assertion and populate expected values that match the constructor's initialized fields. <details> <summary>Prompt for AI agents</summary> ```text Check if this issue is valid — if so, understand the root cause and fix it. At pkg/kubelet/cm/dra/claiminfo_test.go, line 117: <comment>These constructor tests silently pass without validating the result: they call `t.Errorf` when values are equal, while one expected object has the wrong namespace and the other expected object is nil. Invert the assertion and populate expected values that match the constructor's initialized fields.</comment> <file context> @@ -0,0 +1,894 @@ + } { + t.Run(test.description, func(t *testing.T) { + result := newClaimInfoFromClaim(test.claim) + if reflect.DeepEqual(result, test.expectedResult) { + t.Errorf("Expected %v, but got %v", test.expectedResult, result) + } </file context> ``` </details>
PR-level
<!-- cubic:review-summary:start --> **3 issues found** across 9 files <!-- cubic:review-summary:end --> <details> <summary>Prompt for AI agents (unresolved issues)</summary> ```text Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately. <file name="pkg/kubelet/cm/dra/claiminfo_test.go"> <violation number="1" location="pkg/kubelet/cm/dra/claiminfo_test.go:117"> P3: These constructor tests silently pass without validating the result: they call `t.Errorf` when values are equal, while one expected object has the wrong namespace and the other expected object is nil. Invert the assertion and populate expected values that match the constructor's initialized fields.</violation> </file> <file name="pkg/kubelet/cm/dra/manager.go"> <violation number="1" location="pkg/kubelet/cm/dra/manager.go:235"> P1: When an allocation has no `resourceHandles`, `newClaimInfoFromClaim` synthesizes an empty handle, but this line batches it under an empty plugin name. `NewDRAPluginClient("")` rejects that name, so preparation and cleanup fail for the documented single-plugin allocation path. Fall back to `claimInfo.DriverName` when `resourceHandle.DriverName` is empty in both prepare and unprepare batching.</violation> <violation number="2" location="pkg/kubelet/cm/dra/manager.go:512"> P1: If a prepare adds or updates a claim while this unprepare RPC is in flight, the final unconditional delete removes the newly active claim from the cache. Revalidate the claim's references/state after the RPC, or serialize prepare and unprepare operations through a per-claim lifecycle guard before deleting it.</violation> </file> ``` </details> <sub>Reply with feedback, questions, or to request a fix.<br /><br />[Re-trigger cubic](https://www.cubic.dev/action/re-review/pr/drape-io/crbench-cubic-2026-09/48/ai_pr_review_github_delivery_28324058f6262b05a441fc683ce17a12330c36dd7db47c5e19bbef3d106d327d?returnTo=https%3A%2F%2Fgithub.com%2Fdrape-io%2Fcrbench-cubic-2026-09%2Fpull%2F48)</sub> <!-- cubic:review-post:ai_pr_review_github_delivery_28324058f6262b05a441fc683ce17a12330c36dd7db47c5e19bbef3d106d327d:1e30ebd5d09f070c9b820bc42cde0bf5e69a3279:70a92121-9751-546b-936b-91d041a6dc9a -->
cursor · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✓ off by one
d3 medium ✗ —
valid · impact high
The diff removed the fallback that set pluginName to Status.DriverName when it was empty. newClaimInfoFromClaim still makes one empty ResourceHandle when there are none, so pluginName is empty. NewDRAPluginClient returns 'plugin name is empty' for that, so these claims can no longer be prepared or unprepared. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 5/5: valid=5]
valid · matches d2 · impact medium
raw comments (3)
pkg/kubelet/cm/dra/manager.go:236
### Empty handle DriverName skips plugin fallback **High Severity** <!-- DESCRIPTION START --> `PrepareResources` and `unprepareResources` now take the plugin name only from `resourceHandle.DriverName`. Claims with no `ResourceHandles` still get a synthetic empty handle, and the cache comment still says that case should use `Status.DriverName` (`claimInfo.DriverName`). `NewDRAPluginClient` rejects an empty name, so those claims never prepare or unprepare and can remain stuck in the checkpoint. <!-- DESCRIPTION END --> <!-- BUGBOT_BUG_ID: 4a5a7e6d-1620-49f4-a241-f6a44b653e0e --> <!-- LOCATIONS START pkg/kubelet/cm/dra/manager.go#L234-L236 pkg/kubelet/cm/dra/manager.go#L465-L467 LOCATIONS END --> <details> <summary>Additional Locations (1)</summary> - [`pkg/kubelet/cm/dra/manager.go#L465-L467`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8e246a42bd4c932eaf1004da274e0e2f5310a37/pkg/kubelet/cm/dra/manager.go#L465-L467) </details> <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjQxODJiY2Q2LWI2ZGItNDRhNy1iMTJjLTJlYzQ4ODAxY2JmYyIsImVuY3J5cHRpb25LZXkiOiI3YUNNdXVrUUEwVFZneGpyMkVfMU5xRlI2Nm4ydFduYkdsYjd3MTBvRHp3IiwiYnJhbmNoIjoidDItazhzLTEyNDMyMyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90OjQxODJiY2Q2LWI2ZGItNDRhNy1iMTJjLTJlYzQ4ODAxY2JmYyIsImVuY3J5cHRpb25LZXkiOiI3YUNNdXVrUUEwVFZneGpyMkVfMU5xRlI2Nm4ydFduYkdsYjd3MTBvRHp3IiwiYnJhbmNoIjoidDItazhzLTEyNDMyMyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjQ5LCJjb21taXRTaGEiOiJhOGUyNDZhNDJiZDRjOTMyZWFmMTAwNGRhMjc0ZTBlMmY1MzEwYTM3IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8e246a42bd4c932eaf1004da274e0e2f5310a37. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
pkg/kubelet/cm/dra/claiminfo_test.go:119
### Constructor tests assert the opposite result **Low Severity** <!-- DESCRIPTION START --> `TestNewClaimInfoFromClaim` and `TestNewClaimInfoFromState` call `t.Errorf` when `reflect.DeepEqual` succeeds, so they fail on a correct result and pass on a mismatch. Expected `Namespace` is also set to `claimName` instead of `namespace`, and `TestNewClaimInfoFromState` leaves `expectedResult` nil, so these tests never validate the constructors. <!-- DESCRIPTION END --> <!-- BUGBOT_BUG_ID: c21f5f62-7fa8-4609-830d-8659afc9133d --> <!-- LOCATIONS START pkg/kubelet/cm/dra/claiminfo_test.go#L115-L119 pkg/kubelet/cm/dra/claiminfo_test.go#L144-L148 pkg/kubelet/cm/dra/claiminfo_test.go#L73-L75 LOCATIONS END --> <details> <summary>Additional Locations (2)</summary> - [`pkg/kubelet/cm/dra/claiminfo_test.go#L144-L148`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8e246a42bd4c932eaf1004da274e0e2f5310a37/pkg/kubelet/cm/dra/claiminfo_test.go#L144-L148) - [`pkg/kubelet/cm/dra/claiminfo_test.go#L73-L75`](https://github.com/drape-io/crbench-cursor-2026-09/blob/a8e246a42bd4c932eaf1004da274e0e2f5310a37/pkg/kubelet/cm/dra/claiminfo_test.go#L73-L75) </details> <div><a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9DVVJTT1IiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90Ojc5ODcyZDFkLTdlMDMtNDQzZS1iNzYwLTNlZjFhYWZmODIwNSIsImVuY3J5cHRpb25LZXkiOiJkUjl4b2JRX1NMSDRmdWZtTnJtclhXaDJIX1BGNGJ0c3FsQ2pwNUNHYTQwIiwiYnJhbmNoIjoidDItazhzLTEyNDMyMyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a>&nbsp;<a href="https://cursor.com/agents?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9JTl9XRUIiLCJkYXRhIjp7InJlZGlzS2V5IjoiYnVnYm90Ojc5ODcyZDFkLTdlMDMtNDQzZS1iNzYwLTNlZjFhYWZmODIwNSIsImVuY3J5cHRpb25LZXkiOiJkUjl4b2JRX1NMSDRmdWZtTnJtclhXaDJIX1BGNGJ0c3FsQ2pwNUNHYTQwIiwiYnJhbmNoIjoidDItazhzLTEyNDMyMyIsInJlcG9Pd25lciI6ImRyYXBlLWlvIiwicmVwb05hbWUiOiJjcmJlbmNoLWN1cnNvci0yMDI2LTA5IiwicHJOdW1iZXIiOjQ5LCJjb21taXRTaGEiOiJhOGUyNDZhNDJiZDRjOTMyZWFmMTAwNGRhMjc0ZTBlMmY1MzEwYTM3IiwicHJvdmlkZXIiOiJnaXRodWIifX0" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-web-light.png"><img alt="Fix in Web" width="99" height="28" src="https://cursor.com/assets/images/fix-in-web-dark.png"></picture></a></div> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8e246a42bd4c932eaf1004da274e0e2f5310a37. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
PR-level
<!-- BUGBOT_REVIEW --> Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues. <!-- BUGBOT_FIX_ALL --> <a href="https://cursor.com/open?link=eyJ2ZXJzaW9uIjoxLCJ0eXBlIjoiQlVHQk9UX0ZJWF9BTExfSU5fQ1VSU09SIiwiZGF0YSI6eyJyZWRpc0tleSI6ImJ1Z2JvdC1tdWx0aTo0ZmQxODhjYi01MGRiLTRhNDctODkxZC1mYWQwMmYwOGQ3NmUiLCJlbmNyeXB0aW9uS2V5IjoibWNEMVZER0tiWnhRNmxGbXZqSFVfR3EwY051aWlRaFZySEZyY3dlQzN5QSIsImJyYW5jaCI6InQyLWs4cy0xMjQzMjMiLCJyZXBvT3duZXIiOiJkcmFwZS1pbyIsInJlcG9OYW1lIjoiY3JiZW5jaC1jdXJzb3ItMjAyNi0wOSIsInByb3ZpZGVyIjoiZ2l0aHViIn19" target="_blank" rel="noopener noreferrer"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/fix-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/fix-in-cursor-light.png"><img alt="Fix All in Cursor" width="115" height="28" src="https://cursor.com/assets/images/fix-in-cursor-dark.png"></picture></a> <!-- /BUGBOT_FIX_ALL --> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_BEGIN --> <sup>❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).</sup> <!-- BUGBOT_AUTOFIX_REVIEW_FOOTNOTE_END --> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a8e246a42bd4c932eaf1004da274e0e2f5310a37. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup>
Drape (Deep Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
valid · impact high
The diff removed the fallback to resourceClaim.Status.DriverName, and newClaimInfoFromClaim creates a single empty handle when there are no resourceHandles. Those claims are batched under an empty plugin name, which NewDRAPluginClient rejects. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
valid · impact high
The fallback to claimInfo.DriverName was also removed in unprepareResources. Handles with no driver name go to an empty plugin name, so the lookup fails on every attempt. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
valid · impact low
The old restore path returned an error from addCDIDevices. The new code drops the error, so a malformed device name silently produces no annotations. [grounded: tree pkg/kubelet/cm/dra/claiminfo.go] [consensus 3/3: valid=3]
valid · impact low
hasPodReference used RLock before this change. The read-only path now takes the exclusive lock, which needlessly serializes readers. This is a small contention regression. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
invalid
The base code had the same window: it looked up the claim, made the RPC, and then deleted the claim without re-checking for other pod references. The race existed before this change and was not introduced by it. [invalid: introduced=no] [consensus 3/3: invalid=3]
valid · impact low
Each claim now triggers a checkpoint write while the write lock is held. This looks like a deliberate trade for crash safety, and pods have few claims, so the performance cost is minor. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
raw comments (6)
pkg/kubelet/cm/dra/manager.go:235
**Claims without resource handles can't be prepared** When a claim's allocation has no resourceHandles, `newClaimInfoFromClaim` makes one empty handle with no driver name, and the fallback to `claim.Status.DriverName` was removed here. The batch is then keyed by "", so plugin lookup fails and the pod never starts. Fall back to `claimInfo.DriverName` when `resourceHandle.DriverName` is empty. ``` pkg/kubelet/cm/dra/manager.go:235 pluginName := resourceHandle.DriverName pkg/kubelet/cm/dra/manager.go:236 batches[pluginName] = append(batches[pluginName], claim) pkg/kubelet/cm/dra/manager.go:131 (base) } pkg/kubelet/cm/dra/manager.go:133 (base) // Loop through all plugins and prepare for calling NodePrepareResources. pkg/kubelet/cm/dra/plugin/client.go:32 func NewDRAPluginClient(pluginName string) (drapb.NodeClient, error) { pkg/kubelet/cm/dra/plugin/client.go:33 if pluginName == "" { pkg/kubelet/cm/dra/plugin/client.go:34 return nil, fmt.Errorf("plugin name is empty") pkg/kubelet/cm/dra/plugin/client.go:35 } staging/src/k8s.io/api/resource/v1alpha2/types.go:156 // Setting this field is optional. It has a maximum size of 32 entries. staging/src/k8s.io/api/resource/v1alpha2/types.go:157 // If null (or empty), it is assumed this allocation will be processed by a ```
pkg/kubelet/cm/dra/manager.go:465
**Claims without resource handles never get unprepared** The fallback to `claimInfo.DriverName` for an empty `resourceHandle.DriverName` was also removed in `unprepareResources`. Claims with no resourceHandles are therefore sent to plugin "", the lookup fails, and the pod (and every later reconcile pass) can't unprepare them. Use `claimInfo.DriverName` when `resourceHandle.DriverName` is empty. ``` pkg/kubelet/cm/dra/manager.go:453 claimNamesMap[claimInfo.ClaimUID] = claimInfo.ClaimName pkg/kubelet/cm/dra/manager.go:455 // Loop through all plugins and prepare for calling NodeUnprepareResources. pkg/kubelet/cm/dra/manager.go:456 for _, resourceHandle := range claimInfo.ResourceHandles { pkg/kubelet/cm/dra/manager.go:457 claim := &drapb.Claim{ pkg/kubelet/cm/dra/plugin/client.go:32 func NewDRAPluginClient(pluginName string) (drapb.NodeClient, error) { pkg/kubelet/cm/dra/plugin/client.go:33 if pluginName == "" { pkg/kubelet/cm/dra/plugin/client.go:34 return nil, fmt.Errorf("plugin name is empty") pkg/kubelet/cm/dra/plugin/client.go:35 } pkg/kubelet/cm/dra/claiminfo.go:55 resourceHandles := claim.Status.Allocation.ResourceHandles pkg/kubelet/cm/dra/claiminfo.go:56 if len(resourceHandles) == 0 { ```
pkg/kubelet/cm/dra/claiminfo.go:85
**Checkpoint restore silently drops bad CDI annotations** `newClaimInfoFromState` throws away the error from `cdi.GenerateAnnotations`. The old restore path failed cache creation instead. A malformed checkpointed device name now leaves the claim with no annotations, and nothing is logged. Return the error from `newClaimInfoFromState` and propagate it from `newClaimInfoCache`. ``` pkg/kubelet/cm/dra/claiminfo.go:77 // newClaimInfoFromClaim creates a new claim info from a checkpointed claim info state object. pkg/kubelet/cm/dra/claiminfo.go:78 func newClaimInfoFromState(state *state.ClaimInfoState) *ClaimInfo { pkg/kubelet/cm/dra/claiminfo.go:79 info := &ClaimInfo{ pkg/kubelet/cm/dra/claiminfo.go:80 ClaimInfoState: *state.DeepCopy(), pkg/kubelet/cm/dra/claiminfo.go:96 annotations, err := cdi.GenerateAnnotations(info.ClaimUID, info.DriverName, cdiDevices) pkg/kubelet/cm/dra/claiminfo.go:97 if err != nil { pkg/kubelet/cm/dra/claiminfo.go:98 return fmt.Errorf("failed to generate container annotations, err: %+v", err) ```
pkg/kubelet/cm/dra/manager.go:531
**Read-only status check takes the write lock** `PodMightNeedToUnprepareResources` only reads the cache but takes the exclusive lock. Every status-manager check now waits behind, and blocks, every other cache reader. Use `m.cache.RLock()`/`RUnlock()` (or `withRLock`). ``` pkg/kubelet/cm/dra/manager.go:531 m.cache.Lock() pkg/kubelet/cm/dra/manager.go:532 defer m.cache.Unlock() pkg/kubelet/cm/dra/claiminfo.go:193 func (cache *claimInfoCache) withRLock(f func() error) error { pkg/kubelet/cm/dra/claiminfo.go:194 cache.RLock() pkg/kubelet/cm/dra/claiminfo.go:195 defer cache.RUnlock() pkg/kubelet/cm/dra/claiminfo.go:196 return f() pkg/kubelet/cm/dra/claiminfo.go:197 } ```
pkg/kubelet/cm/dra/manager.go:512
**Unprepare can drop a new pod's claim reference** `unprepareResources` releases the lock between choosing a claim and deleting it. Another pod's `PrepareResources` on the same shared claim can run in between, see `isPrepared()` and return; its reference is then deleted along with the claim. Re-check under the lock that no other pod references the claim before deleting it. ``` pkg/kubelet/cm/dra/manager.go:440 if len(claimInfo.PodUIDs) > 1 { pkg/kubelet/cm/dra/manager.go:441 // We delay checkpointing of this change until pkg/kubelet/cm/dra/manager.go:442 // UnprepareResources returns successfully. It is OK to do pkg/kubelet/cm/dra/manager.go:443 // this because we will only return successfully from this call pkg/kubelet/cm/dra/manager.go:215 // If this claim is already prepared, there is no need to prepare it again. pkg/kubelet/cm/dra/manager.go:216 if claimInfo.isPrepared() { pkg/kubelet/cm/dra/manager.go:217 return nil pkg/kubelet/cm/dra/manager.go:218 } pkg/kubelet/cm/dra/manager.go:511 for _, claimName := range claimNamesMap { pkg/kubelet/cm/dra/manager.go:512 m.cache.delete(claimName, namespace) ```
pkg/kubelet/cm/dra/manager.go:211
**Checkpoint written to disk once per claim** `PrepareResources` now calls `syncToCheckpoint` inside the per-claim loop while holding the cache write lock. A pod with N claims gets N full checkpoint writes, and every other cache reader is blocked during the disk I/O. Add all pod references first, then checkpoint once before calling the plugins. ``` pkg/kubelet/cm/dra/manager.go:196 err = m.cache.withLock(func() error { pkg/kubelet/cm/dra/manager.go:197 // Get a reference to the claim info for this claim from the cache. pkg/kubelet/cm/dra/manager.go:198 // If there isn't one yet, then add it to the cache. pkg/kubelet/cm/dra/manager.go:199 claimInfo, exists := m.cache.get(resourceClaim.Name, resourceClaim.Namespace) pkg/kubelet/cm/dra/claiminfo.go:236 func (cache *claimInfoCache) syncToCheckpoint() error { pkg/kubelet/cm/dra/claiminfo.go:237 claimInfoStateList := make(state.ClaimInfoStateList, 0, len(cache.claimInfo)) pkg/kubelet/cm/dra/claiminfo.go:238 for _, infoClaim := range cache.claimInfo { pkg/kubelet/cm/dra/claiminfo.go:239 claimInfoStateList = append(claimInfoStateList, infoClaim.ClaimInfoState) pkg/kubelet/cm/dra/claiminfo.go:240 } pkg/kubelet/cm/dra/claiminfo.go:241 return cache.state.Store(claimInfoStateList) ```
Drape (Review) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
valid · impact low
The old hasPodReference used cache.RLock; the new wrapper takes the exclusive Lock for a read-only scan. That needlessly serializes concurrent readers. It is a real but small performance regression. [grounded: diff] [consensus 3/3: valid=3]
valid · impact high
The removed lines fell back to claimInfo.DriverName when the handle's driver name was empty. newClaimInfoFromClaim still creates an empty synthetic handle, so unprepare now batches under plugin "" and NewDRAPluginClient("") fails. [grounded: diff] [consensus 3/3: valid=3]
invalid
The race is real: unprepare checks for a sole reference, makes the RPC, then deletes the claim, and a concurrent prepare can join in between. The old code had the same check, RPC, then delete sequence with no locking, so this window existed before the change. [invalid: introduced=no] [consensus 3/3: invalid=3]
valid · impact high
The fallback to Status.DriverName was removed. Claims without allocation handles get a synthetic empty handle, which is now batched under plugin "" and fails to prepare. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
The old restore path returned an error when addCDIDevices failed. The new path silently drops the error, so annotations can go missing without any signal. [grounded: diff] [consensus 3/3: valid=3]
valid · impact low
A checkpoint is now written under the write lock for every claim plus once at the end. Previously it was written once per plugin batch plus once at the end. This is a real but small performance cost, and largely intentional for crash safety. [grounded: diff] [consensus 3/3: valid=3]
raw comments (6)
pkg/kubelet/cm/dra/manager.go:531
**Read-only check takes exclusive cache lock** `PodMightNeedToUnprepareResources` now takes the write lock (`m.cache.Lock()`) for a read-only scan. The status manager calls it often, so it blocks all `GetResources` and `GetContainerClaimInfos` readers. Use `m.cache.RLock()` and `RUnlock()`. ``` pkg/kubelet/cm/dra/manager.go:529 // unprepare resources pkg/kubelet/cm/dra/manager.go:530 func (m *ManagerImpl) PodMightNeedToUnprepareResources(UID types.UID) bool { pkg/kubelet/cm/dra/manager.go:531 m.cache.Lock() pkg/kubelet/cm/dra/claiminfo.go:226 func (cache *claimInfoCache) hasPodReference(UID types.UID) bool { pkg/kubelet/cm/dra/claiminfo.go:227 for _, claimInfo := range cache.claimInfo { pkg/kubelet/cm/dra/claiminfo.go:228 if claimInfo.hasPodReference(UID) { pkg/kubelet/cm/dra/claiminfo.go:229 return true pkg/kubelet/cm/dra/claiminfo.go:230 } pkg/kubelet/cm/dra/claiminfo.go:231 } pkg/kubelet/cm/dra/claiminfo.go:232 return false ```
pkg/kubelet/cm/dra/manager.go:492
**Unprepare loses driver name fallback** `unprepareResources` batches by `resourceHandle.DriverName` only and no longer falls back to `claimInfo.DriverName`. Claims with empty handle driver names are sent to plugin "" and can never be unprepared. Use `claimInfo.DriverName` when `resourceHandle.DriverName` is empty. ``` pkg/kubelet/cm/dra/manager.go:470 return nil pkg/kubelet/cm/dra/manager.go:431 (base) for _, claim := range container.Resources.Claims { pkg/kubelet/cm/dra/manager.go:432 (base) if podResourceClaim.Name != claim.Name { pkg/kubelet/cm/dra/manager.go:433 (base) continue pkg/kubelet/cm/dra/claiminfo.go:49 // newClaimInfoFromClaim creates a new claim info from a resource claim. pkg/kubelet/cm/dra/claiminfo.go:50 func newClaimInfoFromClaim(claim *resourcev1alpha2.ResourceClaim) *ClaimInfo { pkg/kubelet/cm/dra/claiminfo.go:51 // Grab the allocation.resourceHandles. If there are no pkg/kubelet/cm/dra/claiminfo.go:52 // allocation.resourceHandles, create a single resourceHandle with no pkg/kubelet/cm/dra/claiminfo.go:53 // content. This will trigger processing of this claim by a single pkg/kubelet/cm/dra/claiminfo.go:54 // kubelet plugin whose name matches resourceClaim.Status.DriverName. ```
pkg/kubelet/cm/dra/manager.go:508
**Shared claim deleted while another pod starts** The sole-reference check and the delete run in separate lock sections, with the RPC between them. A pod that joins meanwhile skips prepare and then loses the claim. In the final withLock, remove podUID and delete only if PodUIDs is empty. ``` pkg/kubelet/cm/dra/manager.go:441 // We delay checkpointing of this change until pkg/kubelet/cm/dra/manager.go:442 // UnprepareResources returns successfully. It is OK to do pkg/kubelet/cm/dra/manager.go:443 // this because we will only return successfully from this call pkg/kubelet/cm/dra/manager.go:444 // if the checkpoint has succeeded. That means if the kubelet pkg/kubelet/cm/dra/claiminfo.go:167 curState, err := stateImpl.GetOrCreate() pkg/kubelet/cm/dra/claiminfo.go:168 if err != nil { pkg/kubelet/cm/dra/claiminfo.go:169 return nil, fmt.Errorf("error calling GetOrCreate() on checkpoint state: %v", err) pkg/kubelet/cm/dra/claiminfo.go:170 } ```
pkg/kubelet/cm/dra/manager.go:236
**Prepare sends empty driver name to plugin** PrepareResources now batches by `resourceHandle.DriverName` directly, dropping the old fallback to the claim's `Status.DriverName`. Handles with no driver name, including the synthetic empty handle, go to plugin "". Fall back to claimInfo.DriverName when resourceHandle.DriverName is empty. ``` pkg/kubelet/cm/dra/manager.go:222 resourceClaims[claimInfo.ClaimUID] = resourceClaim pkg/kubelet/cm/dra/manager.go:224 // Loop through all plugins and prepare for calling NodePrepareResources. pkg/kubelet/cm/dra/manager.go:120 (base) // will only return successfully from this call if the pkg/kubelet/cm/dra/manager.go:121 (base) // checkpoint has succeeded. That means if the kubelet is pkg/kubelet/cm/dra/manager.go:122 (base) // ever restarted before this checkpoint succeeds, the pod pkg/kubelet/cm/dra/manager.go:123 (base) // whose resources are being prepared would never have pkg/kubelet/cm/dra/manager.go:124 (base) // started, so it's OK (actually correct) to not include it pkg/kubelet/cm/dra/manager.go:125 (base) // in the cache. pkg/kubelet/cm/dra/manager.go:126 (base) claimInfo.addPodReference(pod.UID) pkg/kubelet/cm/dra/manager.go:128 (base) if claimInfo.prepared { ```
pkg/kubelet/cm/dra/claiminfo.go:92
**CDI annotation errors ignored on checkpoint restore** newClaimInfoFromState discards the error from `cdi.GenerateAnnotations`. The old restore path returned an error when adding CDI devices failed. Return the error from newClaimInfoFromState and propagate it from newClaimInfoCache. ``` pkg/kubelet/cm/dra/claiminfo.go:83 } pkg/kubelet/cm/dra/claiminfo.go:84 for pluginName, devices := range info.CDIDevices { pkg/kubelet/cm/dra/claiminfo.go:85 annotations, _ := cdi.GenerateAnnotations(info.ClaimUID, info.DriverName, devices) pkg/kubelet/cm/dra/claiminfo.go:86 info.annotations[pluginName] = append(info.annotations[pluginName], annotations...) pkg/kubelet/cm/dra/claiminfo.go:154 (base) info := newClaimInfo( pkg/kubelet/cm/dra/claiminfo.go:155 (base) entry.DriverName, pkg/kubelet/cm/dra/claiminfo.go:156 (base) entry.ClassName, pkg/kubelet/cm/dra/claiminfo.go:157 (base) entry.ClaimUID, pkg/kubelet/cm/dra/claiminfo.go:158 (base) entry.ClaimName, pkg/kubelet/cm/dra/claiminfo.go:159 (base) entry.Namespace, ```
pkg/kubelet/cm/dra/manager.go:205
**Checkpoint written per claim under write lock** `PrepareResources` calls `syncToCheckpoint` (full file write) inside the cache write lock for every claim, plus a final sync. A pod with N claims does N+1 checkpoints while blocking readers such as GetResources. Add pod references for all claims first, then checkpoint once before the RPCs. ``` pkg/kubelet/cm/dra/manager.go:195 // Atomically perform some operations on the claimInfo cache. pkg/kubelet/cm/dra/manager.go:196 err = m.cache.withLock(func() error { pkg/kubelet/cm/dra/manager.go:197 // Get a reference to the claim info for this claim from the cache. pkg/kubelet/cm/dra/manager.go:198 // If there isn't one yet, then add it to the cache. ```
greptile · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✓ exact
d3 medium ✗ —
valid · impact high
The diff removes the fallback to the claim's Status.DriverName for handles with an empty DriverName. newClaimInfoFromClaim deliberately creates an empty handle when a claim has none, so that handle now goes into an empty-name batch. NewDRAPluginClient returns an error for an empty plugin name (client.go:33), so prepare fails. The same thing happens on unprepare for checkpointed handles that have no driver name. [grounded: diff] [consensus 3/3: valid=3]
valid · matches d2 · impact medium
raw comments (3)
pkg/kubelet/cm/dra/manager.go:236
<a href="#"><img alt="P1" src="https://greptile-static-assets.s3.amazonaws.com/badges/p1.svg?v=9" align="top"></a> **Claim driver fallback removed** When a claim has no resource handles, `newClaimInfoFromClaim` intentionally creates an empty handle that must use the claim-level `DriverName`. This code instead batches it under the handle’s empty driver name, which `NewDRAPluginClient` rejects. As a result, valid claims cannot be prepared. The same missing fallback at lines 466–467 also prevents affected checkpointed claims from being unprepared.
pkg/kubelet/cm/dra/claiminfo_test.go:119
<a href="#"><img alt="P2" src="https://greptile-static-assets.s3.amazonaws.com/badges/p2.svg?v=9" align="top"></a> **Constructor assertions are inverted** This check reports an error when the actual and expected values match, while accepting mismatches. The fixtures currently guarantee a mismatch because the expected namespace is wrong and other expected state is missing, so constructor regressions pass unnoticed. Correct the expected objects and assert equality here and in `TestNewClaimInfoFromState` at lines 146–148. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
PR-level
<h3>Greptile Summary</h3> This PR refactors DRA claim state around a cache-wide lock, adds periodic reconciliation for stale pod references, deep-copies claim information returned to callers, and expands unit and concurrency coverage. - Starts DRA reconciliation from the container manager. - Persists claim references before plugin preparation and reconciles inactive pods. - Adds generated deep-copy implementations for claim state. - Introduces a blocking regression for claims whose resource handles rely on the claim-level driver fallback. - Adds constructor tests whose inverted assertions currently provide no regression protection. <h3>Confidence Score: 4/5</h3> The PR is not safe to merge until resource handles with an empty driver name retain the claim-level driver fallback required for preparation and cleanup. Empty or legacy resource handles are now batched under an empty plugin name, which the plugin client explicitly rejects, preventing affected DRA claims from being prepared or unprepared; the new constructor tests also fail to guard their behavior. **Files Needing Attention:** pkg/kubelet/cm/dra/manager.go, pkg/kubelet/cm/dra/claiminfo_test.go <details><summary><h3>Important Files Changed</h3></summary> | Filename | Overview | |----------|----------| | pkg/kubelet/cm/dra/manager.go | Refactors synchronized claim preparation and unpreparation and adds reconciliation, but drops the required claim-level driver fallback. | | pkg/kubelet/cm/dra/claiminfo.go | Centralizes claim cache locking, introduces constructors and deep-copy-compatible claim state, and documents the empty-handle fallback contract. | | pkg/kubelet/cm/dra/claiminfo_test.go | Adds broad cache and claim tests, but both constructor tests use inverted assertions and invalid expected values. | | pkg/kubelet/cm/container_manager_linux.go | Starts the DRA reconciliation loop and consumes deep-copied claim information without per-claim locking. | | pkg/kubelet/cm/dra/state/zz_generated.deepcopy.go | Adds generated deep-copy support for checkpointed claim state. | | pkg/kubelet/cm/dra/zz_generated.deepcopy.go | Adds generated deep-copy support for runtime claim information. | </details> <details open><summary><h3>Flowchart</h3></summary> ```mermaid %%{init: {'theme': 'neutral'}}%% flowchart TD A[Kubelet starts DRA manager] --> B[Periodic reconciliation] B --> C{Configuration sources ready?} C -- No --> B C -- Yes --> D[Compare checkpoint references with active pods] D --> E[Unprepare inactive pod claims] F[Pod preparation] --> G[Fetch ResourceClaim] G --> H[Add pod reference and checkpoint] H --> I[Batch handles by DRA driver] I --> J[NodePrepareResources] J --> K[Store CDI devices and prepared state] ``` </details> <!-- greptile_other_comments_section --> <sub>Reviews (1): Last reviewed commit: ["Update pkg/kubelet/cm/container\_manager\_..."](https://github.com/drape-io/crbench-greptile-2026-09/commit/562303a530b416f3e07ef075e469c8336abaa8c0) | [Re-trigger Greptile](https://app.greptile.com/api/retrigger?id=64284539)</sub>
Mjolnir (Opus 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
valid · impact high
The diff removes the fallback, but newClaimInfoFromClaim still creates a zero-value handle when there are no ResourceHandles. As a result pluginName becomes empty, and NewDRAPluginClient returns the error 'plugin name is empty'. [grounded: diff] [consensus 3/3: valid=3]
valid · impact high
unprepareResources dropped the same fallback, so claims with an empty handle are batched under an empty plugin name. The client creation fails and the unprepare errors out before the cache entry is deleted. [grounded: diff] [consensus 3/3: valid=3]
valid · impact high
This finding combines the prepare and unprepare cases. Both fallbacks were removed while the empty placeholder handle is still created, so NewDRAPluginClient fails with an empty name. [grounded: diff] [consensus 3/3: valid=3]
raw comments (3)
pkg/kubelet/cm/dra/manager.go:235
[P1] The plugin name is empty for claims that have no ResourceHandles `newClaimInfoFromClaim` still adds one empty `ResourceHandle` when `claim.Status.Allocation.ResourceHandles` is empty. That empty handle is meant to send the claim to the kubelet plugin named in `claim.Status.DriverName`. However, this change dropped the `if pluginName == "" { pluginName = ...DriverName }` fallback, so the claim is now batched under `""`. `dra.NewDRAPluginClient("")` then fails, and `PrepareResources` returns an error. Pods using a claim whose allocation has no resource handles can no longer start. The pod reference has also already been checkpointed into the cache at that point.
pkg/kubelet/cm/dra/manager.go:466
[P1] Unprepare has the same empty-plugin-name problem for claims without ResourceHandles In `unprepareResources`, the fallback to `claimInfo.DriverName` for handles with an empty `DriverName` was also removed. For claims created with the placeholder empty handle, `NodeUnprepareResources` is sent to plugin `""` and always fails. The claim info is never removed from the cache. `PodMightNeedToUnprepareResources` therefore keeps returning true and blocks pod termination. The new reconcile loop retries the same failure every period.
pkg/kubelet/cm/dra/manager.go:557
[P1] Empty resource-handle driver name no longer falls back to the claim's driver name. Location (the same issue is at pkg/kubelet/cm/dra/manager.go:789-790). The old code used `resourceClaim.Status.DriverName` (or `claimInfo.DriverName` in unprepare) when `resourceHandle.DriverName` was empty, and this change removes that fallback. `newClaimInfoFromClaim` still creates a single zero-value `ResourceHandle` when `Status.Allocation.ResourceHandles` is empty, so that handle has `DriverName == ""`. Its own comment says this handle should go to the plugin named in `Status.DriverName`. Instead, the claim is batched under `""`, and `dra.NewDRAPluginClient("")` always returns "plugin name is empty". This affects any claim allocated without resource handles, which the API allows, and any older checkpoint entry whose handles have no driver name. For those claims, PrepareResources always fails, so the pod never starts. UnprepareResources and the new reconcile loop also fail for them, so the claim info and pod reference are never cleaned up
Mjolnir (Sonnet 5.5) · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
valid · impact high
The diff removes the fallback that set pluginName to Status.DriverName when it was empty, in both prepare and unprepare. newClaimInfoFromClaim still creates an empty placeholder ResourceHandle when there are none. Such claims are now batched under an empty plugin name, and NewDRAPluginClient fails for that name. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
valid · impact high
This is the same defect as finding 0. The fallback to the claim's DriverName was removed in both paths. The placeholder handle with an empty DriverName now batches under an empty plugin name, and the plugin lookup fails. [grounded: tree pkg/kubelet/cm/dra/manager.go] [consensus 3/3: valid=3]
raw comments (2)
pkg/kubelet/cm/dra/manager.go:235
[P1] Missing fallback to claim DriverName when resource handle has none (also 466-467) The old code used `Status.DriverName` (prepare) and `claimInfo.DriverName` (unprepare) whenever `resourceHandle.DriverName` was empty. The refactor now keys the batch by `resourceHandle.DriverName` alone. `newClaimInfoFromClaim` still creates a single empty `ResourceHandle` when `Allocation.ResourceHandles` is empty. That case is intentional and documented as "triggers processing by the plugin matching Status.DriverName". It now batches under `""`, so `dra.NewDRAPluginClient("")` fails with "failed to get DRA Plugin client for plugin name" and the claim can't be prepared or unprepared. The same applies to any handle with an empty DriverName. Affected claims are those without resource handles, or with handles that omit the driver name. The prepare path also stores CDI devices under the wrong plugin key. The reconcile loop will keep retrying unprepare for such claims without ever succeeding.
pkg/kubelet/cm/dra/manager.go:235
[P1] Driver-name fallback dropped when batching claims (same at 466-467 in unprepareResources) The old code used `Status.DriverName` (or `claimInfo.DriverName` on unprepare) whenever `resourceHandle.DriverName` was empty. The refactor now uses `resourceHandle.DriverName` directly as the batch key and drops that fallback. This breaks claims whose handles have no DriverName. That includes the placeholder handle `newClaimInfoFromClaim` creates when `Allocation.ResourceHandles` is empty, which is meant to be served by the plugin named in `Status.DriverName`. Those claims are now batched under the empty plugin name `""`. Plugin lookup for `""` fails in `NodePrepareResources` and `NodeUnprepareResources`, so pods using such claims cannot start or have their claims unprepared. Restoring the `if pluginName == "" { pluginName = ‹claim DriverName› }` fallback in both places fixes it.
qodo · cross-file engine perris 0.11.1+proven.tiered0.25.call.read.subclass.type
DefectSeverityFoundGrade
d1 high ✗ —
d2 medium ✗ —
d3 medium ✗ —
raw comments (2)
PR-level
<h3>Qodo is busy working</h3> Check back in a few minutes. Qodo's code review agents are on it. <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <img src="https://www.qodo.ai/wp-content/uploads/2026/01/anteater-looking-at-ants-01-transparent-bg-croped-ezgif.com-optimize-1.gif" width="30%">
PR-level
<h3>PR Summary by Qodo</h3> Reconcile DRA claim state and synchronize cache access <code>🐞 Bug fix</code> <code>✨ Enhancement</code> <code>🧪 Tests</code> <code>🕐 40+ Minutes</code> <img src="https://www.qodo.ai/wp-content/uploads/2025/11/light-grey-line.svg" height="10%" alt="Grey Divider"> <details> <summary>AI Description</summary> <dl> <dd> <br/> ><pre> >• Periodically reconciles stale DRA claims after pods disappear unexpectedly. >• Serializes claim cache mutations and checkpoints to eliminate concurrent state races. >• Adds deep-copy isolation and broad cache, lifecycle, and concurrency tests. ></pre> </dd> </dl> </details> <details> <summary>Diagram</summary> <dl> <dd> <br/> ```mermaid graph TD K["Kubelet"] --> M["DRA Manager"] --> R["Reconcile Loop"] --> A["Active Pods"] SR["Sources Ready"] --> R R --> C["Claim Cache"] --> S[("Checkpoint")] M --> C M --> P["DRA Plugins"] R --> P ``` </dd> </dl> </details> <details> <summary>High-Level Assessment</summary> <dl> <dd> <br/> >The following are alternative approaches to this PR: <details> <summary><b>1. Event-driven pod cleanup</b></summary> <dl> <dd> - ➕ Can clean stale claims immediately after pod deletion events. - ➕ Avoids periodic scans during normal operation. - ➖ Deletion events may be missed during restarts or source disruption. - ➖ Still requires reconciliation for crash recovery and checkpoint inconsistencies. </dd> </dl> </details> <details> <summary><b>2. Per-claim locking</b></summary> <dl> <dd> - ➕ Allows unrelated claims to be prepared and unprepared concurrently. - ➕ Reduces contention as DRA claim volume grows. - ➖ Complicates atomic full-cache checkpointing and lock ordering. - ➖ Increases deadlock and partial-state risks across multi-claim pod operations. </dd> </dl> </details> >**Recommendation:** Keep the PR&#x27;s cache-level locking, deep-copy snapshots, and periodic reconciliation. This approach prioritizes checkpoint consistency and recovery from missed pod lifecycle events; event-driven cleanup could supplement it later, while per-claim locking is not justified without evidence that cache contention is significant. </dd> </dl> </details> <details> <summary> Files changed (9) <code> +1570 / -258 </code> </summary> <dl> <dd> <br/> <details> <summary>Enhancement (1) <code> +5 / -0 </code></summary> <dl> <dd> <details> <summary>types.go<code>Expose DRA manager startup contract</code> <code>+5/-0</code></summary> <br/> >Expose DRA manager startup contract > ><pre> >• Extends the Manager interface with Start, accepting active-pod discovery and kubelet source-readiness dependencies for reconciliation. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-8df1ea72cd9cedaa53b9f4bca594f106ef7ec7cc9e9307e3d81dc8bf3fef83c3'>pkg/kubelet/cm/dra/types.go</a> </details> </dd> </dl> </details> <details> <summary>Bug fix (2) <code> +270 / -142 </code></summary> <dl> <dd> <details> <summary>container_manager_linux.go<code>Start DRA reconciliation with kubelet lifecycle inputs</code> <code>+9/-3</code></summary> <br/> >Start DRA reconciliation with kubelet lifecycle inputs > ><pre> >• Starts the DRA manager with active-pod and source-readiness providers when the feature is enabled. Removes direct ClaimInfo locking because returned claim data is now isolated through cache synchronization and deep copies. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-c07d343a8d459721656cf7ddacda71506bde01a5cac288d15a4aba6bfc9a1cae'>pkg/kubelet/cm/container_manager_linux.go</a> </details> <details> <summary>manager.go<code>Reconcile stale claims and atomically checkpoint DRA state</code> <code>+261/-139</code></summary> <br/> >Reconcile stale claims and atomically checkpoint DRA state > ><pre> >• Adds a readiness-gated periodic loop that unprepares claims belonging to inactive pods. Refactors prepare, read, and unprepare paths to synchronize cache transactions, checkpoint lifecycle transitions, and return deep-copied claim information. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-203d2de4519315883638490fcafedbe368e5d2dee0cdba88c91cef46614f80ac'>pkg/kubelet/cm/dra/manager.go</a> </details> </dd> </dl> </details> <details> <summary>Refactor (2) <code> +111 / -91 </code></summary> <dl> <dd> <details> <summary>claiminfo.go<code>Centralize synchronization and claim cache operations</code> <code>+110/-91</code></summary> <br/> >Centralize synchronization and claim cache operations > ><pre> >• Moves concurrency control from individual claims to the claim cache, standardizes namespace/claim cache keys, and adds explicit lookup and mutation helpers. Adds constructors for API and checkpoint state, CDI flattening, preparation state helpers, and checkpoint restoration through deep copies. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-fb23be99f2cb3e8a64ffa9fbc3cabe6315a3ed277fb32e8f7f8a2f3d938d8f57'>pkg/kubelet/cm/dra/claiminfo.go</a> </details> <details> <summary>state_checkpoint.go<code>Enable deep-copy generation for checkpointed claims</code> <code>+1/-0</code></summary> <br/> >Enable deep-copy generation for checkpointed claims > ><pre> >• Marks ClaimInfoState for Kubernetes deep-copy generation so cache snapshots do not share mutable maps, sets, or slices. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-02a867e6f262f712c1a4ff3a4407160ede32c85ad9d36be6a044e9f424e547c5'>pkg/kubelet/cm/dra/state/state_checkpoint.go</a> </details> </dd> </dl> </details> <details> <summary>Tests (2) <code> +1054 / -25 </code></summary> <dl> <dd> <details> <summary>claiminfo_test.go<code>Add comprehensive ClaimInfo and cache unit tests</code> <code>+894/-0</code></summary> <br/> >Add comprehensive ClaimInfo and cache unit tests > ><pre> >• Adds tests for claim construction, CDI annotations and devices, pod references, preparation state, cache locking, lookup operations, deletion, and checkpoint synchronization. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-09590b07136d966e0c0e99bf17af6b957b7c9ec74892ab7e577422216b237a93'>pkg/kubelet/cm/dra/claiminfo_test.go</a> </details> <details> <summary>manager_test.go<code>Exercise synchronized DRA lifecycle operations</code> <code>+160/-25</code></summary> <br/> >Exercise synchronized DRA lifecycle operations > ><pre> >• Updates manager fixtures and assertions for the new cache API and resource-handle routing. Adds concurrent prepare/unprepare coverage using multiple goroutines and improves fake plugin default responses. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-e0fdd924b2f3d663debcdd33ec80e817cc945c935479ef3304b707069bf4012d'>pkg/kubelet/cm/dra/manager_test.go</a> </details> </dd> </dl> </details> <details> <summary>Other (2) <code> +130 / -0 </code></summary> <dl> <dd> <details> <summary>zz_generated.deepcopy.go<code>Generate deep-copy support for checkpoint state</code> <code>+72/-0</code></summary> <br/> >Generate deep-copy support for checkpoint state > ><pre> >• Adds generated deep-copy methods for ClaimInfoState, including independent copies of pod references, resource handles, and CDI device mappings. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-98c70a3f42c3f30ed8d5e93dd0354af276a500a5c1d27523007c419bf8bde8bd'>pkg/kubelet/cm/dra/state/zz_generated.deepcopy.go</a> </details> <details> <summary>zz_generated.deepcopy.go<code>Generate deep-copy support for ClaimInfo</code> <code>+58/-0</code></summary> <br/> >Generate deep-copy support for ClaimInfo > ><pre> >• Adds generated deep-copy methods for ClaimInfo and its annotation map, enabling callers to consume claim snapshots without accessing mutable cache entries. ></pre> > ><a href='https://github.com/drape-io/crbench-qodo-2026-09/pull/47/files#diff-cf929fc6168bd85e24f53bb6440e014de373a4e1bb5ec96b59f113629b4730ec'>pkg/kubelet/cm/dra/zz_generated.deepcopy.go</a> </details> </dd> </dl> </details> </dd> </dl> </details>