From 2bbe859154d6978f8bb94247e63b86f4068bda0d Mon Sep 17 00:00:00 2001 From: Omran Date: Thu, 20 Mar 2025 05:34:25 +0000 Subject: [PATCH] Fix cool down status condition to trigger scale down --- cluster-autoscaler/core/static_autoscaler.go | 32 +++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/cluster-autoscaler/core/static_autoscaler.go b/cluster-autoscaler/core/static_autoscaler.go index 6899260238..6188e1c669 100644 --- a/cluster-autoscaler/core/static_autoscaler.go +++ b/cluster-autoscaler/core/static_autoscaler.go @@ -627,6 +627,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr if scaleDownInCooldown { scaleDownStatus.Result = scaledownstatus.ScaleDownInCooldown + a.updateSoftDeletionTaints(allNodes) } else { klog.V(4).Infof("Starting scale down") @@ -645,21 +646,7 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr a.lastScaleDownDeleteTime = currentTime a.clusterStateRegistry.Recalculate() } - - if scaleDownStatus.Result == scaledownstatus.ScaleDownNoNodeDeleted && - a.AutoscalingContext.AutoscalingOptions.MaxBulkSoftTaintCount != 0 { - taintableNodes := a.scaleDownPlanner.UnneededNodes() - - // Make sure we are only cleaning taints from selected node groups. - selectedNodes := filterNodesFromSelectedGroups(a.CloudProvider, allNodes...) - - // This is a sanity check to make sure `taintableNodes` only includes - // nodes from selected nodes. - taintableNodes = intersectNodes(selectedNodes, taintableNodes) - untaintableNodes := subtractNodes(selectedNodes, taintableNodes) - actuation.UpdateSoftDeletionTaints(a.AutoscalingContext, taintableNodes, untaintableNodes) - } - + a.updateSoftDeletionTaints(allNodes) if typedErr != nil { klog.Errorf("Failed to scale down: %v", typedErr) a.lastScaleDownFailTime = currentTime @@ -679,6 +666,21 @@ func (a *StaticAutoscaler) RunOnce(currentTime time.Time) caerrors.AutoscalerErr return nil } +func (a *StaticAutoscaler) updateSoftDeletionTaints(allNodes []*apiv1.Node) { + if a.AutoscalingContext.AutoscalingOptions.MaxBulkSoftTaintCount != 0 { + taintableNodes := a.scaleDownPlanner.UnneededNodes() + + // Make sure we are only cleaning taints from selected node groups. + selectedNodes := filterNodesFromSelectedGroups(a.CloudProvider, allNodes...) + + // This is a sanity check to make sure `taintableNodes` only includes + // nodes from selected nodes. + taintableNodes = intersectNodes(selectedNodes, taintableNodes) + untaintableNodes := subtractNodes(selectedNodes, taintableNodes) + actuation.UpdateSoftDeletionTaints(a.AutoscalingContext, taintableNodes, untaintableNodes) + } +} + func (a *StaticAutoscaler) addUpcomingNodesToClusterSnapshot(upcomingCounts map[string]int, nodeInfosForGroups map[string]*framework.NodeInfo) error { nodeGroups := a.nodeGroupsById() upcomingNodeGroups := make(map[string]int)