Skip to content

Commit 6f2835d

Browse files
committed
Emit scale down metric even when there is no scale down candidates
Signed-off-by: Jack Francis <[email protected]>
1 parent 72f9592 commit 6f2835d

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

cluster-autoscaler/core/scaledown/status/status.go

+2
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ const (
100100
ScaleDownInCooldown
101101
// ScaleDownInProgress - the scale down wasn't attempted, because a previous scale-down was still in progress.
102102
ScaleDownInProgress
103+
// ScaleDownNoCandidates - the scale down was skipped because of no scale down candidates.
104+
ScaleDownNoCandidates
103105
)
104106

105107
// NodeDeleteResultType denotes the type of the result of node deletion. It provides deeper

cluster-autoscaler/core/static_autoscaler.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr
619619

620620
metrics.UpdateDurationFromStart(metrics.FindUnneeded, unneededStart)
621621

622-
scaleDownInCooldown := a.isScaleDownInCooldown(currentTime, scaleDownCandidates)
622+
scaleDownInCooldown := a.isScaleDownInCooldown(currentTime)
623623
klog.V(4).Infof("Scale down status: lastScaleUpTime=%s lastScaleDownDeleteTime=%v "+
624624
"lastScaleDownFailTime=%s scaleDownForbidden=%v scaleDownInCooldown=%v",
625625
a.lastScaleUpTime, a.lastScaleDownDeleteTime, a.lastScaleDownFailTime,
@@ -727,8 +727,8 @@ func (a *StaticAutoscaler) addUpcomingNodesToClusterSnapshot(upcomingCounts map[
727727
return nil
728728
}
729729

730-
func (a *StaticAutoscaler) isScaleDownInCooldown(currentTime time.Time, scaleDownCandidates []*apiv1.Node) bool {
731-
scaleDownInCooldown := a.processorCallbacks.disableScaleDownForLoop || len(scaleDownCandidates) == 0
730+
func (a *StaticAutoscaler) isScaleDownInCooldown(currentTime time.Time) bool {
731+
scaleDownInCooldown := a.processorCallbacks.disableScaleDownForLoop
732732

733733
if a.ScaleDownDelayTypeLocal {
734734
return scaleDownInCooldown

cluster-autoscaler/core/static_autoscaler_test.go

+14-7
Original file line numberDiff line numberDiff line change
@@ -2651,28 +2651,35 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
26512651
tests := []struct {
26522652
name string
26532653
testNodes []*apiv1.Node
2654-
expectedScaleDownCoolDown bool
2654+
scaleDownInCoolDown bool
26552655
expectedNodesWithSoftTaints []*apiv1.Node
26562656
expectedNodesWithNoSoftTaints []*apiv1.Node
26572657
}{
26582658
{
2659-
name: "Soft tainted nodes are cleaned in case of scale down is in cool down",
2659+
name: "Soft tainted nodes are cleaned when scale down skipped",
26602660
testNodes: nodesToHaveNoTaints,
2661-
expectedScaleDownCoolDown: true,
2661+
expectedScaleDownCoolDown: false,
2662+
expectedNodesWithSoftTaints: []*apiv1.Node{},
2663+
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
2664+
},
2665+
{
2666+
name: "Soft tainted nodes are cleaned when scale down in cooldown",
2667+
testNodes: nodesToHaveNoTaints,
2668+
scaleDownInCoolDown: true,
26622669
expectedNodesWithSoftTaints: []*apiv1.Node{},
26632670
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
26642671
},
26652672
{
26662673
name: "Soft tainted nodes are not cleaned in case of scale down isn't in cool down",
26672674
testNodes: nodesToHaveTaints,
2668-
expectedScaleDownCoolDown: false,
2675+
scaleDownInCoolDown: false,
26692676
expectedNodesWithSoftTaints: nodesToHaveTaints,
26702677
expectedNodesWithNoSoftTaints: []*apiv1.Node{},
26712678
},
26722679
{
26732680
name: "Soft tainted nodes are cleaned only from min sized node group in case of scale down isn't in cool down",
26742681
testNodes: append(nodesToHaveNoTaints, nodesToHaveTaints...),
2675-
expectedScaleDownCoolDown: false,
2682+
scaleDownInCoolDown: false,
26762683
expectedNodesWithSoftTaints: nodesToHaveTaints,
26772684
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
26782685
},
@@ -2683,12 +2690,12 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
26832690
fakeClient := buildFakeClient(t, test.testNodes...)
26842691

26852692
autoscaler := buildStaticAutoscaler(t, provider, test.testNodes, test.testNodes, fakeClient)
2693+
autoscaler.processorCallbacks.disableScaleDownForLoop = test.scaleDownInCoolDown
2694+
assert.Equal(t, autoscaler.isScaleDownInCooldown(time.Now()), test.scaleDownInCoolDown)
26862695

26872696
err := autoscaler.RunOnce(time.Now())
26882697

26892698
assert.NoError(t, err)
2690-
candidates, _ := autoscaler.processors.ScaleDownNodeProcessor.GetScaleDownCandidates(autoscaler.AutoscalingContext, test.testNodes)
2691-
assert.Equal(t, test.expectedScaleDownCoolDown, autoscaler.isScaleDownInCooldown(time.Now(), candidates))
26922699

26932700
assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithSoftTaints, true)
26942701
assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithNoSoftTaints, false)

0 commit comments

Comments
 (0)