@@ -20,6 +20,7 @@ import (
20
20
v1 "k8s.io/api/core/v1"
21
21
"k8s.io/apimachinery/pkg/api/resource"
22
22
"k8s.io/apimachinery/pkg/runtime"
23
+ "k8s.io/apimachinery/pkg/util/uuid"
23
24
"k8s.io/client-go/informers"
24
25
"k8s.io/client-go/kubernetes/fake"
25
26
"sigs.k8s.io/descheduler/pkg/api"
@@ -363,6 +364,8 @@ func TestDefaultEvictorFilter(t *testing.T) {
363
364
nodeTaintKey := "hardware"
364
365
nodeTaintValue := "gpu"
365
366
367
+ ownerRefUUID := uuid .NewUUID ()
368
+
366
369
type testCase struct {
367
370
description string
368
371
pods []* v1.Pod
@@ -372,6 +375,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
372
375
evictSystemCriticalPods bool
373
376
priorityThreshold * int32
374
377
nodeFit bool
378
+ minReplicas uint
375
379
result bool
376
380
}
377
381
@@ -527,7 +531,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
527
531
evictSystemCriticalPods : false ,
528
532
result : true ,
529
533
}, {
530
- description : "Pod not evicted becasuse it is part of a daemonSet" ,
534
+ description : "Pod not evicted because it is part of a daemonSet" ,
531
535
pods : []* v1.Pod {
532
536
test .BuildTestPod ("p8" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
533
537
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -538,7 +542,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
538
542
evictSystemCriticalPods : false ,
539
543
result : false ,
540
544
}, {
541
- description : "Pod is evicted becasuse it is part of a daemonSet, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
545
+ description : "Pod is evicted because it is part of a daemonSet, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
542
546
pods : []* v1.Pod {
543
547
test .BuildTestPod ("p9" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
544
548
pod .Annotations = map [string ]string {"descheduler.alpha.kubernetes.io/evict" : "true" }
@@ -549,7 +553,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
549
553
evictSystemCriticalPods : false ,
550
554
result : true ,
551
555
}, {
552
- description : "Pod not evicted becasuse it is a mirror poddsa" ,
556
+ description : "Pod not evicted because it is a mirror poddsa" ,
553
557
pods : []* v1.Pod {
554
558
test .BuildTestPod ("p10" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
555
559
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -560,7 +564,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
560
564
evictSystemCriticalPods : false ,
561
565
result : false ,
562
566
}, {
563
- description : "Pod is evicted becasuse it is a mirror pod, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
567
+ description : "Pod is evicted because it is a mirror pod, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
564
568
pods : []* v1.Pod {
565
569
test .BuildTestPod ("p11" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
566
570
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -572,7 +576,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
572
576
evictSystemCriticalPods : false ,
573
577
result : true ,
574
578
}, {
575
- description : "Pod not evicted becasuse it has system critical priority" ,
579
+ description : "Pod not evicted because it has system critical priority" ,
576
580
pods : []* v1.Pod {
577
581
test .BuildTestPod ("p12" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
578
582
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -584,7 +588,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
584
588
evictSystemCriticalPods : false ,
585
589
result : false ,
586
590
}, {
587
- description : "Pod is evicted becasuse it has system critical priority, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
591
+ description : "Pod is evicted because it has system critical priority, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
588
592
pods : []* v1.Pod {
589
593
test .BuildTestPod ("p13" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
590
594
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -599,7 +603,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
599
603
evictSystemCriticalPods : false ,
600
604
result : true ,
601
605
}, {
602
- description : "Pod not evicted becasuse it has a priority higher than the configured priority threshold" ,
606
+ description : "Pod not evicted because it has a priority higher than the configured priority threshold" ,
603
607
pods : []* v1.Pod {
604
608
test .BuildTestPod ("p14" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
605
609
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -611,7 +615,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
611
615
priorityThreshold : & lowPriority ,
612
616
result : false ,
613
617
}, {
614
- description : "Pod is evicted becasuse it has a priority higher than the configured priority threshold, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
618
+ description : "Pod is evicted because it has a priority higher than the configured priority threshold, but it has scheduler.alpha.kubernetes.io/evict annotation" ,
615
619
pods : []* v1.Pod {
616
620
test .BuildTestPod ("p15" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
617
621
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -624,7 +628,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
624
628
priorityThreshold : & lowPriority ,
625
629
result : true ,
626
630
}, {
627
- description : "Pod is evicted becasuse it has system critical priority, but evictSystemCriticalPods = true" ,
631
+ description : "Pod is evicted because it has system critical priority, but evictSystemCriticalPods = true" ,
628
632
pods : []* v1.Pod {
629
633
test .BuildTestPod ("p16" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
630
634
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -636,7 +640,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
636
640
evictSystemCriticalPods : true ,
637
641
result : true ,
638
642
}, {
639
- description : "Pod is evicted becasuse it has system critical priority, but evictSystemCriticalPods = true and it has scheduler.alpha.kubernetes.io/evict annotation" ,
643
+ description : "Pod is evicted because it has system critical priority, but evictSystemCriticalPods = true and it has scheduler.alpha.kubernetes.io/evict annotation" ,
640
644
pods : []* v1.Pod {
641
645
test .BuildTestPod ("p16" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
642
646
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -649,7 +653,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
649
653
evictSystemCriticalPods : true ,
650
654
result : true ,
651
655
}, {
652
- description : "Pod is evicted becasuse it has a priority higher than the configured priority threshold, but evictSystemCriticalPods = true" ,
656
+ description : "Pod is evicted because it has a priority higher than the configured priority threshold, but evictSystemCriticalPods = true" ,
653
657
pods : []* v1.Pod {
654
658
test .BuildTestPod ("p17" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
655
659
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -661,7 +665,7 @@ func TestDefaultEvictorFilter(t *testing.T) {
661
665
priorityThreshold : & lowPriority ,
662
666
result : true ,
663
667
}, {
664
- description : "Pod is evicted becasuse it has a priority higher than the configured priority threshold, but evictSystemCriticalPods = true and it has scheduler.alpha.kubernetes.io/evict annotation" ,
668
+ description : "Pod is evicted because it has a priority higher than the configured priority threshold, but evictSystemCriticalPods = true and it has scheduler.alpha.kubernetes.io/evict annotation" ,
665
669
pods : []* v1.Pod {
666
670
test .BuildTestPod ("p17" , 400 , 0 , n1 .Name , func (pod * v1.Pod ) {
667
671
pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
@@ -704,6 +708,47 @@ func TestDefaultEvictorFilter(t *testing.T) {
704
708
evictSystemCriticalPods : false ,
705
709
nodeFit : true ,
706
710
result : true ,
711
+ }, {
712
+ description : "minReplicas of 2, owner with 2 replicas, evicts" ,
713
+ pods : []* v1.Pod {
714
+ test .BuildTestPod ("p1" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
715
+ pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
716
+ pod .ObjectMeta .OwnerReferences [0 ].UID = ownerRefUUID
717
+ }),
718
+ test .BuildTestPod ("p2" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
719
+ pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
720
+ pod .ObjectMeta .OwnerReferences [0 ].UID = ownerRefUUID
721
+ }),
722
+ },
723
+ minReplicas : 2 ,
724
+ result : true ,
725
+ }, {
726
+ description : "minReplicas of 3, owner with 2 replicas, no eviction" ,
727
+ pods : []* v1.Pod {
728
+ test .BuildTestPod ("p1" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
729
+ pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
730
+ pod .ObjectMeta .OwnerReferences [0 ].UID = ownerRefUUID
731
+ }),
732
+ test .BuildTestPod ("p2" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
733
+ pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
734
+ pod .ObjectMeta .OwnerReferences [0 ].UID = ownerRefUUID
735
+ }),
736
+ },
737
+ minReplicas : 3 ,
738
+ result : false ,
739
+ }, {
740
+ description : "minReplicas of 2, multiple owners, no eviction" ,
741
+ pods : []* v1.Pod {
742
+ test .BuildTestPod ("p1" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
743
+ pod .ObjectMeta .OwnerReferences = append (test .GetNormalPodOwnerRefList (), test .GetNormalPodOwnerRefList ()... )
744
+ pod .ObjectMeta .OwnerReferences [0 ].UID = ownerRefUUID
745
+ }),
746
+ test .BuildTestPod ("p2" , 1 , 1 , n1 .Name , func (pod * v1.Pod ) {
747
+ pod .ObjectMeta .OwnerReferences = test .GetNormalPodOwnerRefList ()
748
+ }),
749
+ },
750
+ minReplicas : 2 ,
751
+ result : true ,
707
752
},
708
753
}
709
754
@@ -741,7 +786,8 @@ func TestDefaultEvictorFilter(t *testing.T) {
741
786
PriorityThreshold : & api.PriorityThreshold {
742
787
Value : test .priorityThreshold ,
743
788
},
744
- NodeFit : test .nodeFit ,
789
+ NodeFit : test .nodeFit ,
790
+ MinReplicas : test .minReplicas ,
745
791
}
746
792
747
793
evictorPlugin , err := New (
0 commit comments