diff --git a/cluster-autoscaler/main.go b/cluster-autoscaler/main.go index fe9c53449527..05dcfe0091db 100644 --- a/cluster-autoscaler/main.go +++ b/cluster-autoscaler/main.go @@ -233,6 +233,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 { @@ -253,12 +263,22 @@ func createAutoscalingOptions() config.AutoscalingOptions { if *maxDrainParallelismFlag > 1 && !*parallelDrain { klog.Fatalf("Invalid configuration, could not use --max-drain-parallelism > 1 if --parallel-drain is false") } + // cases we have 3, 1. Mebd was set, but msdp was not, 2 msdp was set, but mebd was not, 3. both were set + if isFlagPassed("max-empty-bulk-delete") && !isFlagPassed("max-scale-down-parallelism") { + // Set maxScaleDownParallelismFlag = maxEmptyBulkDeleteFlag to avoid inconsistent deletion thresholds for the legacy planner and the new actuator. + *maxScaleDownParallelismFlag = *maxEmptyBulkDeleteFlag + } else if !isFlagPassed("max-empty-bulk-delete") && isFlagPassed("max-scale-down-parallelism") { + // Set maxEmptyBulkDeleteFlag = maxScaleDownParallelismFlag to avoid inconsistent deletion thresholds for the legacy planner and the new actuator. + *maxEmptyBulkDeleteFlag = *maxScaleDownParallelismFlag + } else { + maxDeletionSize := int(math.Max(float64(*maxEmptyBulkDeleteFlag), float64(*maxScaleDownParallelismFlag))) + *maxEmptyBulkDeleteFlag = maxDeletionSize + *maxScaleDownParallelismFlag = maxDeletionSize + + } // In order to avoid inconsistent deletion thresholds for the legacy planner and the new actuator, // we set the deletion threshold to the maximum of the two flags that are used to filter down deletion candidates. - maxDeletionSize := int(math.Max(float64(*maxEmptyBulkDeleteFlag), float64(*maxScaleDownParallelismFlag))) - *maxEmptyBulkDeleteFlag = maxDeletionSize - *maxScaleDownParallelismFlag = maxDeletionSize return config.AutoscalingOptions{ NodeGroupDefaults: config.NodeGroupAutoscalingOptions{ ScaleDownUtilizationThreshold: *scaleDownUtilizationThreshold,