Skip to content

Commit 83288cf

Browse files
authored
feat: support granular aggressive mode config (#458)
* feat: support granular aggressive mode config in scheduled rebalancing
1 parent 2a0b837 commit 83288cf

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

castai/data_source_resource_rebalancing_schedule_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ func TestRebalancingScheduleDataSourceRead(t *testing.T) {
5050
"evictGracefully": false,
5151
"aggressiveMode": false,
5252
"aggressiveModeConfig": {
53-
"ignoreLocalPersistentVolumes": true
53+
"ignoreLocalPersistentVolumes": true,
54+
"ignoreProblemJobPods": true,
55+
"ignoreProblemRemovalDisabledPods": true,
56+
"ignoreProblemPodsWithoutController": true
5457
}
5558
},
5659
"numTargetedNodes": 20,
@@ -131,6 +134,9 @@ launch_configuration.# = 1
131134
launch_configuration.0.aggressive_mode = false
132135
launch_configuration.0.aggressive_mode_config.# = 1
133136
launch_configuration.0.aggressive_mode_config.0.ignore_local_persistent_volumes = true
137+
launch_configuration.0.aggressive_mode_config.0.ignore_problem_job_pods = true
138+
launch_configuration.0.aggressive_mode_config.0.ignore_problem_pods_without_controller = true
139+
launch_configuration.0.aggressive_mode_config.0.ignore_problem_removal_disabled_pods = true
134140
launch_configuration.0.execution_conditions.# = 1
135141
launch_configuration.0.execution_conditions.0.achieved_savings_percentage = 15
136142
launch_configuration.0.execution_conditions.0.enabled = true

castai/resource_rebalancing_schedule.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,22 @@ func resourceRebalancingSchedule() *schema.Resource {
131131
"ignore_local_persistent_volumes": {
132132
Type: schema.TypeBool,
133133
Required: true,
134-
Description: "Rebalance workloads using local-path Persistent Volumes. THIS WILL RESULT IN DATA LOSS.",
134+
Description: "Rebalance workloads that use local-path Persistent Volumes. THIS WILL RESULT IN DATA LOSS.",
135+
},
136+
"ignore_problem_job_pods": {
137+
Type: schema.TypeBool,
138+
Required: true,
139+
Description: "Pods spawned by Jobs or CronJobs will not prevent the Rebalancer from deleting a node on which they run. WARNING: When true, pods spawned by Jobs or CronJobs will be terminated if the Rebalancer picks a node that runs them. As such, they are likely to lose their progress.",
140+
},
141+
"ignore_problem_removal_disabled_pods": {
142+
Type: schema.TypeBool,
143+
Required: true,
144+
Description: `Pods that are marked with "removal disabled" will not prevent the Rebalancer from deleting a node on which they run. WARNING: When true, such pods will be evicted and disrupted.`,
145+
},
146+
"ignore_problem_pods_without_controller": {
147+
Type: schema.TypeBool,
148+
Required: true,
149+
Description: "Pods that don't have a controller (bare pods) will not prevent the Rebalancer from deleting a node on which they run. WARNING: When true, such pods might not restart, since they have no controller to do it.",
135150
},
136151
},
137152
},
@@ -314,7 +329,10 @@ func stateToSchedule(d *schema.ResourceData) (*sdk.ScheduledrebalancingV1Rebalan
314329
aggressiveModeConfigSection := launchConfigurationData["aggressive_mode_config"].([]any)
315330
if len(aggressiveModeConfigSection) != 0 {
316331
aggressiveModeConfig = &sdk.ScheduledrebalancingV1AggressiveModeConfig{
317-
IgnoreLocalPersistentVolumes: lo.ToPtr(aggressiveModeConfigSection[0].(map[string]any)["ignore_local_persistent_volumes"].(bool)),
332+
IgnoreLocalPersistentVolumes: lo.ToPtr(aggressiveModeConfigSection[0].(map[string]any)["ignore_local_persistent_volumes"].(bool)),
333+
IgnoreProblemJobPods: lo.ToPtr(aggressiveModeConfigSection[0].(map[string]any)["ignore_problem_job_pods"].(bool)),
334+
IgnoreProblemRemovalDisabledPods: lo.ToPtr(aggressiveModeConfigSection[0].(map[string]any)["ignore_problem_removal_disabled_pods"].(bool)),
335+
IgnoreProblemPodsWithoutController: lo.ToPtr(aggressiveModeConfigSection[0].(map[string]any)["ignore_problem_pods_without_controller"].(bool)),
318336
}
319337
}
320338

@@ -363,7 +381,10 @@ func scheduleToState(schedule *sdk.ScheduledrebalancingV1RebalancingSchedule, d
363381
if schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig != nil {
364382
launchConfig["aggressive_mode_config"] = []map[string]any{
365383
{
366-
"ignore_local_persistent_volumes": schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig.IgnoreLocalPersistentVolumes,
384+
"ignore_local_persistent_volumes": schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig.IgnoreLocalPersistentVolumes,
385+
"ignore_problem_job_pods": schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig.IgnoreProblemJobPods,
386+
"ignore_problem_removal_disabled_pods": schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig.IgnoreProblemRemovalDisabledPods,
387+
"ignore_problem_pods_without_controller": schedule.LaunchConfiguration.RebalancingOptions.AggressiveModeConfig.IgnoreProblemPodsWithoutController,
367388
},
368389
}
369390
}

castai/resource_rebalancing_schedule_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ func TestAccResourceRebalancingSchedule_basic(t *testing.T) {
4444
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "schedule.0.cron", "1 4 * * *"),
4545
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "launch_configuration.0.aggressive_mode", "true"),
4646
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "launch_configuration.0.aggressive_mode_config.0.ignore_local_persistent_volumes", "true"),
47+
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "launch_configuration.0.aggressive_mode_config.0.ignore_problem_job_pods", "true"),
48+
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "launch_configuration.0.aggressive_mode_config.0.ignore_problem_removal_disabled_pods", "true"),
49+
resource.TestCheckResourceAttr("castai_rebalancing_schedule.test", "launch_configuration.0.aggressive_mode_config.0.ignore_problem_pods_without_controller", "true"),
4750
),
4851
},
4952
{
@@ -96,6 +99,9 @@ resource "castai_rebalancing_schedule" "test" {
9699
aggressive_mode = true
97100
aggressive_mode_config {
98101
ignore_local_persistent_volumes = true
102+
ignore_problem_job_pods = true
103+
ignore_problem_removal_disabled_pods = true
104+
ignore_problem_pods_without_controller = true
99105
}
100106
selector = jsonencode({
101107
nodeSelectorTerms = [{

castai/sdk/api.gen.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/data-sources/rebalancing_schedule.md

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/resources/rebalancing_schedule.md

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)