Revert "DRA: Allow AllocationMode: All from multi-node resource pools"

This reverts commit 2e534d6da1.
It caused a performance regression, a different fix is needed.
This commit is contained in:
Patrick Ohly
2025-11-03 13:10:43 +01:00
parent afb2b97425
commit a0e500ace3
4 changed files with 6 additions and 163 deletions

View File

@@ -5240,40 +5240,6 @@ func TestAllocator(t *testing.T,
),
},
},
"allocation-mode-all-with-multi-host-resource-pool": {
claimsToAllocate: objects(claimWithRequests(claim0, nil, resourceapi.DeviceRequest{
Name: req0,
Exactly: &resourceapi.ExactDeviceRequest{
AllocationMode: resourceapi.DeviceAllocationModeAll,
DeviceClassName: classA,
},
})),
classes: objects(class(classA, driverA)),
slices: unwrap(
func() wrapResourceSlice {
s := slice(slice1, node1, pool1, driverA,
device(device1, nil, nil),
)
s.Spec.Pool.ResourceSliceCount = 2
return s
}(),
func() wrapResourceSlice {
s := slice(slice2, node2, pool1, driverA,
device(device2, nil, nil),
)
s.Spec.Pool.ResourceSliceCount = 2
return s
}(),
),
node: node(node1, region1),
expectResults: []any{
allocationResult(
localNodeSelector(node1),
deviceAllocationResult(req0, driverA, pool1, device1, false),
),
},
},
}
for name, tc := range testcases {

View File

@@ -45,10 +45,6 @@ func nodeMatches(node *v1.Node, nodeNameToMatch string, allNodesMatch bool, node
return false, nil
}
type poolIdentifier struct {
driver, pool string
}
// GatherPools collects information about all resource pools which provide
// devices that are accessible from the given node.
//
@@ -56,46 +52,9 @@ type poolIdentifier struct {
// required slices available) or invalid (for example, device names not unique).
// Both is recorded in the result.
func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node *v1.Node, features Features) ([]*Pool, error) {
slicesByPool := make(map[poolIdentifier][]*resourceapi.ResourceSlice)
for _, slice := range slices {
poolID := poolIdentifier{
driver: slice.Spec.Driver,
pool: slice.Spec.Pool.Name,
}
slicesByPool[poolID] = append(slicesByPool[poolID], slice)
}
// We need to check whether a pool is complete while we have all
// the slices. Once we discard slices that don't target the node, we
// no longer have the information needed to find out.
incompletePools := sets.New[poolIdentifier]()
for poolID, slices := range slicesByPool {
complete := true
sliceCount := len(slices)
generation := slices[0].Spec.Pool.Generation
for _, slice := range slices {
// If the number of slices in the pool specified in any of the slices
// doesn't match what we found, the pool is most likely being updated
// by the controller.
if slice.Spec.Pool.ResourceSliceCount != int64(sliceCount) {
complete = false
}
// If the generation of the pool isn't the same across all slices,
// the pool is most likely being updated by the controller. We can't
// allocate devices from it.
if slice.Spec.Pool.Generation != generation {
complete = false
}
}
// We still need to keep incomplete pools, since we need to make sure
// all devices available on a node is considered for allocationMode All.
if !complete {
incompletePools.Insert(poolID)
}
}
pools := make(map[PoolID]*Pool)
var slicesWithBindingConditions []*resourceapi.ResourceSlice
for _, slice := range slices {
if !features.PartitionableDevices && slice.Spec.PerDeviceNodeSelection != nil {
continue
@@ -162,7 +121,7 @@ func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node
result := make([]*Pool, 0, len(pools))
var resultWithBindingConditions []*Pool
for _, pool := range pools {
pool.IsIncomplete = incompletePools.Has(poolIdentifier{driver: pool.Driver.String(), pool: pool.Pool.String()})
pool.IsIncomplete = int64(len(pool.Slices)) != pool.Slices[0].Spec.Pool.ResourceSliceCount
pool.IsInvalid, pool.InvalidReason = poolIsInvalid(pool)
// if pool has binding conditions, add the pool to the end of the result
if poolHasBindingConditions(*pool) {

View File

@@ -45,10 +45,6 @@ func nodeMatches(node *v1.Node, nodeNameToMatch string, allNodesMatch bool, node
return false, nil
}
type poolIdentifier struct {
driver, pool string
}
// GatherPools collects information about all resource pools which provide
// devices that are accessible from the given node.
//
@@ -56,45 +52,8 @@ type poolIdentifier struct {
// required slices available) or invalid (for example, device names not unique).
// Both is recorded in the result.
func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node *v1.Node, features Features) ([]*Pool, error) {
slicesByPool := make(map[poolIdentifier][]*resourceapi.ResourceSlice)
for _, slice := range slices {
poolID := poolIdentifier{
driver: slice.Spec.Driver,
pool: slice.Spec.Pool.Name,
}
slicesByPool[poolID] = append(slicesByPool[poolID], slice)
}
// We need to check whether a pool is complete while we have all
// the slices. Once we discard slices that don't target the node, we
// no longer have the information needed to find out.
incompletePools := sets.New[poolIdentifier]()
for poolID, slices := range slicesByPool {
complete := true
sliceCount := len(slices)
generation := slices[0].Spec.Pool.Generation
for _, slice := range slices {
// If the number of slices in the pool specified in any of the slices
// doesn't match what we found, the pool is most likely being updated
// by the controller.
if slice.Spec.Pool.ResourceSliceCount != int64(sliceCount) {
complete = false
}
// If the generation of the pool isn't the same across all slices,
// the pool is most likely being updated by the controller. We can't
// allocate devices from it.
if slice.Spec.Pool.Generation != generation {
complete = false
}
}
// We still need to keep incomplete pools, since we need to make sure
// all devices available on a node is considered for allocationMode All.
if !complete {
incompletePools.Insert(poolID)
}
}
pools := make(map[PoolID]*Pool)
for _, slice := range slices {
if !features.PartitionableDevices && slice.Spec.PerDeviceNodeSelection != nil {
continue
@@ -140,7 +99,7 @@ func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node
// Find incomplete pools and flatten into a single slice.
result := make([]*Pool, 0, len(pools))
for _, pool := range pools {
pool.IsIncomplete = incompletePools.Has(poolIdentifier{driver: pool.Driver.String(), pool: pool.Pool.String()})
pool.IsIncomplete = int64(len(pool.Slices)) != pool.Slices[0].Spec.Pool.ResourceSliceCount
pool.IsInvalid, pool.InvalidReason = poolIsInvalid(pool)
result = append(result, pool)
}

View File

@@ -45,10 +45,6 @@ func nodeMatches(node *v1.Node, nodeNameToMatch string, allNodesMatch bool, node
return false, nil
}
type poolIdentifier struct {
driver, pool string
}
// GatherPools collects information about all resource pools which provide
// devices that are accessible from the given node.
//
@@ -56,45 +52,8 @@ type poolIdentifier struct {
// required slices available) or invalid (for example, device names not unique).
// Both is recorded in the result.
func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node *v1.Node, features Features) ([]*Pool, error) {
slicesByPool := make(map[poolIdentifier][]*resourceapi.ResourceSlice)
for _, slice := range slices {
poolID := poolIdentifier{
driver: slice.Spec.Driver,
pool: slice.Spec.Pool.Name,
}
slicesByPool[poolID] = append(slicesByPool[poolID], slice)
}
// We need to check whether a pool is complete while we have all
// the slices. Once we discard slices that don't target the node, we
// no longer have the information needed to find out.
incompletePools := sets.New[poolIdentifier]()
for poolID, slices := range slicesByPool {
complete := true
sliceCount := len(slices)
generation := slices[0].Spec.Pool.Generation
for _, slice := range slices {
// If the number of slices in the pool specified in any of the slices
// doesn't match what we found, the pool is most likely being updated
// by the controller.
if slice.Spec.Pool.ResourceSliceCount != int64(sliceCount) {
complete = false
}
// If the generation of the pool isn't the same across all slices,
// the pool is most likely being updated by the controller. We can't
// allocate devices from it.
if slice.Spec.Pool.Generation != generation {
complete = false
}
}
// We still need to keep incomplete pools, since we need to make sure
// all devices available on a node is considered for allocationMode All.
if !complete {
incompletePools.Insert(poolID)
}
}
pools := make(map[PoolID]*Pool)
for _, slice := range slices {
if !features.PartitionableDevices && slice.Spec.PerDeviceNodeSelection != nil {
continue
@@ -140,7 +99,7 @@ func GatherPools(ctx context.Context, slices []*resourceapi.ResourceSlice, node
// Find incomplete pools and flatten into a single slice.
result := make([]*Pool, 0, len(pools))
for _, pool := range pools {
pool.IsIncomplete = incompletePools.Has(poolIdentifier{driver: pool.Driver.String(), pool: pool.Pool.String()})
pool.IsIncomplete = int64(len(pool.Slices)) != pool.Slices[0].Spec.Pool.ResourceSliceCount
pool.IsInvalid, pool.InvalidReason = poolIsInvalid(pool)
result = append(result, pool)
}