diff --git a/cluster-autoscaler/core/scaledown/status/status.go b/cluster-autoscaler/core/scaledown/status/status.go index 65df001a6778..9361d88e4dc7 100644 --- a/cluster-autoscaler/core/scaledown/status/status.go +++ b/cluster-autoscaler/core/scaledown/status/status.go @@ -98,6 +98,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 acf2c806ed78..e3dff2092ad9 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -606,7 +606,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, @@ -628,6 +628,11 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr if scaleDownInCooldown { scaleDownStatus.Result = scaledownstatus.ScaleDownInCooldown a.updateSoftDeletionTaints(allNodes) + } else if len(scaleDownCandidates) == 0 { + klog.V(4).Infof("Starting scale down: no scale down candidates. skipping...") + scaleDownStatus.Result = scaledownstatus.ScaleDownNoCandidates + metrics.UpdateLastTime(metrics.ScaleDown, time.Now()) + a.updateSoftDeletionTaints(allNodes) } else { klog.V(4).Infof("Starting scale down") @@ -712,8 +717,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