@@ -45,6 +45,8 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
45
45
scheduledPodRep1Copy1 := buildTestPod ("default" , "-scheduled-pod-rep1-1" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ), WithNodeName (node .Name ))
46
46
podRep1Copy1 := buildTestPod ("default" , "pod-rep1-1" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
47
47
podRep1Copy2 := buildTestPod ("default" , "pod-rep1-2" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
48
+ podRep1Copy3Gated := buildTestPod ("default" , "pod-rep1-3" , WithControllerOwnerRef (replicaSet1 .Name , "ReplicaSet" , replicaSet1 .UID ))
49
+ podRep1Copy3Gated = WithSchedulingGatedStatus (podRep1Copy3Gated )
48
50
49
51
job1 := createTestJob ("job-1" , "default" , 10 , 10 , 0 )
50
52
scheduledPodJob1Copy1 := buildTestPod ("default" , "scheduled-pod-job1-1" , WithControllerOwnerRef (job1 .Name , "Job" , job1 .UID ), WithNodeName (node .Name ))
@@ -55,6 +57,8 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
55
57
scheduledParallelStatefulsetPod := buildTestPod ("default" , "parallel-scheduled-pod-statefulset-1" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ), WithNodeName (node .Name ))
56
58
parallelStatefulsetPodCopy1 := buildTestPod ("default" , "parallel-pod-statefulset1-1" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
57
59
parallelStatefulsetPodCopy2 := buildTestPod ("default" , "parallel-pod-statefulset1-2" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
60
+ parallelStatefulsetPodCopy3Gated := buildTestPod ("default" , "parallel-pod-statefulset1-3" , WithControllerOwnerRef (parallelStatefulset .Name , "StatefulSet" , parallelStatefulset .UID ))
61
+ parallelStatefulsetPodCopy3Gated = WithSchedulingGatedStatus (parallelStatefulsetPodCopy3Gated )
58
62
59
63
sequentialStatefulset := createTestStatefulset ("sequential-statefulset-1" , "default" , appsv1 .OrderedReadyPodManagement , 10 )
60
64
scheduledSequentialStatefulsetPod := buildTestPod ("default" , "sequential-scheduled-pod-statefulset-1" , WithControllerOwnerRef (sequentialStatefulset .Name , "StatefulSet" , sequentialStatefulset .UID ), WithNodeName (node .Name ))
@@ -72,6 +76,7 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
72
76
name string
73
77
scheduledPods []* apiv1.Pod
74
78
unschedulablePods []* apiv1.Pod
79
+ otherPods []* apiv1.Pod
75
80
wantPods []* apiv1.Pod
76
81
}{
77
82
{
@@ -111,6 +116,20 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
111
116
makeFakePods (parallelStatefulset .UID , scheduledParallelStatefulsetPod , 7 )... ,
112
117
),
113
118
},
119
+ {
120
+ name : "Mix of controllers with scheduling gated pods" ,
121
+ scheduledPods : []* apiv1.Pod {scheduledPodRep1Copy1 , scheduledPodJob1Copy1 , scheduledParallelStatefulsetPod },
122
+ unschedulablePods : []* apiv1.Pod {podRep1Copy1 , podRep1Copy2 , podJob1Copy1 , podJob1Copy2 , parallelStatefulsetPodCopy1 , parallelStatefulsetPodCopy2 },
123
+ otherPods : []* apiv1.Pod {parallelStatefulsetPodCopy3Gated , podRep1Copy3Gated },
124
+ wantPods : append (
125
+ append (
126
+ append (
127
+ []* apiv1.Pod {podRep1Copy1 , podRep1Copy2 , podJob1Copy1 , podJob1Copy2 , parallelStatefulsetPodCopy1 , parallelStatefulsetPodCopy2 },
128
+ makeFakePods (replicaSet1 .UID , scheduledPodRep1Copy1 , 1 )... ),
129
+ makeFakePods (job1 .UID , scheduledPodJob1Copy1 , 7 )... ),
130
+ makeFakePods (parallelStatefulset .UID , scheduledParallelStatefulsetPod , 6 )... ,
131
+ ),
132
+ },
114
133
}
115
134
116
135
for _ , tc := range testCases {
@@ -119,9 +138,10 @@ func TestTargetCountInjectionPodListProcessor(t *testing.T) {
119
138
clusterSnapshot := testsnapshot .NewCustomTestSnapshotOrDie (t , store .NewDeltaSnapshotStore (16 ))
120
139
err := clusterSnapshot .AddNodeInfo (framework .NewTestNodeInfo (node , tc .scheduledPods ... ))
121
140
assert .NoError (t , err )
141
+ allPodsLister := fakeAllPodsLister {podsToList : append (append (tc .scheduledPods , tc .unschedulablePods ... ), tc .otherPods ... )}
122
142
ctx := context.AutoscalingContext {
123
143
AutoscalingKubeClients : context.AutoscalingKubeClients {
124
- ListerRegistry : kubernetes .NewListerRegistry (nil , nil , nil , nil , nil , nil , jobLister , replicaSetLister , statefulsetLister ),
144
+ ListerRegistry : kubernetes .NewListerRegistry (nil , nil , & allPodsLister , nil , nil , nil , jobLister , replicaSetLister , statefulsetLister ),
125
145
},
126
146
ClusterSnapshot : clusterSnapshot ,
127
147
}
@@ -433,3 +453,11 @@ func buildTestPod(namespace, name string, opts ...podOption) *apiv1.Pod {
433
453
}
434
454
435
455
type podOption func (* apiv1.Pod )
456
+
457
+ type fakeAllPodsLister struct {
458
+ podsToList []* apiv1.Pod
459
+ }
460
+
461
+ func (l * fakeAllPodsLister ) List () ([]* apiv1.Pod , error ) {
462
+ return l .podsToList , nil
463
+ }
0 commit comments