Skip to content

Commit

Permalink
feat: dynamic assignment of the scale down threshold flags
Browse files Browse the repository at this point in the history
  • Loading branch information
bsoghigian committed Jul 4, 2023
1 parent 92a6707 commit 6a1eb24
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions cluster-autoscaler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 6a1eb24

Please sign in to comment.