@@ -31,20 +31,17 @@ import (
31
31
"k8s.io/apimachinery/pkg/util/sets"
32
32
"k8s.io/apimachinery/pkg/util/strategicpatch"
33
33
"k8s.io/apimachinery/pkg/util/wait"
34
- utilfeature "k8s.io/apiserver/pkg/util/feature"
35
34
"k8s.io/client-go/informers"
36
35
coreinformers "k8s.io/client-go/informers/core/v1"
37
36
clientset "k8s.io/client-go/kubernetes"
38
37
"k8s.io/client-go/kubernetes/fake"
39
38
clienttesting "k8s.io/client-go/testing"
40
39
"k8s.io/client-go/util/workqueue"
41
- featuregatetesting "k8s.io/component-base/featuregate/testing"
42
40
metricstestutil "k8s.io/component-base/metrics/testutil"
43
41
"k8s.io/klog/v2/ktesting"
44
42
"k8s.io/kubernetes/pkg/controller"
45
43
"k8s.io/kubernetes/pkg/controller/podgc/metrics"
46
44
"k8s.io/kubernetes/pkg/controller/testutil"
47
- "k8s.io/kubernetes/pkg/features"
48
45
"k8s.io/kubernetes/pkg/kubelet/eviction"
49
46
testingclock "k8s.io/utils/clock/testing"
50
47
"k8s.io/utils/pointer"
@@ -69,23 +66,21 @@ func TestGCTerminated(t *testing.T) {
69
66
}
70
67
71
68
testCases := []struct {
72
- name string
73
- pods []nameToPhase
74
- threshold int
75
- deletedPodNames sets.Set [string ]
76
- patchedPodNames sets.Set [string ]
77
- enablePodDisruptionConditions bool
69
+ name string
70
+ pods []nameToPhase
71
+ threshold int
72
+ deletedPodNames sets.Set [string ]
73
+ patchedPodNames sets.Set [string ]
78
74
}{
79
75
{
80
- name : "delete pod a which is PodFailed and pod b which is PodSucceeded; PodDisruptionConditions enabled " ,
76
+ name : "delete pod a which is PodFailed and pod b which is PodSucceeded" ,
81
77
pods : []nameToPhase {
82
78
{name : "a" , phase : v1 .PodFailed },
83
79
{name : "b" , phase : v1 .PodSucceeded },
84
80
{name : "c" , phase : v1 .PodFailed },
85
81
},
86
- threshold : 1 ,
87
- deletedPodNames : sets .New ("a" , "b" ),
88
- enablePodDisruptionConditions : true ,
82
+ threshold : 1 ,
83
+ deletedPodNames : sets .New ("a" , "b" ),
89
84
},
90
85
{
91
86
name : "threshold = 0, disables terminated pod deletion" ,
@@ -156,7 +151,6 @@ func TestGCTerminated(t *testing.T) {
156
151
t .Run (test .name , func (t * testing.T ) {
157
152
resetMetrics ()
158
153
_ , ctx := ktesting .NewTestContext (t )
159
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodDisruptionConditions , test .enablePodDisruptionConditions )
160
154
creationTime := time .Unix (0 , 0 )
161
155
nodes := []* v1.Node {testutil .NewNode ("node" )}
162
156
@@ -206,19 +200,18 @@ func waitForAdded(q workqueue.TypedDelayingInterface[string], depth int) error {
206
200
207
201
func TestGCOrphaned (t * testing.T ) {
208
202
testCases := []struct {
209
- name string
210
- initialClientNodes []* v1.Node
211
- initialInformerNodes []* v1.Node
212
- delay time.Duration
213
- addedClientNodes []* v1.Node
214
- deletedClientNodes []* v1.Node
215
- addedInformerNodes []* v1.Node
216
- deletedInformerNodes []* v1.Node
217
- pods []* v1.Pod
218
- itemsInQueue int
219
- deletedPodNames sets.Set [string ]
220
- patchedPodNames sets.Set [string ]
221
- enablePodDisruptionConditions bool
203
+ name string
204
+ initialClientNodes []* v1.Node
205
+ initialInformerNodes []* v1.Node
206
+ delay time.Duration
207
+ addedClientNodes []* v1.Node
208
+ deletedClientNodes []* v1.Node
209
+ addedInformerNodes []* v1.Node
210
+ deletedInformerNodes []* v1.Node
211
+ pods []* v1.Pod
212
+ itemsInQueue int
213
+ deletedPodNames sets.Set [string ]
214
+ patchedPodNames sets.Set [string ]
222
215
}{
223
216
{
224
217
name : "nodes present in lister" ,
@@ -259,17 +252,16 @@ func TestGCOrphaned(t *testing.T) {
259
252
deletedPodNames : sets .New ("a" , "b" ),
260
253
},
261
254
{
262
- name : "no nodes with PodDisruptionConditions enabled " ,
255
+ name : "no nodes, one running pod " ,
263
256
delay : 2 * quarantineTime ,
264
257
pods : []* v1.Pod {
265
258
makePod ("a" , "deleted" , v1 .PodFailed ),
266
259
makePod ("b" , "deleted" , v1 .PodSucceeded ),
267
260
makePod ("c" , "deleted" , v1 .PodRunning ),
268
261
},
269
- itemsInQueue : 1 ,
270
- deletedPodNames : sets .New ("a" , "b" , "c" ),
271
- patchedPodNames : sets .New ("c" ),
272
- enablePodDisruptionConditions : true ,
262
+ itemsInQueue : 1 ,
263
+ deletedPodNames : sets .New ("a" , "b" , "c" ),
264
+ patchedPodNames : sets .New ("c" ),
273
265
},
274
266
{
275
267
name : "quarantine not finished" ,
@@ -351,7 +343,6 @@ func TestGCOrphaned(t *testing.T) {
351
343
t .Run (test .name , func (t * testing.T ) {
352
344
resetMetrics ()
353
345
_ , ctx := ktesting .NewTestContext (t )
354
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodDisruptionConditions , test .enablePodDisruptionConditions )
355
346
356
347
client := setupNewSimpleClient (test .initialClientNodes , test .pods )
357
348
gcc , podInformer , nodeInformer := NewFromClient (ctx , client , - 1 )
@@ -416,23 +407,11 @@ func TestGCUnscheduledTerminating(t *testing.T) {
416
407
}
417
408
418
409
testCases := []struct {
419
- name string
420
- pods []nameToPhase
421
- deletedPodNames sets.Set [string ]
422
- patchedPodNames sets.Set [string ]
423
- enablePodDisruptionConditions bool
410
+ name string
411
+ pods []nameToPhase
412
+ deletedPodNames sets.Set [string ]
413
+ patchedPodNames sets.Set [string ]
424
414
}{
425
- {
426
- name : "Unscheduled pod in any phase must be deleted, the phase of the running pod is changed to Failed; PodDisruptionConditions enabled" ,
427
- pods : []nameToPhase {
428
- {name : "a" , phase : v1 .PodFailed , deletionTimeStamp : & metav1.Time {}, nodeName : "" },
429
- {name : "b" , phase : v1 .PodSucceeded , deletionTimeStamp : & metav1.Time {}, nodeName : "" },
430
- {name : "c" , phase : v1 .PodRunning , deletionTimeStamp : & metav1.Time {}, nodeName : "" },
431
- },
432
- deletedPodNames : sets .New ("a" , "b" , "c" ),
433
- patchedPodNames : sets .New ("c" ),
434
- enablePodDisruptionConditions : true ,
435
- },
436
415
{
437
416
name : "Unscheduled pod in any phase must be deleted" ,
438
417
pods : []nameToPhase {
@@ -457,7 +436,6 @@ func TestGCUnscheduledTerminating(t *testing.T) {
457
436
t .Run (test .name , func (t * testing.T ) {
458
437
resetMetrics ()
459
438
_ , ctx := ktesting .NewTestContext (t )
460
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodDisruptionConditions , test .enablePodDisruptionConditions )
461
439
creationTime := time .Unix (0 , 0 )
462
440
463
441
pods := make ([]* v1.Pod , 0 , len (test .pods ))
@@ -505,12 +483,11 @@ func TestGCTerminating(t *testing.T) {
505
483
}
506
484
507
485
testCases := []struct {
508
- name string
509
- pods []nameToPodConfig
510
- nodes []node
511
- deletedPodNames sets.Set [string ]
512
- patchedPodNames sets.Set [string ]
513
- enablePodDisruptionConditions bool
486
+ name string
487
+ pods []nameToPodConfig
488
+ nodes []node
489
+ deletedPodNames sets.Set [string ]
490
+ patchedPodNames sets.Set [string ]
514
491
}{
515
492
{
516
493
name : "pods have deletion timestamp set and the corresponding nodes are not ready" ,
@@ -592,7 +569,7 @@ func TestGCTerminating(t *testing.T) {
592
569
patchedPodNames : sets .New ("b1" , "b4" , "b5" , "b6" ),
593
570
},
594
571
{
595
- name : "pods deleted from node tained out-of-service; PodDisruptionConditions enabled " ,
572
+ name : "pods deleted from node tainted out-of-service" ,
596
573
nodes : []node {
597
574
{name : "worker" , readyCondition : v1 .ConditionFalse , taints : []v1.Taint {{Key : v1 .TaintNodeOutOfService ,
598
575
Effect : v1 .TaintEffectNoExecute }}},
@@ -602,16 +579,14 @@ func TestGCTerminating(t *testing.T) {
602
579
{name : "b" , phase : v1 .PodFailed , deletionTimeStamp : & metav1.Time {}, nodeName : "worker" },
603
580
{name : "c" , phase : v1 .PodSucceeded , deletionTimeStamp : & metav1.Time {}, nodeName : "worker" },
604
581
},
605
- deletedPodNames : sets .New ("a" , "b" , "c" ),
606
- patchedPodNames : sets .New ("a" ),
607
- enablePodDisruptionConditions : true ,
582
+ deletedPodNames : sets .New ("a" , "b" , "c" ),
583
+ patchedPodNames : sets .New ("a" ),
608
584
},
609
585
}
610
586
for _ , test := range testCases {
611
587
t .Run (test .name , func (t * testing.T ) {
612
588
resetMetrics ()
613
589
_ , ctx := ktesting .NewTestContext (t )
614
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodDisruptionConditions , test .enablePodDisruptionConditions )
615
590
616
591
creationTime := time .Unix (0 , 0 )
617
592
nodes := make ([]* v1.Node , 0 , len (test .nodes ))
@@ -720,7 +695,6 @@ func TestGCInspectingPatchedPodBeforeDeletion(t *testing.T) {
720
695
for _ , test := range testCases {
721
696
t .Run (test .name , func (t * testing.T ) {
722
697
_ , ctx := ktesting .NewTestContext (t )
723
- featuregatetesting .SetFeatureGateDuringTest (t , utilfeature .DefaultFeatureGate , features .PodDisruptionConditions , true )
724
698
725
699
pods := []* v1.Pod {test .pod }
726
700
0 commit comments