fix nil panic in hasBindingConditions, it cannot assume claim has allocations

This commit is contained in:
yliao
2025-07-30 00:10:56 +00:00
committed by Sunyanan Choochotkaew
parent 7f052afaef
commit 0a12f00e9d
2 changed files with 14 additions and 1 deletions

View File

@@ -1657,6 +1657,9 @@ func (pl *DynamicResources) isPodReadyForBinding(state *stateData) (bool, error)
// It returns false if no claim has binding conditions.
func hasBindingConditions(state *stateData) bool {
for _, claim := range state.claims.all() {
if claim.Status.Allocation == nil {
continue
}
for _, device := range claim.Status.Allocation.Devices.Results {
if len(device.BindingConditions) > 0 {
return true

View File

@@ -136,7 +136,8 @@ var (
workerNode3 = &st.MakeNode().Name(node3Name).Label("kubernetes.io/hostname", node3Name).Node
workerNode3Slice = st.MakeResourceSlice(node3Name, driver).Device("instance-1", map[resourceapi.QualifiedName]resourceapi.DeviceAttribute{attrName: {BoolValue: ptr.To(true)}}).Obj()
brokenSelector = resourceapi.DeviceSelector{
workerNodeWithExtendedResource = &st.MakeNode().Name(nodeName).Label("kubernetes.io/hostname", nodeName).Capacity(map[v1.ResourceName]string{v1.ResourceName(extendedResourceName): "1"}).Node
brokenSelector = resourceapi.DeviceSelector{
CEL: &resourceapi.CELDeviceSelector{
// Not set for workerNode.
Expression: fmt.Sprintf(`device.attributes["%s"].%s`, driver, attrName),
@@ -1260,6 +1261,15 @@ func TestPlugin(t *testing.T) {
},
},
},
"extended-resource-name-wth-node-resource": {
enableDRAExtendedResource: true,
enableDRADeviceBindingConditions: true,
enableDRAResourceClaimDeviceStatus: true,
nodes: []*v1.Node{workerNodeWithExtendedResource},
pod: podWithExtendedResourceName,
classes: []*resourceapi.DeviceClass{deviceClassWithExtendResourceName},
want: want{},
},
"extended-resource-name-no-resource": {
enableDRAExtendedResource: true,
pod: podWithExtendedResourceName,