@@ -18,6 +18,7 @@ package termination_test
18
18
19
19
import (
20
20
"context"
21
+ "fmt"
21
22
"sync"
22
23
"testing"
23
24
"time"
@@ -89,6 +90,7 @@ var _ = Describe("Termination", func() {
89
90
90
91
nodePool = test .NodePool ()
91
92
nodeClaim , node = test .NodeClaimAndNode (v1.NodeClaim {ObjectMeta : metav1.ObjectMeta {Finalizers : []string {v1 .TerminationFinalizer }}})
93
+
92
94
node .Labels [v1 .NodePoolLabelKey ] = test .NodePool ().Name
93
95
cloudProvider .CreatedNodeClaims [node .Spec .ProviderID ] = nodeClaim
94
96
})
@@ -189,6 +191,8 @@ var _ = Describe("Termination", func() {
189
191
Expect (env .Client .Delete (ctx , node )).To (Succeed ())
190
192
// We only reconcile once since this label should be applied before draining the node
191
193
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node ))
194
+ ExpectObjectReconcileFailed (ctx , env .Client , queue , pod )
195
+
192
196
node = ExpectNodeExists (ctx , env .Client , node .Name )
193
197
Expect (node .Labels [corev1 .LabelNodeExcludeBalancers ]).Should (Equal ("karpenter" ))
194
198
})
@@ -200,27 +204,29 @@ var _ = Describe("Termination", func() {
200
204
ObjectMeta : metav1.ObjectMeta {OwnerReferences : defaultOwnerRefs },
201
205
})
202
206
ExpectApplied (ctx , env .Client , node , nodeClaim , podEvict , podSkip )
207
+ ExpectMakeNodesReady (ctx , env .Client , node ) // Remove the not-ready taint
203
208
204
209
// Trigger Termination Controller
205
210
Expect (env .Client .Delete (ctx , node )).To (Succeed ())
206
211
node = ExpectNodeExists (ctx , env .Client , node .Name )
207
- ExpectObjectReconciled (ctx , env .Client , terminationController , node )
208
212
Expect (queue .Has (podSkip )).To (BeFalse ())
209
213
ExpectObjectReconciled (ctx , env .Client , queue , podEvict )
210
214
211
215
// Expect node to exist and be draining
216
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
212
217
ExpectNodeWithNodeClaimDraining (env .Client , node .Name )
213
218
214
219
// Expect podEvict to be evicting, and delete it
215
220
EventuallyExpectTerminating (ctx , env .Client , podEvict )
216
221
ExpectDeleted (ctx , env .Client , podEvict )
222
+ ExpectObjectReconciled (ctx , env .Client , queue , podSkip )
217
223
218
224
// Reconcile to delete node
219
225
node = ExpectNodeExists (ctx , env .Client , node .Name )
220
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
221
226
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // VolumeDetachment
222
227
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationInitiation
223
- ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
228
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
229
+ ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // FinalizerRemoval
224
230
ExpectNotFound (ctx , env .Client , node )
225
231
})
226
232
It ("should not evict pods that tolerate karpenter disruption taint with exists operator" , func () {
@@ -231,15 +237,16 @@ var _ = Describe("Termination", func() {
231
237
ObjectMeta : metav1.ObjectMeta {OwnerReferences : defaultOwnerRefs },
232
238
})
233
239
ExpectApplied (ctx , env .Client , node , nodeClaim , podEvict , podSkip )
240
+ ExpectMakeNodesReady (ctx , env .Client , node ) // Remove the not-ready taint
234
241
235
242
// Trigger Termination Controller
236
243
Expect (env .Client .Delete (ctx , node )).To (Succeed ())
237
244
node = ExpectNodeExists (ctx , env .Client , node .Name )
238
- ExpectObjectReconciled (ctx , env .Client , terminationController , node )
239
245
Expect (queue .Has (podSkip )).To (BeFalse ())
240
246
ExpectObjectReconciled (ctx , env .Client , queue , podEvict )
241
247
242
248
// Expect node to exist and be draining
249
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
243
250
ExpectNodeWithNodeClaimDraining (env .Client , node .Name )
244
251
245
252
// Expect podEvict to be evicting, and delete it
@@ -250,10 +257,10 @@ var _ = Describe("Termination", func() {
250
257
251
258
// Reconcile to delete node
252
259
node = ExpectNodeExists (ctx , env .Client , node .Name )
253
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
254
260
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // VolumeDetachment
255
261
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationInitiation
256
- ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
262
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
263
+ ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // FinalizerRemoval
257
264
ExpectNotFound (ctx , env .Client , node )
258
265
})
259
266
It ("should evict pods that tolerate the node.kubernetes.io/unschedulable taint" , func () {
@@ -271,6 +278,7 @@ var _ = Describe("Termination", func() {
271
278
ExpectObjectReconciled (ctx , env .Client , queue , podEvict )
272
279
273
280
// Expect node to exist and be draining
281
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
274
282
ExpectNodeWithNodeClaimDraining (env .Client , node .Name )
275
283
276
284
// Expect podEvict to be evicting, and delete it
@@ -279,10 +287,10 @@ var _ = Describe("Termination", func() {
279
287
280
288
// Reconcile to delete node
281
289
node = ExpectNodeExists (ctx , env .Client , node .Name )
282
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
283
290
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // VolumeDetachment
284
291
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationInitiation
285
- ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
292
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
293
+ ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // FinalizerRemoval
286
294
ExpectNotFound (ctx , env .Client , node )
287
295
})
288
296
It ("should delete nodes that have pods without an ownerRef" , func () {
@@ -303,17 +311,18 @@ var _ = Describe("Termination", func() {
303
311
EventuallyExpectTerminating (ctx , env .Client , pod )
304
312
305
313
// Expect node to exist and be draining
314
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
306
315
ExpectNodeWithNodeClaimDraining (env .Client , node .Name )
307
316
308
317
// Delete no owner refs pod to simulate successful eviction
309
318
ExpectDeleted (ctx , env .Client , pod )
310
319
311
320
// Reconcile node to evict pod and delete node
312
321
node = ExpectNodeExists (ctx , env .Client , node .Name )
313
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
314
322
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // VolumeDetachment
315
323
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationInitiation
316
- ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
324
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
325
+ ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // FinalizerRemoval
317
326
ExpectNotFound (ctx , env .Client , node )
318
327
})
319
328
It ("should delete nodes with terminal pods" , func () {
@@ -367,7 +376,7 @@ var _ = Describe("Termination", func() {
367
376
Expect (queue .Has (podNoEvict )).To (BeTrue ())
368
377
369
378
// Attempt to evict the pod, but fail to do so
370
- ExpectObjectReconciled (ctx , env .Client , queue , podNoEvict )
379
+ ExpectObjectReconcileFailed (ctx , env .Client , queue , podNoEvict )
371
380
372
381
// Expect podNoEvict to fail eviction due to PDB, and be retried
373
382
Expect (queue .Has (podNoEvict )).To (BeTrue ())
@@ -378,10 +387,10 @@ var _ = Describe("Termination", func() {
378
387
379
388
// Reconcile to delete node
380
389
node = ExpectNodeExists (ctx , env .Client , node .Name )
381
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // DrainValidation
382
390
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // VolumeDetachment
383
391
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationInitiation
384
- ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
392
+ ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // InstanceTerminationValidation
393
+ ExpectNotRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // Finalizer Removal
385
394
ExpectNotFound (ctx , env .Client , node )
386
395
})
387
396
It ("should evict pods in order and wait until pods are fully deleted" , func () {
@@ -432,6 +441,7 @@ var _ = Describe("Termination", func() {
432
441
ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node ))
433
442
ExpectNodeWithNodeClaimDraining (env .Client , node .Name )
434
443
for _ , pod := range podGroup {
444
+ Expect (queue .Has (pod )).To (BeTrue ())
435
445
ExpectObjectReconciled (ctx , env .Client , queue , pod )
436
446
}
437
447
// Start draining the pod group, but don't complete it yet
@@ -440,7 +450,7 @@ var _ = Describe("Termination", func() {
440
450
// Look at the next pod group and ensure that none of the pods have started terminating on it
441
451
if i != len (podGroups )- 1 {
442
452
for _ , pod := range podGroups [i + 1 ] {
443
- ExpectObjectReconciled ( ctx , env . Client , queue , pod )
453
+ Expect ( queue . Has ( pod )). To ( BeFalse () )
444
454
}
445
455
ConsistentlyExpectNotTerminating (ctx , env .Client , lo .Map (podGroups [i + 1 ], func (p * corev1.Pod , _ int ) client.Object { return p })... )
446
456
}
@@ -518,6 +528,7 @@ var _ = Describe("Termination", func() {
518
528
519
529
// Expect mirror pod to not be queued for eviction
520
530
Expect (queue .Has (podNoEvict )).To (BeFalse ())
531
+ ExpectObjectReconciled (ctx , env .Client , queue , podEvict )
521
532
522
533
// Expect podEvict to be enqueued for eviction then be successful
523
534
EventuallyExpectTerminating (ctx , env .Client , podEvict )
@@ -712,8 +723,8 @@ var _ = Describe("Termination", func() {
712
723
})
713
724
ExpectApplied (ctx , env .Client , node , pod )
714
725
715
- // Trigger eviction queue with the pod key still in it
716
- ExpectObjectReconciled ( ctx , env . Client , queue , pod )
726
+ // Trigger eviction queue with the old pod key still in it
727
+ queue . Add ( pod )
717
728
718
729
Consistently (func (g Gomega ) {
719
730
g .Expect (env .Client .Get (ctx , client .ObjectKeyFromObject (pod ), pod )).To (Succeed ())
@@ -920,29 +931,6 @@ var _ = Describe("Termination", func() {
920
931
Expect (ok ).To (BeTrue ())
921
932
Expect (lo .FromPtr (m .GetHistogram ().SampleCount )).To (BeNumerically ("==" , 1 ))
922
933
})
923
- It ("should update the eviction queueDepth metric when reconciling pods" , func () {
924
- minAvailable := intstr .FromInt32 (0 )
925
- labelSelector := map [string ]string {test .RandomName (): test .RandomName ()}
926
- pdb := test .PodDisruptionBudget (test.PDBOptions {
927
- Labels : labelSelector ,
928
- // Don't let any pod evict
929
- MinAvailable : & minAvailable ,
930
- })
931
- ExpectApplied (ctx , env .Client , pdb , node , nodeClaim )
932
- pods := test .Pods (5 , test.PodOptions {NodeName : node .Name , ObjectMeta : metav1.ObjectMeta {
933
- OwnerReferences : defaultOwnerRefs ,
934
- Labels : labelSelector ,
935
- }})
936
- ExpectApplied (ctx , env .Client , lo .Map (pods , func (p * corev1.Pod , _ int ) client.Object { return p })... )
937
-
938
- wqDepthBefore , _ := FindMetricWithLabelValues ("workqueue_adds_total" , map [string ]string {"name" : "eviction.workqueue" })
939
- Expect (env .Client .Delete (ctx , node )).To (Succeed ())
940
- node = ExpectNodeExists (ctx , env .Client , node .Name )
941
- ExpectRequeued (ExpectObjectReconciled (ctx , env .Client , terminationController , node )) // Drain
942
- wqDepthAfter , ok := FindMetricWithLabelValues ("workqueue_adds_total" , map [string ]string {"name" : "eviction.workqueue" })
943
- Expect (ok ).To (BeTrue ())
944
- Expect (lo .FromPtr (wqDepthAfter .GetCounter ().Value ) - lo .FromPtr (wqDepthBefore .GetCounter ().Value )).To (BeNumerically ("==" , 5 ))
945
- })
946
934
})
947
935
})
948
936
0 commit comments