@@ -68,7 +68,7 @@ func NewAllocator(ctx context.Context,
68
68
}, nil
69
69
}
70
70
71
- // ClaimsToAllocate returns the claims that the allocated was created for.
71
+ // ClaimsToAllocate returns the claims that the allocator was created for.
72
72
func (a * Allocator ) ClaimsToAllocate () []* resourceapi.ResourceClaim {
73
73
return a .claimsToAllocate
74
74
}
@@ -169,9 +169,13 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node) (finalResult []
169
169
return nil , fmt .Errorf ("claim %s, request %s: could not retrieve device class %s: %w" , klog .KObj (claim ), request .Name , request .DeviceClassName , err )
170
170
}
171
171
172
+ // Start collecting information about the request.
173
+ // The class must be set and stored before calling isSelectable.
172
174
requestData := requestData {
173
175
class : class ,
174
176
}
177
+ requestKey := requestIndices {claimIndex : claimIndex , requestIndex : requestIndex }
178
+ alloc .requestData [requestKey ] = requestData
175
179
176
180
switch request .AllocationMode {
177
181
case resourceapi .DeviceAllocationModeExactCount :
@@ -190,7 +194,7 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node) (finalResult []
190
194
191
195
for _ , slice := range pool .Slices {
192
196
for deviceIndex := range slice .Spec .Devices {
193
- selectable , err := alloc .isSelectable (requestIndices { claimIndex : claimIndex , requestIndex : requestIndex } , slice , deviceIndex )
197
+ selectable , err := alloc .isSelectable (requestKey , slice , deviceIndex )
194
198
if err != nil {
195
199
return nil , err
196
200
}
@@ -205,7 +209,7 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node) (finalResult []
205
209
default :
206
210
return nil , fmt .Errorf ("claim %s, request %s: unsupported count mode %s" , klog .KObj (claim ), request .Name , request .AllocationMode )
207
211
}
208
- alloc .requestData [requestIndices { claimIndex : claimIndex , requestIndex : requestIndex } ] = requestData
212
+ alloc .requestData [requestKey ] = requestData
209
213
numDevices += requestData .numDevices
210
214
}
211
215
alloc .logger .V (6 ).Info ("Checked claim" , "claim" , klog .KObj (claim ), "numDevices" , numDevices )
@@ -290,10 +294,13 @@ func (a *Allocator) Allocate(ctx context.Context, node *v1.Node) (finalResult []
290
294
// All errors get created such that they can be returned by Allocate
291
295
// without further wrapping.
292
296
done , err := alloc .allocateOne (deviceIndices {})
297
+ if errors .Is (err , errStop ) {
298
+ return nil , nil
299
+ }
293
300
if err != nil {
294
301
return nil , err
295
302
}
296
- if errors . Is ( err , errStop ) || ! done {
303
+ if ! done {
297
304
return nil , nil
298
305
}
299
306
@@ -347,7 +354,6 @@ type allocator struct {
347
354
constraints [][]constraint // one list of constraints per claim
348
355
requestData map [requestIndices ]requestData // one entry per request
349
356
allocated map [DeviceID ]bool
350
- skippedUnknownDevice bool
351
357
result []* resourceapi.AllocationResult
352
358
}
353
359
@@ -534,20 +540,23 @@ func (alloc *allocator) allocateOne(r deviceIndices) (bool, error) {
534
540
// For "all" devices we already know which ones we need. We
535
541
// just need to check whether we can use them.
536
542
deviceWithID := requestData .allDevices [r .deviceIndex ]
537
- _ , _ , err := alloc .allocateDevice (r , deviceWithID .device , deviceWithID .DeviceID , true )
543
+ success , _ , err := alloc .allocateDevice (r , deviceWithID .device , deviceWithID .DeviceID , true )
538
544
if err != nil {
539
545
return false , err
540
546
}
547
+ if ! success {
548
+ // The order in which we allocate "all" devices doesn't matter,
549
+ // so we only try with the one which was up next. If we couldn't
550
+ // get all of them, then there is no solution and we have to stop.
551
+ return false , errStop
552
+ }
541
553
done , err := alloc .allocateOne (deviceIndices {claimIndex : r .claimIndex , requestIndex : r .requestIndex , deviceIndex : r .deviceIndex + 1 })
542
554
if err != nil {
543
555
return false , err
544
556
}
545
-
546
- // The order in which we allocate "all" devices doesn't matter,
547
- // so we only try with the one which was up next. If we couldn't
548
- // get all of them, then there is no solution and we have to stop.
549
557
if ! done {
550
- return false , errStop
558
+ // Backtrack.
559
+ return false , nil
551
560
}
552
561
return done , nil
553
562
}
@@ -610,9 +619,6 @@ func (alloc *allocator) isSelectable(r requestIndices, slice *resourceapi.Resour
610
619
device := slice .Spec .Devices [deviceIndex ].Basic
611
620
if device == nil {
612
621
// Must be some future, unknown device type. We cannot select it.
613
- // If we don't find anything else, then this will get reported
614
- // in the final result, so remember that we skipped some device.
615
- alloc .skippedUnknownDevice = true
616
622
return false , nil
617
623
}
618
624
0 commit comments