@@ -139,7 +139,7 @@ func (r listerRegistryImpl) StatefulSetLister() v1appslister.StatefulSetLister {
139139}
140140
141141// PodLister lists all pods.
142- // To filter out the scheduled or unschedulable pods the helper methods ScheduledPods and UnschedulablePods should be used.
142+ // To filter out scheduled, unschedulable, or unprocessed pods the helper method FilterPodsBySchedulability should be used.
143143type PodLister interface {
144144 List () ([]* apiv1.Pod , error )
145145}
@@ -156,19 +156,6 @@ func isDeleted(pod *apiv1.Pod) bool {
156156 return pod .GetDeletionTimestamp () != nil
157157}
158158
159- // isUnschedulable checks whether a pod is unschedulable or not
160- // This method doesn't check for nil ptr, it's the responsibility of the caller
161- func isUnschedulable (pod * apiv1.Pod ) bool {
162- if isScheduled (pod ) || isDeleted (pod ) {
163- return false
164- }
165- _ , condition := podv1 .GetPodCondition (& pod .Status , apiv1 .PodScheduled )
166- if condition == nil || condition .Status != apiv1 .ConditionFalse || condition .Reason != apiv1 .PodReasonUnschedulable {
167- return false
168- }
169- return true
170- }
171-
172159// ScheduledPods is a helper method that returns all scheduled pods from given pod list.
173160func ScheduledPods (allPods []* apiv1.Pod ) []* apiv1.Pod {
174161 var scheduledPods []* apiv1.Pod
@@ -181,27 +168,28 @@ func ScheduledPods(allPods []*apiv1.Pod) []*apiv1.Pod {
181168 return scheduledPods
182169}
183170
184- // SchedulerUnprocessedPods is a helper method that returns all pods which are not yet processed by the specified bypassed schedulers
185- func SchedulerUnprocessedPods (allPods []* apiv1.Pod , bypassedSchedulers map [string ]bool ) []* apiv1.Pod {
186- var unprocessedPods []* apiv1.Pod
187-
171+ // FilterPodsBySchedulability is a helper method that returns all scheduled and unschedulable pods from given pod list.
172+ func FilterPodsBySchedulability (allPods []* apiv1.Pod , bypassedSchedulers map [string ]bool ) (scheduled , unschedulable , unprocessed []* apiv1.Pod ) {
188173 for _ , pod := range allPods {
189- if canBypass := bypassedSchedulers [pod .Spec .SchedulerName ]; ! canBypass {
174+ if isScheduled (pod ) {
175+ scheduled = append (scheduled , pod )
190176 continue
191- }
192- // Make sure it's not scheduled or deleted
193- if isScheduled (pod ) || isDeleted (pod ) || isUnschedulable (pod ) {
177+ } else if isDeleted (pod ) {
194178 continue
195- }
196- // Make sure that if it's not scheduled it's either
197- // Not processed (condition is nil)
198- // Or Reason is empty (not schedulerError, terminated, ...etc)
199- _ , condition := podv1 .GetPodCondition (& pod .Status , apiv1 .PodScheduled )
200- if condition == nil || (condition .Status == apiv1 .ConditionFalse && condition .Reason == "" ) {
201- unprocessedPods = append (unprocessedPods , pod )
179+ } else {
180+ _ , condition := podv1 .GetPodCondition (& pod .Status , apiv1 .PodScheduled )
181+ if ! (condition == nil || condition .Status != apiv1 .ConditionFalse || condition .Reason != apiv1 .PodReasonUnschedulable ) {
182+ unschedulable = append (unschedulable , pod )
183+ } else {
184+ if canBypass := bypassedSchedulers [pod .Spec .SchedulerName ]; canBypass {
185+ if condition == nil || (condition .Status == apiv1 .ConditionFalse && condition .Reason == "" ) {
186+ unprocessed = append (unprocessed , pod )
187+ }
188+ }
189+ }
202190 }
203191 }
204- return unprocessedPods
192+ return scheduled , unschedulable , unprocessed
205193}
206194
207195// SchedulingGatedPods is a helper method that returns all pods which has scheduling gate
@@ -228,18 +216,6 @@ func isSchedulingGated(pod *apiv1.Pod) bool {
228216 return false
229217}
230218
231- // UnschedulablePods is a helper method that returns all unschedulable pods from given pod list.
232- func UnschedulablePods (allPods []* apiv1.Pod ) []* apiv1.Pod {
233- var unschedulablePods []* apiv1.Pod
234- for _ , pod := range allPods {
235- if ! isUnschedulable (pod ) {
236- continue
237- }
238- unschedulablePods = append (unschedulablePods , pod )
239- }
240- return unschedulablePods
241- }
242-
243219// AllPodLister lists all pods.
244220type AllPodLister struct {
245221 podLister v1lister.PodLister
0 commit comments