Skip to content

Commit f0aba33

Browse files
pohlyk8s-publishing-bot
authored andcommitted
DRA: remove immediate allocation
As agreed in kubernetes/enhancements#4709, immediate allocation is one of those features which can be removed because it makes no sense for structured parameters and the justification for classic DRA is weak. Kubernetes-commit: de5742ae83c8d77268a7caf5f3b1f418c4a13a84
1 parent 4940ebf commit f0aba33

File tree

2 files changed

+48
-197
lines changed

2 files changed

+48
-197
lines changed

controller/controller.go

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -515,48 +515,7 @@ func (ctrl *controller) syncClaim(ctx context.Context, claim *resourceapi.Resour
515515
logger.V(5).Info("ResourceClaim is allocated")
516516
return nil
517517
}
518-
if claim.Spec.AllocationMode != resourceapi.AllocationModeImmediate {
519-
logger.V(5).Info("ResourceClaim waiting for first consumer")
520-
return nil
521-
}
522-
523-
// We need the ResourceClass to determine whether we should allocate it.
524-
class, err := ctrl.rcLister.Get(claim.Spec.ResourceClassName)
525-
if err != nil {
526-
return err
527-
}
528-
if class.DriverName != ctrl.name {
529-
// Not ours *at the moment*. This can change, so requeue and
530-
// check again. We could trigger a faster check when the
531-
// ResourceClass changes, but that shouldn't occur much in
532-
// practice and thus isn't worth the effort.
533-
//
534-
// We use exponential backoff because it is unlikely that
535-
// the ResourceClass changes much.
536-
logger.V(5).Info("ResourceClaim is handled by other driver", "driver", class.DriverName)
537-
return errRequeue
538-
}
539-
540-
// Check parameters. Do not record event to Claim if its parameters are invalid,
541-
// syncKey will record the error.
542-
claimParameters, classParameters, err := ctrl.getParameters(ctx, claim, class, false)
543-
if err != nil {
544-
return err
545-
}
546-
547-
claimAllocations := claimAllocations{&ClaimAllocation{
548-
Claim: claim,
549-
ClaimParameters: claimParameters,
550-
Class: class,
551-
ClassParameters: classParameters,
552-
}}
553-
554-
ctrl.allocateClaims(ctx, claimAllocations, "", nil)
555-
556-
if claimAllocations[0].Error != nil {
557-
return fmt.Errorf("allocate: %v", claimAllocations[0].Error)
558-
}
559-
518+
logger.V(5).Info("ResourceClaim waiting for first consumer")
560519
return nil
561520
}
562521

@@ -678,10 +637,6 @@ func (ctrl *controller) checkPodClaim(ctx context.Context, pod *v1.Pod, podClaim
678637
return nil, err
679638
}
680639
}
681-
if claim.Spec.AllocationMode != resourceapi.AllocationModeWaitForFirstConsumer {
682-
// Nothing to do for it as part of pod scheduling.
683-
return nil, nil
684-
}
685640
if claim.Status.Allocation != nil {
686641
// Already allocated, class and parameter are not needed and nothing
687642
// need to be done for the claim either.

controller/controller_test.go

Lines changed: 47 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ func TestController(t *testing.T) {
5353
}
5454
claim := createClaim(claimName, claimNamespace, className)
5555
otherClaim := createClaim(claimName, claimNamespace, otherClassName)
56-
delayedClaim := claim.DeepCopy()
57-
delayedClaim.Spec.AllocationMode = resourceapi.AllocationModeWaitForFirstConsumer
5856
podName := "pod"
5957
podKey := "schedulingCtx:default/pod"
6058
pod := createPod(podName, claimNamespace, nil)
@@ -148,94 +146,6 @@ func TestController(t *testing.T) {
148146
classes: classes,
149147
claim: otherClaim,
150148
expectedClaim: otherClaim,
151-
expectedError: errRequeue.Error(), // class might change
152-
},
153-
// Immediate allocation:
154-
// deletion time stamp set, our finalizer set, not allocated -> remove finalizer
155-
"immediate-deleted-finalizer-removal": {
156-
key: claimKey,
157-
classes: classes,
158-
claim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
159-
driver: m.expectDeallocate(map[string]error{claimName: nil}),
160-
expectedClaim: withDeletionTimestamp(claim),
161-
},
162-
// deletion time stamp set, our finalizer set, not allocated, stopping fails -> requeue
163-
"immediate-deleted-finalizer-stop-failure": {
164-
key: claimKey,
165-
classes: classes,
166-
claim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
167-
driver: m.expectDeallocate(map[string]error{claimName: errors.New("fake error")}),
168-
expectedClaim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
169-
expectedError: "stop allocation: fake error",
170-
},
171-
// deletion time stamp set, other finalizer set, not allocated -> do nothing
172-
"immediate-deleted-finalizer-no-removal": {
173-
key: claimKey,
174-
classes: classes,
175-
claim: withFinalizer(withDeletionTimestamp(claim), otherFinalizer),
176-
expectedClaim: withFinalizer(withDeletionTimestamp(claim), otherFinalizer),
177-
},
178-
// deletion time stamp set, finalizer set, allocated -> deallocate
179-
"immediate-deleted-allocated": {
180-
key: claimKey,
181-
classes: classes,
182-
claim: withAllocate(withDeletionTimestamp(claim)),
183-
driver: m.expectDeallocate(map[string]error{claimName: nil}),
184-
expectedClaim: withDeletionTimestamp(claim),
185-
},
186-
// deletion time stamp set, finalizer set, allocated, deallocation fails -> requeue
187-
"immediate-deleted-deallocate-failure": {
188-
key: claimKey,
189-
classes: classes,
190-
claim: withAllocate(withDeletionTimestamp(claim)),
191-
driver: m.expectDeallocate(map[string]error{claimName: errors.New("fake error")}),
192-
expectedClaim: withAllocate(withDeletionTimestamp(claim)),
193-
expectedError: "deallocate: fake error",
194-
},
195-
// deletion time stamp set, finalizer not set -> do nothing
196-
"immediate-deleted-no-finalizer": {
197-
key: claimKey,
198-
classes: classes,
199-
claim: withDeletionTimestamp(claim),
200-
expectedClaim: withDeletionTimestamp(claim),
201-
},
202-
// not deleted, not allocated, no finalizer -> add finalizer, allocate
203-
"immediate-do-allocation": {
204-
key: claimKey,
205-
classes: classes,
206-
claim: claim,
207-
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
208-
expectClaimParameters(map[string]interface{}{claimName: 2}).
209-
expectAllocate(map[string]allocate{claimName: {allocResult: &allocation, allocErr: nil}}),
210-
expectedClaim: withAllocate(claim),
211-
},
212-
// not deleted, not allocated, finalizer -> allocate
213-
"immediate-continue-allocation": {
214-
key: claimKey,
215-
classes: classes,
216-
claim: withFinalizer(claim, ourFinalizer),
217-
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
218-
expectClaimParameters(map[string]interface{}{claimName: 2}).
219-
expectAllocate(map[string]allocate{claimName: {allocResult: &allocation, allocErr: nil}}),
220-
expectedClaim: withAllocate(claim),
221-
},
222-
// not deleted, not allocated, finalizer, fail allocation -> requeue
223-
"immediate-fail-allocation": {
224-
key: claimKey,
225-
classes: classes,
226-
claim: withFinalizer(claim, ourFinalizer),
227-
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
228-
expectClaimParameters(map[string]interface{}{claimName: 2}).
229-
expectAllocate(map[string]allocate{claimName: {allocErr: errors.New("fake error")}}),
230-
expectedClaim: withFinalizer(claim, ourFinalizer),
231-
expectedError: "allocate: fake error",
232-
},
233-
// not deleted, allocated -> do nothing
234-
"immediate-allocated-nop": {
235-
key: claimKey,
236-
classes: classes,
237-
claim: withAllocate(claim),
238-
expectedClaim: withAllocate(claim),
239149
},
240150

241151
// not deleted, reallocate -> deallocate
@@ -257,62 +167,60 @@ func TestController(t *testing.T) {
257167
expectedError: "deallocate: fake error",
258168
},
259169

260-
// Delayed allocation is similar in some cases, but not quite
261-
// the same.
262170
// deletion time stamp set, our finalizer set, not allocated -> remove finalizer
263-
"delayed-deleted-finalizer-removal": {
171+
"deleted-finalizer-removal": {
264172
key: claimKey,
265173
classes: classes,
266-
claim: withFinalizer(withDeletionTimestamp(delayedClaim), ourFinalizer),
174+
claim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
267175
driver: m.expectDeallocate(map[string]error{claimName: nil}),
268-
expectedClaim: withDeletionTimestamp(delayedClaim),
176+
expectedClaim: withDeletionTimestamp(claim),
269177
},
270178
// deletion time stamp set, our finalizer set, not allocated, stopping fails -> requeue
271-
"delayed-deleted-finalizer-stop-failure": {
179+
"deleted-finalizer-stop-failure": {
272180
key: claimKey,
273181
classes: classes,
274-
claim: withFinalizer(withDeletionTimestamp(delayedClaim), ourFinalizer),
182+
claim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
275183
driver: m.expectDeallocate(map[string]error{claimName: errors.New("fake error")}),
276-
expectedClaim: withFinalizer(withDeletionTimestamp(delayedClaim), ourFinalizer),
184+
expectedClaim: withFinalizer(withDeletionTimestamp(claim), ourFinalizer),
277185
expectedError: "stop allocation: fake error",
278186
},
279187
// deletion time stamp set, other finalizer set, not allocated -> do nothing
280-
"delayed-deleted-finalizer-no-removal": {
188+
"deleted-finalizer-no-removal": {
281189
key: claimKey,
282190
classes: classes,
283-
claim: withFinalizer(withDeletionTimestamp(delayedClaim), otherFinalizer),
284-
expectedClaim: withFinalizer(withDeletionTimestamp(delayedClaim), otherFinalizer),
191+
claim: withFinalizer(withDeletionTimestamp(claim), otherFinalizer),
192+
expectedClaim: withFinalizer(withDeletionTimestamp(claim), otherFinalizer),
285193
},
286194
// deletion time stamp set, finalizer set, allocated -> deallocate
287-
"delayed-deleted-allocated": {
195+
"deleted-allocated": {
288196
key: claimKey,
289197
classes: classes,
290-
claim: withAllocate(withDeletionTimestamp(delayedClaim)),
198+
claim: withAllocate(withDeletionTimestamp(claim)),
291199
driver: m.expectDeallocate(map[string]error{claimName: nil}),
292-
expectedClaim: withDeletionTimestamp(delayedClaim),
200+
expectedClaim: withDeletionTimestamp(claim),
293201
},
294202
// deletion time stamp set, finalizer set, allocated, deallocation fails -> requeue
295-
"delayed-deleted-deallocate-failure": {
203+
"deleted-deallocate-failure": {
296204
key: claimKey,
297205
classes: classes,
298-
claim: withAllocate(withDeletionTimestamp(delayedClaim)),
206+
claim: withAllocate(withDeletionTimestamp(claim)),
299207
driver: m.expectDeallocate(map[string]error{claimName: errors.New("fake error")}),
300-
expectedClaim: withAllocate(withDeletionTimestamp(delayedClaim)),
208+
expectedClaim: withAllocate(withDeletionTimestamp(claim)),
301209
expectedError: "deallocate: fake error",
302210
},
303211
// deletion time stamp set, finalizer not set -> do nothing
304-
"delayed-deleted-no-finalizer": {
212+
"deleted-no-finalizer": {
305213
key: claimKey,
306214
classes: classes,
307-
claim: withDeletionTimestamp(delayedClaim),
308-
expectedClaim: withDeletionTimestamp(delayedClaim),
215+
claim: withDeletionTimestamp(claim),
216+
expectedClaim: withDeletionTimestamp(claim),
309217
},
310218
// waiting for first consumer -> do nothing
311-
"delayed-pending": {
219+
"pending": {
312220
key: claimKey,
313221
classes: classes,
314-
claim: delayedClaim,
315-
expectedClaim: delayedClaim,
222+
claim: claim,
223+
expectedClaim: claim,
316224
},
317225

318226
// pod with no claims -> shouldn't occur, check again anyway
@@ -324,34 +232,23 @@ func TestController(t *testing.T) {
324232
expectedError: errPeriodic.Error(),
325233
},
326234

327-
// pod with immediate allocation and selected node -> shouldn't occur, check again in case that claim changes
328-
"pod-immediate": {
235+
// no potential nodes -> shouldn't occur
236+
"no-nodes": {
329237
key: podKey,
238+
classes: classes,
330239
claim: claim,
331240
expectedClaim: claim,
332241
pod: podWithClaim,
333-
schedulingCtx: withSelectedNode(podSchedulingCtx),
334-
expectedSchedulingCtx: withSelectedNode(podSchedulingCtx),
335-
expectedError: errPeriodic.Error(),
336-
},
337-
338-
// pod with delayed allocation, no potential nodes -> shouldn't occur
339-
"pod-delayed-no-nodes": {
340-
key: podKey,
341-
classes: classes,
342-
claim: delayedClaim,
343-
expectedClaim: delayedClaim,
344-
pod: podWithClaim,
345242
schedulingCtx: podSchedulingCtx,
346243
expectedSchedulingCtx: podSchedulingCtx,
347244
},
348245

349-
// pod with delayed allocation, potential nodes -> provide unsuitable nodes
350-
"pod-delayed-info": {
246+
// potential nodes -> provide unsuitable nodes
247+
"info": {
351248
key: podKey,
352249
classes: classes,
353-
claim: delayedClaim,
354-
expectedClaim: delayedClaim,
250+
claim: claim,
251+
expectedClaim: claim,
355252
pod: podWithClaim,
356253
schedulingCtx: withPotentialNodes(podSchedulingCtx),
357254
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
@@ -361,23 +258,23 @@ func TestController(t *testing.T) {
361258
expectedError: errPeriodic.Error(),
362259
},
363260

364-
// pod with delayed allocation, potential nodes, selected node, missing class -> failure
365-
"pod-delayed-missing-class": {
261+
// potential nodes, selected node, missing class -> failure
262+
"missing-class": {
366263
key: podKey,
367-
claim: delayedClaim,
368-
expectedClaim: delayedClaim,
264+
claim: claim,
265+
expectedClaim: claim,
369266
pod: podWithClaim,
370267
schedulingCtx: withSelectedNode(withPotentialNodes(podSchedulingCtx)),
371268
expectedSchedulingCtx: withSelectedNode(withPotentialNodes(podSchedulingCtx)),
372269
expectedError: `pod claim my-pod-claim: resourceclass.resource.k8s.io "mock-class" not found`,
373270
},
374271

375-
// pod with delayed allocation, potential nodes, selected node -> allocate
376-
"pod-delayed-allocate": {
272+
// potential nodes, selected node -> allocate
273+
"allocate": {
377274
key: podKey,
378275
classes: classes,
379-
claim: delayedClaim,
380-
expectedClaim: withReservedFor(withAllocate(delayedClaim), pod),
276+
claim: claim,
277+
expectedClaim: withReservedFor(withAllocate(claim), pod),
381278
pod: podWithClaim,
382279
schedulingCtx: withSelectedNode(withPotentialNodes(podSchedulingCtx)),
383280
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
@@ -387,12 +284,12 @@ func TestController(t *testing.T) {
387284
expectedSchedulingCtx: withUnsuitableNodes(withSelectedNode(withPotentialNodes(podSchedulingCtx))),
388285
expectedError: errPeriodic.Error(),
389286
},
390-
// pod with delayed allocation, potential nodes, selected node, all unsuitable -> update unsuitable nodes
391-
"pod-selected-is-potential-node": {
287+
// potential nodes, selected node, all unsuitable -> update unsuitable nodes
288+
"is-potential-node": {
392289
key: podKey,
393290
classes: classes,
394-
claim: delayedClaim,
395-
expectedClaim: delayedClaim,
291+
claim: claim,
292+
expectedClaim: claim,
396293
pod: podWithClaim,
397294
schedulingCtx: withPotentialNodes(withSelectedNode(withPotentialNodes(podSchedulingCtx))),
398295
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
@@ -401,12 +298,12 @@ func TestController(t *testing.T) {
401298
expectedSchedulingCtx: withSpecificUnsuitableNodes(withSelectedNode(withPotentialNodes(podSchedulingCtx)), potentialNodes),
402299
expectedError: errPeriodic.Error(),
403300
},
404-
// pod with delayed allocation, max potential nodes, other selected node, all unsuitable -> update unsuitable nodes with truncation at start
405-
"pod-selected-is-potential-node-truncate-first": {
301+
// max potential nodes, other selected node, all unsuitable -> update unsuitable nodes with truncation at start
302+
"is-potential-node-truncate-first": {
406303
key: podKey,
407304
classes: classes,
408-
claim: delayedClaim,
409-
expectedClaim: delayedClaim,
305+
claim: claim,
306+
expectedClaim: claim,
410307
pod: podWithClaim,
411308
schedulingCtx: withSpecificPotentialNodes(withSelectedNode(withSpecificPotentialNodes(podSchedulingCtx, maxNodes)), maxNodes),
412309
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
@@ -415,12 +312,12 @@ func TestController(t *testing.T) {
415312
expectedSchedulingCtx: withSpecificUnsuitableNodes(withSelectedNode(withSpecificPotentialNodes(podSchedulingCtx, maxNodes)), append(maxNodes[1:], nodeName)),
416313
expectedError: errPeriodic.Error(),
417314
},
418-
// pod with delayed allocation, max potential nodes, other selected node, all unsuitable (but in reverse order) -> update unsuitable nodes with truncation at end
315+
// max potential nodes, other selected node, all unsuitable (but in reverse order) -> update unsuitable nodes with truncation at end
419316
"pod-selected-is-potential-node-truncate-last": {
420317
key: podKey,
421318
classes: classes,
422-
claim: delayedClaim,
423-
expectedClaim: delayedClaim,
319+
claim: claim,
320+
expectedClaim: claim,
424321
pod: podWithClaim,
425322
schedulingCtx: withSpecificPotentialNodes(withSelectedNode(withSpecificPotentialNodes(podSchedulingCtx, maxNodes)), maxNodes),
426323
driver: m.expectClassParameters(map[string]interface{}{className: 1}).
@@ -652,7 +549,6 @@ func createClaim(claimName, claimNamespace, className string) *resourceapi.Resou
652549
},
653550
Spec: resourceapi.ResourceClaimSpec{
654551
ResourceClassName: className,
655-
AllocationMode: resourceapi.AllocationModeImmediate,
656552
},
657553
}
658554
}

0 commit comments

Comments
 (0)