From 0a12f00e9d30bce9a0579a72da725ecdcdb88696 Mon Sep 17 00:00:00 2001 From: yliao Date: Wed, 30 Jul 2025 00:10:56 +0000 Subject: [PATCH] fix nil panic in hasBindingConditions, it cannot assume claim has allocations --- .../plugins/dynamicresources/dynamicresources.go | 3 +++ .../dynamicresources/dynamicresources_test.go | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go index c17a2fda4eb..3cd457a9ea9 100644 --- a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go +++ b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources.go @@ -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 diff --git a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go index 0f7170d29ba..a86bbcdcef6 100644 --- a/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go +++ b/pkg/scheduler/framework/plugins/dynamicresources/dynamicresources_test.go @@ -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,