From b30944b07153279af0abca2f5238dabca78de6f9 Mon Sep 17 00:00:00 2001 From: googs1025 Date: Mon, 10 Feb 2025 14:04:50 +0800 Subject: [PATCH] chore(dra): move pool validity check to the beginning of pool processing --- .../structured/allocator.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go b/staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go index 74b82c6f1a7..6e05234074a 100644 --- a/staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go +++ b/staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go @@ -595,6 +595,12 @@ func (alloc *allocator) allocateOne(r deviceIndices) (bool, error) { // We need to find suitable devices. for _, pool := range alloc.pools { + // If the pool is not valid, then fail now. It's okay when pools of one driver + // are invalid if we allocate from some other pool, but it's not safe to + // allocated from an invalid pool. + if pool.IsInvalid { + return false, fmt.Errorf("pool %s is invalid: %s", pool.Pool, pool.InvalidReason) + } for _, slice := range pool.Slices { for deviceIndex := range slice.Spec.Devices { deviceID := DeviceID{Driver: pool.Driver, Pool: pool.Pool, Device: slice.Spec.Devices[deviceIndex].Name} @@ -615,13 +621,6 @@ func (alloc *allocator) allocateOne(r deviceIndices) (bool, error) { continue } - // If the pool is not valid, then fail now. It's okay when pools of one driver - // are invalid if we allocate from some other pool, but it's not safe to - // allocated from an invalid pool. - if pool.IsInvalid { - return false, fmt.Errorf("pool %s is invalid: %s", pool.Pool, pool.InvalidReason) - } - // Finally treat as allocated and move on to the next device. device := deviceWithID{ id: deviceID,