From f6a38be048c66c3251c25fe485d084d92e2be496 Mon Sep 17 00:00:00 2001 From: shubham82 Date: Mon, 5 Feb 2024 17:08:26 +0530 Subject: [PATCH] Backport #5901 [CA] Remove unneeded node groups regardless of scale down being in cooldown into CA1.27 --- cluster-autoscaler/core/static_autoscaler.go | 28 +++++++++++--------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 3499bd6f863f..e86c6a2fc870 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -626,23 +626,27 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr a.processorCallbacks.disableScaleDownForLoop, scaleDownInCooldown) metrics.UpdateScaleDownInCooldown(scaleDownInCooldown) + // We want to delete unneeded Node Groups only if here is no current delete + // in progress. + _, drained := scaleDownActuationStatus.DeletionsInProgress() + var removedNodeGroups []cloudprovider.NodeGroup + if len(drained) == 0 { + var err error + removedNodeGroups, err = a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext) + if err != nil { + klog.Errorf("Error while removing unneeded node groups: %v", err) + } + scaleDownStatus.RemovedNodeGroups = removedNodeGroups + } + if scaleDownInCooldown { scaleDownStatus.Result = scaledownstatus.ScaleDownInCooldown + if len(removedNodeGroups) > 0 { + a.processors.ScaleDownStatusProcessor.Process(autoscalingContext, scaleDownStatus) + } } else { klog.V(4).Infof("Starting scale down") - // We want to delete unneeded Node Groups only if there was no recent scale up, - // and there is no current delete in progress and there was no recent errors. - _, drained := actuationStatus.DeletionsInProgress() - var removedNodeGroups []cloudprovider.NodeGroup - if len(drained) == 0 { - var err error - removedNodeGroups, err = a.processors.NodeGroupManager.RemoveUnneededNodeGroups(autoscalingContext) - if err != nil { - klog.Errorf("Error while removing unneeded node groups: %v", err) - } - } - scaleDownStart := time.Now() metrics.UpdateLastTime(metrics.ScaleDown, scaleDownStart) empty, needDrain := a.scaleDownPlanner.NodesToDelete(currentTime)