diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 365bc8526f96..1bc5376cdc65 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -499,7 +499,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr return scaleUpStart } - postScaleUp := func(scaleUpStart time.Time) (bool, caerrors.AutoscalerError) { + postScaleUp := func(scaleUpStart time.Time) { metrics.UpdateDurationFromStart(metrics.ScaleUp, scaleUpStart) if a.processors != nil && a.processors.ScaleUpStatusProcessor != nil { @@ -509,15 +509,13 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr if typedErr != nil { klog.Errorf("Failed to scale up: %v", typedErr) - return true, typedErr + return } if scaleUpStatus.Result == status.ScaleUpSuccessful { a.lastScaleUpTime = currentTime // No scale down in this iteration. scaleDownStatus.Result = scaledownstatus.ScaleDownInCooldown - return true, nil } - return false, nil } shouldScaleUp := true @@ -557,9 +555,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr if shouldScaleUp || a.processors.ScaleUpEnforcer.ShouldForceScaleUp(unschedulablePodsToHelp) { scaleUpStart := preScaleUp() scaleUpStatus, typedErr = a.scaleUpOrchestrator.ScaleUp(unschedulablePodsToHelp, readyNodes, daemonsets, nodeInfosForGroups, false) - if exit, err := postScaleUp(scaleUpStart); exit { - return err - } + postScaleUp(scaleUpStart) } if a.ScaleDownEnabled { @@ -664,9 +660,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr if a.EnforceNodeGroupMinSize { scaleUpStart := preScaleUp() scaleUpStatus, typedErr = a.scaleUpOrchestrator.ScaleUpToNodeGroupMinSize(readyNodes, nodeInfosForGroups) - if exit, err := postScaleUp(scaleUpStart); exit { - return err - } + postScaleUp(scaleUpStart) } return nil diff --git a/cluster-autoscaler/core/static_autoscaler_test.go b/cluster-autoscaler/core/static_autoscaler_test.go index 27f2aa89f274..58bd01eb5c0a 100644 --- a/cluster-autoscaler/core/static_autoscaler_test.go +++ b/cluster-autoscaler/core/static_autoscaler_test.go @@ -847,6 +847,7 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) { daemonSetListerMock.On("List", labels.Everything()).Return([]*appsv1.DaemonSet{}, nil).Once() onNodeGroupCreateMock.On("Create", "autoprovisioned-TN2").Return(nil).Once() onScaleUpMock.On("ScaleUp", "autoprovisioned-TN2", 1).Return(nil).Once() + onNodeGroupDeleteMock.On("Delete", "autoprovisioned-TN1").Return(nil).Once() err = autoscaler.RunOnce(time.Now().Add(time.Hour)) assert.NoError(t, err) @@ -878,8 +879,7 @@ func TestStaticAutoscalerRunOnceWithAutoprovisionedEnabled(t *testing.T) { allPodListerMock.On("List").Return([]*apiv1.Pod{p1}, nil).Twice() podDisruptionBudgetListerMock.On("List").Return([]*policyv1.PodDisruptionBudget{}, nil).Once() daemonSetListerMock.On("List", labels.Everything()).Return([]*appsv1.DaemonSet{}, nil).Once() - onNodeGroupDeleteMock.On("Delete", "autoprovisioned-"+ - "TN1").Return(nil).Once() + onNodeGroupDeleteMock.On("Delete", "autoprovisioned-TN1").Return(nil).Once() onScaleDownMock.On("ScaleDown", "autoprovisioned-TN2", "n2").Return(nil).Once() err = autoscaler.RunOnce(time.Now().Add(2 * time.Hour))