Merge pull request #139362 from nojnhuh/automated-cherry-pick-of-#139017-upstream-release-1.35

Automated cherry pick of #139017: Fix dra scoring bug with mixed allocated and unallocated claims
This commit is contained in:
Kubernetes Prow Robot
2026-06-08 16:55:59 +05:30
committed by GitHub
2 changed files with 34 additions and 5 deletions

View File

@@ -830,7 +830,7 @@ func (pl *DynamicResources) PostFilter(ctx context.Context, cs fwk.CycleState, p
}
func (pl *DynamicResources) Score(ctx context.Context, cs fwk.CycleState, pod *v1.Pod, nodeInfo fwk.NodeInfo) (int64, *fwk.Status) {
if !pl.enabled {
if !pl.enabled || !pl.fts.EnableDRAPrioritizedList {
return 0, nil
}
logger := klog.FromContext(ctx)
@@ -859,13 +859,29 @@ func (pl *DynamicResources) Score(ctx context.Context, cs fwk.CycleState, pod *v
func computeScore(iterator iter.Seq2[int, *resourceapi.ResourceClaim], allocations nodeAllocation) (int64, error) {
var score int64
for i, claim := range iterator {
unallocatedIndex := 0
for _, claim := range iterator {
// Collect the names for all allocated subrequests.
allocatedSubRequests := sets.New[string]()
if i >= len(allocations.allocationResults) {
return 0, fmt.Errorf("number of allocations %d is smaller than number of claims", len(allocations.allocationResults))
var allocation *resourceapi.AllocationResult
// The allocation for a claim can be in two places:
// 1. For claims allocated in a previous cycle (e.g. PodGroup claims), the allocation
// is already in claim.Status.Allocation.
// 2. For claims allocated in this cycle (in Filter), the allocation is in
// allocations.allocationResults.
// Since we iterate over all claims, we must check both and maintain a separate index
// for claims that needed allocation in this cycle.
if claim.Status.Allocation != nil {
allocation = claim.Status.Allocation
} else {
if unallocatedIndex >= len(allocations.allocationResults) {
return 0, fmt.Errorf("number of allocations %d is smaller than number of claims needing allocation", len(allocations.allocationResults))
}
allocation = &allocations.allocationResults[unallocatedIndex]
unallocatedIndex++
}
allocation := allocations.allocationResults[i]
for _, res := range allocation.Devices.Results {
request := res.Request
if resourceclaim.IsSubRequestRef(request) {

View File

@@ -3310,6 +3310,19 @@ func Test_computesScore(t *testing.T) {
allocations: nodeAllocation{},
expectErr: true,
},
"mix-of-allocated-and-unallocated-claims": {
claims: []*resourceapi.ResourceClaim{
allocatedClaim,
pendingClaim2,
},
allocations: nodeAllocation{
allocationResults: []resourceapi.AllocationResult{
*allocationResult2,
},
},
expectedScore: 0,
expectErr: false,
},
"single-request-only-subrequest-allocated": {
claims: []*resourceapi.ResourceClaim{
st.MakeResourceClaim().