@@ -38,13 +38,22 @@ import (
38
38
. "k8s.io/autoscaler/cluster-autoscaler/utils/test"
39
39
)
40
40
41
+ func setStatusConditionGated (pod * apiv1.Pod ) {
42
+ pod .Status .Conditions = []apiv1.PodCondition {{
43
+ Type : apiv1 .PodScheduled ,
44
+ Status : apiv1 .ConditionFalse ,
45
+ Reason : apiv1 .PodReasonSchedulingGated ,
46
+ }}
47
+ }
41
48
func TestTargetCountInjectionPodListProcessor (t * testing.T ) {
42
49
node := BuildTestNode ("node1" , 100 , 0 )
43
50
44
51
replicaSet1 := createTestReplicaSet ("rep-set-1" , "default" , 5 )
45
52
scheduledPodRep1Copy1 := buildTestPod ("default" , "-scheduled-pod-rep1-1" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ), WithNodeName (node .Name ))
46
53
podRep1Copy1 := buildTestPod ("default" , "pod-rep1-1" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
47
54
podRep1Copy2 := buildTestPod ("default" , "pod-rep1-2" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
55
+ podRep1Copy3Gated := buildTestPod ("default" , "pod-rep1-3" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
56
+ setStatusConditionGated (podRep1Copy3Gated )
48
57
49
58
job1 := createTestJob ("job-1" , "default" , 10 , 10 , 0 )
50
59
scheduledPodJob1Copy1 := buildTestPod ("default" , "scheduled-pod-job1-1" , WithControllerOwnerRef (job1 .Name , "Job" , job1 .UID ), WithNodeName (node .Name ))
@@ -55,6 +64,8 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
55
64
scheduledParallelStatefulsetPod := buildTestPod ("default" , "parallel-scheduled-pod-statefulset-1" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ), WithNodeName (node .Name ))
56
65
parallelStatefulsetPodCopy1 := buildTestPod ("default" , "parallel-pod-statefulset1-1" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
57
66
parallelStatefulsetPodCopy2 := buildTestPod ("default" , "parallel-pod-statefulset1-2" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
67
+ parallelStatefulsetPodCopy3Gated := buildTestPod ("default" , "parallel-pod-statefulset1-3" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
68
+ setStatusConditionGated (parallelStatefulsetPodCopy3Gated )
58
69
59
70
sequentialStatefulset := createTestStatefulset ("sequential-statefulset-1" , "default" , appsv1 .OrderedReadyPodManagement , 10 )
60
71
scheduledSequentialStatefulsetPod := buildTestPod ("default" , "sequential-scheduled-pod-statefulset-1" , WithControllerOwnerRef (sequentialStatefulset .Name , "StatefulSet" , sequentialStatefulset .UID ), WithNodeName (node .Name ))
@@ -72,6 +83,7 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
72
83
name string
73
84
scheduledPods []* apiv1.Pod
74
85
unschedulablePods []* apiv1.Pod
86
+ otherPods []* apiv1.Pod
75
87
wantPods []* apiv1.Pod
76
88
}{
77
89
{
@@ -111,6 +123,20 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
111
123
makeFakePods (parallelStatefulset .UID , scheduledParallelStatefulsetPod , 7 )... ,
112
124
),
113
125
},
126
+ {
127
+ name : "Mix of controllers with scheduling gated pods" ,
128
+ scheduledPods : []* apiv1.Pod {scheduledPodRep1Copy1 , scheduledPodJob1Copy1 , scheduledParallelStatefulsetPod },
129
+ unschedulablePods : []* apiv1.Pod {podRep1Copy1 , podRep1Copy2 , podJob1Copy1 , podJob1Copy2 , parallelStatefulsetPodCopy1 , parallelStatefulsetPodCopy2 },
130
+ otherPods : []* apiv1.Pod {parallelStatefulsetPodCopy3Gated , podRep1Copy3Gated },
131
+ wantPods : append (
132
+ append (
133
+ append (
134
+ []* apiv1.Pod {podRep1Copy1 , podRep1Copy2 , podJob1Copy1 , podJob1Copy2 , parallelStatefulsetPodCopy1 , parallelStatefulsetPodCopy2 },
135
+ makeFakePods (replicaSet1 .UID , scheduledPodRep1Copy1 , 1 )... ),
136
+ makeFakePods (job1 .UID , scheduledPodJob1Copy1 , 7 )... ),
137
+ makeFakePods (parallelStatefulset .UID , scheduledParallelStatefulsetPod , 6 )... ,
138
+ ),
139
+ },
114
140
}
115
141
116
142
for _ , tc := range testCases {
@@ -119,15 +145,16 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
119
145
clusterSnapshot := testsnapshot .NewCustomTestSnapshotOrDie (t , store .NewDeltaSnapshotStore (16 ))
120
146
err := clusterSnapshot .AddNodeInfo (framework .NewTestNodeInfo (node , tc .scheduledPods ... ))
121
147
assert .NoError (t , err )
148
+ allPodsLister := fakeAllPodsLister {podsToList : append (append (tc .scheduledPods , tc .unschedulablePods ... ), tc .otherPods ... )}
122
149
ctx := context.AutoscalingContext {
123
150
AutoscalingKubeClients : context.AutoscalingKubeClients {
124
- ListerRegistry : kubernetes .NewListerRegistry (nil , nil , nil , nil , nil , nil , jobLister , replicaSetLister , statefulsetLister ),
151
+ ListerRegistry : kubernetes .NewListerRegistry (nil , nil , & allPodsLister , nil , nil , nil , jobLister , replicaSetLister , statefulsetLister ),
125
152
},
126
153
ClusterSnapshot : clusterSnapshot ,
127
154
}
128
155
pods , err := p .Process (& ctx , tc .unschedulablePods )
129
156
assert .NoError (t , err )
130
- assert .ElementsMatch (t , tc .wantPods , pods )
157
+ assert .Equal (t , tc .wantPods , pods )
131
158
})
132
159
}
133
160
}
@@ -433,3 +460,11 @@ func buildTestPod(namespace, name string, opts ...podOption) *apiv1.Pod {
433
460
}
434
461
435
462
type podOption func (* apiv1.Pod )
463
+
464
+ type fakeAllPodsLister struct {
465
+ podsToList []* apiv1.Pod
466
+ }
467
+
468
+ func (l * fakeAllPodsLister ) List () ([]* apiv1.Pod , error ) {
469
+ return l .podsToList , nil
470
+ }
0 commit comments