From 5c09c5077431565343d6253834fec2bf5fde6805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Osipiuk?= Date: Wed, 10 Apr 2019 22:01:12 +0200 Subject: [PATCH] Pass ready nodes list to PodListProcessor --- cluster-autoscaler/core/static_autoscaler.go | 14 +++++++------- .../processors/pods/pod_list_processor.go | 10 +++++++--- .../processors/pods/pod_list_processor_test.go | 9 +++++---- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index fe1557f706..2521d240f3 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -276,19 +276,19 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError } metrics.UpdateUnschedulablePodsCount(len(allUnschedulablePods)) - allScheduled, err := scheduledPodLister.List() + allScheduledPods, err := scheduledPodLister.List() if err != nil { klog.Errorf("Failed to list scheduled pods: %v", err) return errors.ToAutoscalerError(errors.ApiCallError, err) } - allUnschedulablePods, allScheduled, err = a.processors.PodListProcessor.Process(a.AutoscalingContext, allUnschedulablePods, allScheduled, allNodes) + allUnschedulablePods, allScheduledPods, err = a.processors.PodListProcessor.Process(a.AutoscalingContext, allUnschedulablePods, allScheduledPods, allNodes, readyNodes) if err != nil { klog.Errorf("Failed to process pod list: %v", err) return errors.ToAutoscalerError(errors.InternalError, err) } - ConfigurePredicateCheckerForLoop(allUnschedulablePods, allScheduled, a.PredicateChecker) + ConfigurePredicateCheckerForLoop(allUnschedulablePods, allScheduledPods, a.PredicateChecker) // We need to check whether pods marked as unschedulable are actually unschedulable. // It's likely we added a new node and the scheduler just haven't managed to put the @@ -317,10 +317,10 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError filterOutSchedulableStart := time.Now() var unschedulablePodsToHelp []*apiv1.Pod if a.FilterOutSchedulablePodsUsesPacking { - unschedulablePodsToHelp = filterOutSchedulableByPacking(unschedulablePods, readyNodes, allScheduled, + unschedulablePodsToHelp = filterOutSchedulableByPacking(unschedulablePods, readyNodes, allScheduledPods, unschedulableWaitingForLowerPriorityPreemption, a.PredicateChecker, a.ExpendablePodsPriorityCutoff) } else { - unschedulablePodsToHelp = filterOutSchedulableSimple(unschedulablePods, readyNodes, allScheduled, + unschedulablePodsToHelp = filterOutSchedulableSimple(unschedulablePods, readyNodes, allScheduledPods, unschedulableWaitingForLowerPriorityPreemption, a.PredicateChecker, a.ExpendablePodsPriorityCutoff) } @@ -390,7 +390,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError scaleDown.CleanUp(currentTime) potentiallyUnneeded := getPotentiallyUnneededNodes(autoscalingContext, allNodes) - typedErr := scaleDown.UpdateUnneededNodes(allNodes, potentiallyUnneeded, append(allScheduled, unschedulableWaitingForLowerPriorityPreemption...), currentTime, pdbs) + typedErr := scaleDown.UpdateUnneededNodes(allNodes, potentiallyUnneeded, append(allScheduledPods, unschedulableWaitingForLowerPriorityPreemption...), currentTime, pdbs) if typedErr != nil { scaleDownStatus.Result = status.ScaleDownError klog.Errorf("Failed to scale down: %v", typedErr) @@ -431,7 +431,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError scaleDownStart := time.Now() metrics.UpdateLastTime(metrics.ScaleDown, scaleDownStart) - scaleDownStatus, typedErr := scaleDown.TryToScaleDown(allNodes, allScheduled, pdbs, currentTime) + scaleDownStatus, typedErr := scaleDown.TryToScaleDown(allNodes, allScheduledPods, pdbs, currentTime) metrics.UpdateDurationFromStart(metrics.ScaleDown, scaleDownStart) if scaleDownStatus.Result == status.ScaleDownNodeDeleted { diff --git a/cluster-autoscaler/processors/pods/pod_list_processor.go b/cluster-autoscaler/processors/pods/pod_list_processor.go index 5391ded6f8..6800e26ee6 100644 --- a/cluster-autoscaler/processors/pods/pod_list_processor.go +++ b/cluster-autoscaler/processors/pods/pod_list_processor.go @@ -23,7 +23,9 @@ import ( // PodListProcessor processes lists of unschedulable and scheduled pods before scaling of the cluster. type PodListProcessor interface { - Process(context *context.AutoscalingContext, unschedulablePods []*apiv1.Pod, allScheduled []*apiv1.Pod, nodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) + Process(context *context.AutoscalingContext, + unschedulablePods []*apiv1.Pod, allScheduledPods []*apiv1.Pod, + allNodes []*apiv1.Node, readyNodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) CleanUp() } @@ -37,8 +39,10 @@ func NewDefaultPodListProcessor() PodListProcessor { } // Process processes lists of unschedulable and scheduled pods before scaling of the cluster. -func (p *NoOpPodListProcessor) Process(context *context.AutoscalingContext, unschedulablePods []*apiv1.Pod, allScheduled []*apiv1.Pod, nodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) { - return unschedulablePods, allScheduled, nil +func (p *NoOpPodListProcessor) Process(context *context.AutoscalingContext, + unschedulablePods []*apiv1.Pod, allScheduledPods []*apiv1.Pod, + allNodes []*apiv1.Node, readyNodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) { + return unschedulablePods, allScheduledPods, nil } // CleanUp cleans up the processor's internal structures. diff --git a/cluster-autoscaler/processors/pods/pod_list_processor_test.go b/cluster-autoscaler/processors/pods/pod_list_processor_test.go index 76b29aafd6..c1aa2d3195 100644 --- a/cluster-autoscaler/processors/pods/pod_list_processor_test.go +++ b/cluster-autoscaler/processors/pods/pod_list_processor_test.go @@ -32,13 +32,14 @@ func TestPodListProcessor(t *testing.T) { n1 := BuildTestNode("n1", 100, 1000) n2 := BuildTestNode("n1", 100, 1000) unschedulablePods := []*apiv1.Pod{p1} - allScheduled := []*apiv1.Pod{p2} - nodes := []*apiv1.Node{n1, n2} + allScheduledPods := []*apiv1.Pod{p2} + allNodes := []*apiv1.Node{n1, n2} + readyNodes := []*apiv1.Node{n1, n2} podListProcessor := NewDefaultPodListProcessor() - gotUnschedulablePods, gotAllScheduled, err := podListProcessor.Process(context, unschedulablePods, allScheduled, nodes) + gotUnschedulablePods, gotAllScheduled, err := podListProcessor.Process(context, unschedulablePods, allScheduledPods, allNodes, readyNodes) if len(gotUnschedulablePods) != 1 || len(gotAllScheduled) != 1 || err != nil { t.Errorf("Error podListProcessor.Process() = %v, %v, %v want %v, %v, nil ", - gotUnschedulablePods, gotAllScheduled, err, unschedulablePods, allScheduled) + gotUnschedulablePods, gotAllScheduled, err, unschedulablePods, allScheduledPods) } }