Skip to content

Commit e8d5d0d

Browse files
committed
Emit scale down metric even when there is no scale down candidates
1 parent 03b6ee8 commit e8d5d0d

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr
626626

627627
metrics.UpdateDurationFromStart(metrics.FindUnneeded, unneededStart)
628628

629-
scaleDownInCooldown := a.isScaleDownInCooldown(currentTime, scaleDownCandidates)
629+
scaleDownInCooldown := a.isScaleDownInCooldown(currentTime)
630630
klog.V(4).Infof("Scale down status: lastScaleUpTime=%s lastScaleDownDeleteTime=%v "+
631631
"lastScaleDownFailTime=%s scaleDownForbidden=%v scaleDownInCooldown=%v",
632632
a.lastScaleUpTime, a.lastScaleDownDeleteTime, a.lastScaleDownFailTime,
@@ -703,8 +703,8 @@ func (a *StaticAutoscaler) updateSoftDeletionTaints(allNodes []*apiv1.Node) {
703703
}
704704
}
705705

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

709709
if a.ScaleDownDelayTypeLocal {
710710
return scaleDownInCooldown

cluster-autoscaler/core/static_autoscaler_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,28 +2599,35 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
25992599
tests := []struct {
26002600
name string
26012601
testNodes []*apiv1.Node
2602-
expectedScaleDownCoolDown bool
2602+
scaleDownInCoolDown bool
26032603
expectedNodesWithSoftTaints []*apiv1.Node
26042604
expectedNodesWithNoSoftTaints []*apiv1.Node
26052605
}{
26062606
{
2607-
name: "Soft tainted nodes are cleaned in case of scale down is in cool down",
2607+
name: "Soft tainted nodes are cleaned when scale down skipped",
26082608
testNodes: nodesToHaveNoTaints,
2609-
expectedScaleDownCoolDown: true,
2609+
scaleDownInCoolDown: false,
26102610
expectedNodesWithSoftTaints: []*apiv1.Node{},
26112611
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
26122612
},
26132613
{
2614-
name: "Soft tainted nodes are not cleaned in case of scale down isn't in cool down",
2614+
name: "Soft tainted nodes are cleaned when scale down in cooldown",
2615+
testNodes: nodesToHaveNoTaints,
2616+
scaleDownInCoolDown: true,
2617+
expectedNodesWithSoftTaints: []*apiv1.Node{},
2618+
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
2619+
},
2620+
{
2621+
name: "Soft tainted nodes are not cleaned when scale down requested",
26152622
testNodes: nodesToHaveTaints,
2616-
expectedScaleDownCoolDown: false,
2623+
scaleDownInCoolDown: false,
26172624
expectedNodesWithSoftTaints: nodesToHaveTaints,
26182625
expectedNodesWithNoSoftTaints: []*apiv1.Node{},
26192626
},
26202627
{
2621-
name: "Soft tainted nodes are cleaned only from min sized node group in case of scale down isn't in cool down",
2628+
name: "Soft tainted nodes are cleaned only from min sized node group when scale down requested",
26222629
testNodes: append(nodesToHaveNoTaints, nodesToHaveTaints...),
2623-
expectedScaleDownCoolDown: false,
2630+
scaleDownInCoolDown: false,
26242631
expectedNodesWithSoftTaints: nodesToHaveTaints,
26252632
expectedNodesWithNoSoftTaints: nodesToHaveNoTaints,
26262633
},
@@ -2631,12 +2638,12 @@ func TestCleaningSoftTaintsInScaleDown(t *testing.T) {
26312638
fakeClient := buildFakeClient(t, test.testNodes...)
26322639

26332640
autoscaler := buildStaticAutoscaler(t, provider, test.testNodes, test.testNodes, fakeClient)
2641+
autoscaler.processorCallbacks.disableScaleDownForLoop = test.scaleDownInCoolDown
2642+
assert.Equal(t, autoscaler.isScaleDownInCooldown(time.Now()), test.scaleDownInCoolDown)
26342643

26352644
err := autoscaler.RunOnce(time.Now())
26362645

26372646
assert.NoError(t, err)
2638-
candidates, _ := autoscaler.processors.ScaleDownNodeProcessor.GetScaleDownCandidates(autoscaler.AutoscalingContext, test.testNodes)
2639-
assert.Equal(t, test.expectedScaleDownCoolDown, autoscaler.isScaleDownInCooldown(time.Now(), candidates))
26402647

26412648
assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithSoftTaints, true)
26422649
assertNodesSoftTaintsStatus(t, fakeClient, test.expectedNodesWithNoSoftTaints, false)

0 commit comments

Comments
 (0)