@@ -58,6 +58,13 @@ type listerRegistryImpl struct {
5858 statefulSetLister v1appslister.StatefulSetLister
5959}
6060
61+ // PodsBySchedulability arranges pods by their schedulability
62+ type PodsBySchedulability struct {
63+ Scheduled []* apiv1.Pod
64+ Unschedulable []* apiv1.Pod
65+ Unprocessed []* apiv1.Pod
66+ }
67+
6168// NewListerRegistry returns a registry providing various listers to list pods or nodes matching conditions
6269func NewListerRegistry (allNode NodeLister , readyNode NodeLister , allPodLister PodLister , podDisruptionBudgetLister PodDisruptionBudgetLister ,
6370 daemonSetLister v1appslister.DaemonSetLister , replicationControllerLister v1lister.ReplicationControllerLister ,
@@ -139,7 +146,7 @@ func (r listerRegistryImpl) StatefulSetLister() v1appslister.StatefulSetLister {
139146}
140147
141148// PodLister lists all pods.
142- // To filter out the scheduled or unschedulable pods the helper methods ScheduledPods and UnschedulablePods should be used.
149+ // To filter out scheduled, unschedulable, or unprocessed pods the helper method ArrangePodsBySchedulability should be used.
143150type PodLister interface {
144151 List () ([]* apiv1.Pod , error )
145152}
@@ -156,19 +163,6 @@ func isDeleted(pod *apiv1.Pod) bool {
156163 return pod .GetDeletionTimestamp () != nil
157164}
158165
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-
172166// ScheduledPods is a helper method that returns all scheduled pods from given pod list.
173167func ScheduledPods (allPods []* apiv1.Pod ) []* apiv1.Pod {
174168 var scheduledPods []* apiv1.Pod
@@ -181,27 +175,29 @@ func ScheduledPods(allPods []*apiv1.Pod) []*apiv1.Pod {
181175 return scheduledPods
182176}
183177
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-
178+ // ArrangePodsBySchedulability is a helper method that arranges pods by schedulability:
179+ // scheduled, unschedulable, and unprocessed by any any bypassed schedulers.
180+ func ArrangePodsBySchedulability (allPods []* apiv1.Pod , bypassedSchedulers map [string ]bool ) (podsBySchedulability PodsBySchedulability ) {
188181 for _ , pod := range allPods {
189- if canBypass := bypassedSchedulers [pod .Spec .SchedulerName ]; ! canBypass {
182+ if isScheduled (pod ) {
183+ podsBySchedulability .Scheduled = append (podsBySchedulability .Scheduled , pod )
190184 continue
191- }
192- // Make sure it's not scheduled or deleted
193- if isScheduled (pod ) || isDeleted (pod ) || isUnschedulable (pod ) {
185+ } else if isDeleted (pod ) {
194186 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 )
187+ } else {
188+ _ , condition := podv1 .GetPodCondition (& pod .Status , apiv1 .PodScheduled )
189+ if condition != nil && condition .Status == apiv1 .ConditionFalse && condition .Reason == apiv1 .PodReasonUnschedulable {
190+ podsBySchedulability .Unschedulable = append (podsBySchedulability .Unschedulable , pod )
191+ } else {
192+ if canBypass := bypassedSchedulers [pod .Spec .SchedulerName ]; canBypass {
193+ if condition == nil || (condition .Status == apiv1 .ConditionFalse && condition .Reason == "" ) {
194+ podsBySchedulability .Unprocessed = append (podsBySchedulability .Unprocessed , pod )
195+ }
196+ }
197+ }
202198 }
203199 }
204- return unprocessedPods
200+ return
205201}
206202
207203// SchedulingGatedPods is a helper method that returns all pods which has scheduling gate
@@ -228,18 +224,6 @@ func isSchedulingGated(pod *apiv1.Pod) bool {
228224 return false
229225}
230226
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-
243227// AllPodLister lists all pods.
244228type AllPodLister struct {
245229 podLister v1lister.PodLister
0 commit comments