diff --git a/cluster-autoscaler/core/scaledown/status/status.go b/cluster-autoscaler/core/scaledown/status/status.go index deb7b21103bae3defae258cc2e9a2e081f1e1f36..3217edffccd4a1f80b2633bd384dc7a704bb603e 100644 --- a/cluster-autoscaler/core/scaledown/status/status.go +++ b/cluster-autoscaler/core/scaledown/status/status.go @@ -100,6 +100,8 @@ const ( ScaleDownInCooldown // ScaleDownInProgress - the scale down wasn't attempted, because a previous scale-down was still in progress. ScaleDownInProgress + // ScaleDownNoCandidates - the scale down was skipped because of no scale down candidates. + ScaleDownNoCandidates ) // NodeDeleteResultType denotes the type of the result of node deletion. It provides deeper diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 0df78c9630249355c386cdef648dbee04cc4182e..d86994bbaa16d6fdb942224c4dbdd3bc343c84a7 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -619,7 +619,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr metrics.UpdateDurationFromStart(metrics.FindUnneeded, unneededStart) - scaleDownInCooldown := a.isScaleDownInCooldown(currentTime, scaleDownCandidates) + scaleDownInCooldown := a.isScaleDownInCooldown(currentTime) klog.V(4).Infof("Scale down status: lastScaleUpTime=%s lastScaleDownDeleteTime=%v "+ "lastScaleDownFailTime=%s scaleDownForbidden=%v scaleDownInCooldown=%v", a.lastScaleUpTime, a.lastScaleDownDeleteTime, a.lastScaleDownFailTime, @@ -727,8 +727,8 @@ func (a *StaticAutoscaler) addUpcomingNodesToClusterSnapshot(upcomingCounts map[ return nil } -func (a *StaticAutoscaler) isScaleDownInCooldown(currentTime time.Time, scaleDownCandidates []*apiv1.Node) bool { - scaleDownInCooldown := a.processorCallbacks.disableScaleDownForLoop || len(scaleDownCandidates) == 0 +func (a *StaticAutoscaler) isScaleDownInCooldown(currentTime time.Time) bool { + scaleDownInCooldown := a.processorCallbacks.disableScaleDownForLoop if a.ScaleDownDelayTypeLocal { return scaleDownInCooldown diff --git a/cluster-autoscaler/core/static_autoscaler_test.go b/cluster-autoscaler/core/static_autoscaler_test.go index 9ff99d2907d13d3ee00623701d9dc00aa99cbc7c..eac4bc4e24372be83e2649e751fddfcf02ed3378 100644 --- a/cluster-autoscaler/core/static_autoscaler_test.go +++ b/cluster-autoscaler/core/static_autoscaler_test.go @@ -2651,28 +2651,35 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) { tests := []struct { name string testNodes []*apiv1.Node - expectedScaleDownCoolDown bool + scaleDownInCoolDown bool expectedNodesWithSoftTaints []*apiv1.Node expectedNodesWithNoSoftTaints []*apiv1.Node }{ { - name: "Soft tainted nodes are cleaned in case of scale down is in cool down", + name: "Soft tainted nodes are cleaned when scale down skipped", testNodes: nodesToHaveNoTaints, - expectedScaleDownCoolDown: true, + scaleDownInCoolDown: false, expectedNodesWithSoftTaints: []*apiv1.Node{}, expectedNodesWithNoSoftTaints: nodesToHaveNoTaints, }, { - name: "Soft tainted nodes are not cleaned in case of scale down isn't in cool down", + name: "Soft tainted nodes are cleaned when scale down in cooldown", + testNodes: nodesToHaveNoTaints, + scaleDownInCoolDown: true, + expectedNodesWithSoftTaints: []*apiv1.Node{}, + expectedNodesWithNoSoftTaints: nodesToHaveNoTaints, + }, + { + name: "Soft tainted nodes are not cleaned when scale down requested", testNodes: nodesToHaveTaints, - expectedScaleDownCoolDown: false, + scaleDownInCoolDown: false, expectedNodesWithSoftTaints: nodesToHaveTaints, expectedNodesWithNoSoftTaints: []*apiv1.Node{}, }, { - name: "Soft tainted nodes are cleaned only from min sized node group in case of scale down isn't in cool down", + name: "Soft tainted nodes are cleaned only from min sized node group when scale down requested", testNodes: append(nodesToHaveNoTaints, nodesToHaveTaints...), - expectedScaleDownCoolDown: false, + scaleDownInCoolDown: false, expectedNodesWithSoftTaints: nodesToHaveTaints, expectedNodesWithNoSoftTaints: nodesToHaveNoTaints, }, @@ -2683,12 +2690,12 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) { fakeClient := buildFakeClient(t, test.testNodes...) autoscaler := buildStaticAutoscaler(t, provider, test.testNodes, test.testNodes, fakeClient) + autoscaler.processorCallbacks.disableScaleDownForLoop = test.scaleDownInCoolDown + assert.Equal(t, autoscaler.isScaleDownInCooldown(time.Now()), test.scaleDownInCoolDown) err := autoscaler.RunOnce(time.Now()) assert.NoError(t, err) - candidates, _ := autoscaler.processors.ScaleDownNodeProcessor.GetScaleDownCandidates(autoscaler.AutoscalingContext, test.testNodes) - assert.Equal(t, test.expectedScaleDownCoolDown, autoscaler.isScaleDownInCooldown(time.Now(), candidates)) assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithSoftTaints, true) assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithNoSoftTaints, false)