Skip to content

Commit 3245e34

Browse files
committed
return struct
1 parent 51f4fe0 commit 3245e34

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

cluster-autoscaler/core/static_autoscaler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,12 +1162,12 @@ func listPods(podLister kube_util.PodLister, bypassedSchedulers map[string]bool)
11621162
klog.Errorf("Failed to list pods: %v", err)
11631163
return nil, nil, nil, err
11641164
}
1165-
scheduled, unschedulable, unprocessed = kube_util.FilterPodsBySchedulability(pods, bypassedSchedulers)
1165+
p := kube_util.ArrangePodsBySchedulability(pods, bypassedSchedulers)
11661166
// Skip logging in case of the boring scenario, when all pods are scheduled.
1167-
if len(pods) != len(scheduled) {
1168-
ignored := len(pods) - len(scheduled) - len(unschedulable) - len(unprocessed)
1167+
if len(pods) != len(p.Scheduled) {
1168+
ignored := len(pods) - len(p.Scheduled) - len(p.Unschedulable) - len(p.Unprocessed)
11691169
klog.Infof("Found %d pods in the cluster: %d scheduled, %d unschedulable, %d unprocessed by scheduler, %d ignored (most likely using custom scheduler)",
1170-
len(pods), len(scheduled), len(unschedulable), len(unprocessed), ignored)
1170+
len(pods), len(p.Scheduled), len(p.Unschedulable), len(p.Unprocessed), ignored)
11711171
}
11721172
return
11731173
}

cluster-autoscaler/utils/kubernetes/listers.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ type listerRegistryImpl struct {
5858
statefulSetLister v1appslister.StatefulSetLister
5959
}
6060

61+
// PodsBySchedulability is a struct that holds pods classified by their schedulability status.
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
6269
func 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 scheduled, unschedulable, or unprocessed pods the helper method FilterPodsBySchedulability should be used.
149+
// To filter out scheduled, unschedulable, or unprocessed pods the helper method ArrangePodsBySchedulability should be used.
143150
type PodLister interface {
144151
List() ([]*apiv1.Pod, error)
145152
}
@@ -168,28 +175,30 @@ func ScheduledPods(allPods []*apiv1.Pod) []*apiv1.Pod {
168175
return scheduledPods
169176
}
170177

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) {
178+
// ArrangePodsBySchedulability is a helper method that classifies pods by scheduled, unschedulable,
179+
// and not processed by a scheduler from given pod list.
180+
func ArrangePodsBySchedulability(allPods []*apiv1.Pod, bypassedSchedulers map[string]bool) PodsBySchedulability {
181+
var arranged PodsBySchedulability
173182
for _, pod := range allPods {
174183
if isScheduled(pod) {
175-
scheduled = append(scheduled, pod)
184+
arranged.Scheduled = append(arranged.Scheduled, pod)
176185
continue
177186
} else if isDeleted(pod) {
178187
continue
179188
} else {
180189
_, condition := podv1.GetPodCondition(&pod.Status, apiv1.PodScheduled)
181190
if !(condition == nil || condition.Status != apiv1.ConditionFalse || condition.Reason != apiv1.PodReasonUnschedulable) {
182-
unschedulable = append(unschedulable, pod)
191+
arranged.Unschedulable = append(arranged.Unschedulable, pod)
183192
} else {
184193
if canBypass := bypassedSchedulers[pod.Spec.SchedulerName]; canBypass {
185194
if condition == nil || (condition.Status == apiv1.ConditionFalse && condition.Reason == "") {
186-
unprocessed = append(unprocessed, pod)
195+
arranged.Unprocessed = append(arranged.Unprocessed, pod)
187196
}
188197
}
189198
}
190199
}
191200
}
192-
return scheduled, unschedulable, unprocessed
201+
return arranged
193202
}
194203

195204
// SchedulingGatedPods is a helper method that returns all pods which has scheduling gate

0 commit comments

Comments
 (0)