Skip to content

Commit d360839

Browse files
committed
DRA: add more allocator test cases
1 parent 87f1fde commit d360839

File tree

2 files changed

+617
-21
lines changed

2 files changed

+617
-21
lines changed

staging/src/k8s.io/dynamic-resource-allocation/structured/allocator.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,14 @@ func (a *Allocator) ClaimsToAllocate() []*resourceapi.ResourceClaim {
9898
// progress reports, and V(6) for detailed debug output.
9999
func (sharedAllocator *Allocator) Allocate(ctx context.Context, node *v1.Node) ([]*resourceapi.AllocationResult, error) {
100100
alloc := &allocator{
101-
Allocator: sharedAllocator,
102-
ctx: ctx, // all methods share the same a and thus ctx
103-
logger: klog.FromContext(ctx),
104-
constraints: make([][]constraint, 0, len(sharedAllocator.claimsToAllocate)),
105-
requestData: make(map[requestIndices]requestData),
106-
allocated: make(map[DeviceID]bool),
107-
result: make([]*resourceapi.AllocationResult, len(sharedAllocator.claimsToAllocate)),
101+
Allocator: sharedAllocator,
102+
ctx: ctx, // all methods share the same a and thus ctx
103+
logger: klog.FromContext(ctx),
104+
deviceMatchesRequest: make(map[matchKey]bool),
105+
constraints: make([][]constraint, 0, len(sharedAllocator.claimsToAllocate)),
106+
requestData: make(map[requestIndices]requestData),
107+
allocated: make(map[DeviceID]bool),
108+
result: make([]*resourceapi.AllocationResult, len(sharedAllocator.claimsToAllocate)),
108109
}
109110

110111
// First determine all eligible pools.
@@ -227,7 +228,7 @@ func (sharedAllocator *Allocator) Allocate(ctx context.Context, node *v1.Node) (
227228
// Constraints are assumed to be monotonic: once a constraint returns
228229
// false, adding more devices will not cause it to return true. This
229230
// allows the search to stop early once a constraint returns false.
230-
var constraints = make([]constraint, len(claim.Spec.Devices.Constraints))
231+
var constraints = make([]constraint, 0, len(claim.Spec.Devices.Constraints))
231232
for i, constraint := range claim.Spec.Devices.Constraints {
232233
switch {
233234
case constraint.MatchAttribute != nil:

0 commit comments

Comments
 (0)