Simplify PodListProcessor interface

This commit is contained in:
Łukasz Osipiuk 2020-01-16 17:43:54 +01:00
parent 014eff3ec8
commit d9891ae3ad
4 changed files with 17 additions and 30 deletions

View File

@ -42,9 +42,7 @@ func NewFilterOutSchedulablePodListProcessor() pods.PodListProcessor {
// Process filters out pods which are schedulable from list of unschedulable pods. // Process filters out pods which are schedulable from list of unschedulable pods.
func (filterOutSchedulablePodListProcessor) Process( func (filterOutSchedulablePodListProcessor) Process(
context *context.AutoscalingContext, context *context.AutoscalingContext,
unschedulablePods []*apiv1.Pod, allScheduledPods []*apiv1.Pod, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) {
allNodes []*apiv1.Node, readyNodes []*apiv1.Node,
upcomingNodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) {
// We need to check whether pods marked as unschedulable are actually unschedulable. // 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 // It's likely we added a new node and the scheduler just haven't managed to put the
// pod on in yet. In this situation we don't want to trigger another scale-up. // pod on in yet. In this situation we don't want to trigger another scale-up.
@ -69,7 +67,7 @@ func (filterOutSchedulablePodListProcessor) Process(
context.PredicateChecker, context.ExpendablePodsPriorityCutoff) context.PredicateChecker, context.ExpendablePodsPriorityCutoff)
if err != nil { if err != nil {
return nil, nil, err return nil, err
} }
metrics.UpdateDurationFromStart(metrics.FilterOutSchedulable, filterOutSchedulableStart) metrics.UpdateDurationFromStart(metrics.FilterOutSchedulable, filterOutSchedulableStart)
@ -80,7 +78,7 @@ func (filterOutSchedulablePodListProcessor) Process(
} else { } else {
klog.V(4).Info("No schedulable pods") klog.V(4).Info("No schedulable pods")
} }
return unschedulablePodsToHelp, allScheduledPods, nil return unschedulablePodsToHelp, nil
} }
func (filterOutSchedulablePodListProcessor) CleanUp() { func (filterOutSchedulablePodListProcessor) CleanUp() {

View File

@ -380,9 +380,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) errors.AutoscalerError
} }
} }
unschedulablePodsToHelp, scheduledPods, _ := a.processors.PodListProcessor.Process( unschedulablePodsToHelp, _ := a.processors.PodListProcessor.Process(a.AutoscalingContext, unschedulablePods)
a.AutoscalingContext, unschedulablePods, scheduledPods, allNodes, readyNodes,
upcomingNodes)
// finally, filter out pods that are too "young" to safely be considered for a scale-up (delay is configurable) // finally, filter out pods that are too "young" to safely be considered for a scale-up (delay is configurable)
unschedulablePodsToHelp = a.filterOutYoungPods(unschedulablePodsToHelp, currentTime) unschedulablePodsToHelp = a.filterOutYoungPods(unschedulablePodsToHelp, currentTime)

View File

@ -21,12 +21,11 @@ import (
"k8s.io/autoscaler/cluster-autoscaler/context" "k8s.io/autoscaler/cluster-autoscaler/context"
) )
// PodListProcessor processes lists of unschedulable and scheduled pods before scaling of the cluster. // PodListProcessor processes lists of unschedulable pods.
type PodListProcessor interface { type PodListProcessor interface {
Process(context *context.AutoscalingContext, Process(
unschedulablePods []*apiv1.Pod, allScheduledPods []*apiv1.Pod, context *context.AutoscalingContext,
allNodes []*apiv1.Node, readyNodes []*apiv1.Node, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error)
upcomingNodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error)
CleanUp() CleanUp()
} }
@ -40,11 +39,10 @@ func NewDefaultPodListProcessor() PodListProcessor {
} }
// Process processes lists of unschedulable and scheduled pods before scaling of the cluster. // Process processes lists of unschedulable and scheduled pods before scaling of the cluster.
func (p *NoOpPodListProcessor) Process(context *context.AutoscalingContext, func (p *NoOpPodListProcessor) Process(
unschedulablePods []*apiv1.Pod, allScheduledPods []*apiv1.Pod, context *context.AutoscalingContext,
allNodes []*apiv1.Node, readyNodes []*apiv1.Node, unschedulablePods []*apiv1.Pod) ([]*apiv1.Pod, error) {
upcomingNodes []*apiv1.Node) ([]*apiv1.Pod, []*apiv1.Pod, error) { return unschedulablePods, nil
return unschedulablePods, allScheduledPods, nil
} }
// CleanUp cleans up the processor's internal structures. // CleanUp cleans up the processor's internal structures.

View File

@ -25,21 +25,14 @@ import (
. "k8s.io/autoscaler/cluster-autoscaler/utils/test" . "k8s.io/autoscaler/cluster-autoscaler/utils/test"
) )
func TestPodListProcessor(t *testing.T) { func TestDefaultUnschedulablePodListProcessor(t *testing.T) {
context := &context.AutoscalingContext{} context := &context.AutoscalingContext{}
p1 := BuildTestPod("p1", 40, 0) p1 := BuildTestPod("p1", 40, 0)
p2 := BuildTestPod("p2", 400, 0)
n1 := BuildTestNode("n1", 100, 1000)
n2 := BuildTestNode("n1", 100, 1000)
unschedulablePods := []*apiv1.Pod{p1} unschedulablePods := []*apiv1.Pod{p1}
allScheduledPods := []*apiv1.Pod{p2}
allNodes := []*apiv1.Node{n1, n2}
readyNodes := []*apiv1.Node{n1, n2}
podListProcessor := NewDefaultPodListProcessor() podListProcessor := NewDefaultPodListProcessor()
gotUnschedulablePods, gotAllScheduled, err := podListProcessor.Process(context, unschedulablePods, allScheduledPods, allNodes, readyNodes, []*apiv1.Node{}) gotUnschedulablePods, err := podListProcessor.Process(context, unschedulablePods)
if len(gotUnschedulablePods) != 1 || len(gotAllScheduled) != 1 || err != nil { if len(gotUnschedulablePods) != 1 || err != nil {
t.Errorf("Error podListProcessor.Process() = %v, %v, %v want %v, %v, nil ", t.Errorf("Error podListProcessor.Process() = %v,%v want %v, nil ",
gotUnschedulablePods, gotAllScheduled, err, unschedulablePods, allScheduledPods) gotUnschedulablePods, err, unschedulablePods)
} }
} }