From 1e4507819a99286c54f5a0d55a55e3f0f78cf84a Mon Sep 17 00:00:00 2001 From: bsoghigian Date: Mon, 26 Jun 2023 07:39:38 -0700 Subject: [PATCH] fix: dynamic assignment of the scale down threshold flags. Setting maxEmptyBulkDelete, and maxScaleDownParallelism to be the larger of the two flags in the case both are set --- cluster-autoscaler/main.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index 073e3fdf1bf3..795471b0be96 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -232,6 +232,16 @@ var ( forceDaemonSets = flag.Bool("force-ds", false, "Blocks scale-up of node groups too small for all suitable Daemon Sets pods.") ) +func isFlagPassed(name string) bool { + found := false + flag.Visit(func(f *flag.Flag) { + if f.Name == name { + found = true + } + }) + return found +} + func createAutoscalingOptions() config.AutoscalingOptions { minCoresTotal, maxCoresTotal, err := parseMinMaxFlag(*coresTotal) if err != nil { @@ -252,6 +262,17 @@ func createAutoscalingOptions() config.AutoscalingOptions { if *maxDrainParallelismFlag > 1 && !*parallelDrain { klog.Fatalf("Invalid configuration, could not use --max-drain-parallelism > 1 if --parallel-drain is false") } + + // in order to avoid inconsistent deletion thresholds for the legacy planner and the new actuator, the max-empty-bulk-delete, + // and max-scale-down-parallelism flags must be set to the same value. + if isFlagPassed("max-empty-bulk-delete") && !isFlagPassed("max-scale-down-parallelism") { + *maxScaleDownParallelismFlag = *maxEmptyBulkDeleteFlag + klog.Warning("The max-empty-bulk-delete flag will be deprecated in k8s version 1.29. Please use max-scale-down-parallelism instead.") + klog.Infof("Setting max-scale-down-parallelism to %d, based on the max-empty-bulk-delete value %d", *maxScaleDownParallelismFlag, *maxEmptyBulkDeleteFlag) + } else if !isFlagPassed("max-empty-bulk-delete") && isFlagPassed("max-scale-down-parallelism") { + *maxEmptyBulkDeleteFlag = *maxScaleDownParallelismFlag + } + return config.AutoscalingOptions{ NodeGroupDefaults: config.NodeGroupAutoscalingOptions{ ScaleDownUtilizationThreshold: *scaleDownUtilizationThreshold,