@@ -862,6 +862,25 @@ func TestReplicaCalcScaleDownIncludeUnreadyPods(t *testing.T) {
862
862
tc .runTest (t )
863
863
}
864
864
865
+ func TestReplicaCalcScaleDownExcludeUnscheduledPods (t * testing.T ) {
866
+ tc := replicaCalcTestCase {
867
+ currentReplicas : 5 ,
868
+ expectedReplicas : 1 ,
869
+ podReadiness : []v1.ConditionStatus {v1 .ConditionTrue , v1 .ConditionFalse , v1 .ConditionFalse , v1 .ConditionFalse , v1 .ConditionFalse },
870
+ podPhase : []v1.PodPhase {v1 .PodRunning , v1 .PodPending , v1 .PodPending , v1 .PodPending , v1 .PodPending },
871
+ resource : & resourceInfo {
872
+ name : v1 .ResourceCPU ,
873
+ requests : []resource.Quantity {resource .MustParse ("1.0" ), resource .MustParse ("1.0" ), resource .MustParse ("1.0" ), resource .MustParse ("1.0" ), resource .MustParse ("1.0" )},
874
+ levels : []int64 {100 },
875
+
876
+ targetUtilization : 50 ,
877
+ expectedUtilization : 10 ,
878
+ expectedValue : numContainersPerPod * 100 ,
879
+ },
880
+ }
881
+ tc .runTest (t )
882
+ }
883
+
865
884
func TestReplicaCalcScaleDownIgnoreHotCpuPods (t * testing.T ) {
866
885
tc := replicaCalcTestCase {
867
886
currentReplicas : 5 ,
@@ -1616,18 +1635,38 @@ func TestGroupPods(t *testing.T) {
1616
1635
sets .NewString ("lucretius" ),
1617
1636
sets .NewString ("epicurus" ),
1618
1637
},
1638
+ {
1639
+ name : "pending pods are ignored" ,
1640
+ pods : []* v1.Pod {
1641
+ {
1642
+ ObjectMeta : metav1.ObjectMeta {
1643
+ Name : "unscheduled" ,
1644
+ },
1645
+ Status : v1.PodStatus {
1646
+ Phase : v1 .PodPending ,
1647
+ },
1648
+ },
1649
+ },
1650
+ metrics : metricsclient.PodMetricsInfo {},
1651
+ resource : v1 .ResourceCPU ,
1652
+ expectReadyPodCount : 0 ,
1653
+ expectIgnoredPods : sets .NewString ("unscheduled" ),
1654
+ expectMissingPods : sets .NewString (),
1655
+ },
1619
1656
}
1620
1657
for _ , tc := range tests {
1621
- readyPodCount , ignoredPods , missingPods := groupPods (tc .pods , tc .metrics , tc .resource , defaultTestingCpuInitializationPeriod , defaultTestingDelayOfInitialReadinessStatus )
1622
- if readyPodCount != tc .expectReadyPodCount {
1623
- t .Errorf ("%s got readyPodCount %d, expected %d" , tc .name , readyPodCount , tc .expectReadyPodCount )
1624
- }
1625
- if ! ignoredPods .Equal (tc .expectIgnoredPods ) {
1626
- t .Errorf ("%s got unreadyPods %v, expected %v" , tc .name , ignoredPods , tc .expectIgnoredPods )
1627
- }
1628
- if ! missingPods .Equal (tc .expectMissingPods ) {
1629
- t .Errorf ("%s got missingPods %v, expected %v" , tc .name , missingPods , tc .expectMissingPods )
1630
- }
1658
+ t .Run (tc .name , func (t * testing.T ) {
1659
+ readyPodCount , ignoredPods , missingPods := groupPods (tc .pods , tc .metrics , tc .resource , defaultTestingCpuInitializationPeriod , defaultTestingDelayOfInitialReadinessStatus )
1660
+ if readyPodCount != tc .expectReadyPodCount {
1661
+ t .Errorf ("%s got readyPodCount %d, expected %d" , tc .name , readyPodCount , tc .expectReadyPodCount )
1662
+ }
1663
+ if ! ignoredPods .Equal (tc .expectIgnoredPods ) {
1664
+ t .Errorf ("%s got unreadyPods %v, expected %v" , tc .name , ignoredPods , tc .expectIgnoredPods )
1665
+ }
1666
+ if ! missingPods .Equal (tc .expectMissingPods ) {
1667
+ t .Errorf ("%s got missingPods %v, expected %v" , tc .name , missingPods , tc .expectMissingPods )
1668
+ }
1669
+ })
1631
1670
}
1632
1671
}
1633
1672
0 commit comments