Skip to content

Commit

Permalink
Allow keeping nodes for which scheduled rebalancer's drain phase has …
Browse files Browse the repository at this point in the history
…timed out (#182)
  • Loading branch information
kiriloman authored Jul 11, 2023
1 parent 3700b51 commit cdbc10c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
13 changes: 11 additions & 2 deletions castai/resource_rebalancing_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func resourceRebalancingSchedule() *schema.Resource {
ValidateDiagFunc: validation.ToDiagFunc(validation.IntAtLeast(1)),
Description: "Minimum number of nodes that should be kept in the cluster after rebalancing.",
},
"keep_drain_timeout_nodes": {
Type: schema.TypeBool,
Optional: true,
Description: "Defines whether the nodes that failed to get drained until a predefined timeout, will be kept with a rebalancing.cast.ai/status=drain-failed annotation instead of forcefully drained.",
},
"execution_conditions": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -243,6 +248,8 @@ func stateToSchedule(d *schema.ResourceData) (*sdk.ScheduledrebalancingV1Rebalan
return nil, fmt.Errorf("parsing selector: %w", err)
}

keepDrainTimeoutNodes := readOptionalValue[bool](launchConfigurationData, "keep_drain_timeout_nodes")

var executionConditions *sdk.ScheduledrebalancingV1ExecutionConditions
executionConditionsData := launchConfigurationData["execution_conditions"].([]any)
if len(executionConditionsData) != 0 {
Expand All @@ -256,8 +263,9 @@ func stateToSchedule(d *schema.ResourceData) (*sdk.ScheduledrebalancingV1Rebalan
NodeTtlSeconds: readOptionalNumber[int, int32](launchConfigurationData, "node_ttl_seconds"),
NumTargetedNodes: readOptionalNumber[int, int32](launchConfigurationData, "num_targeted_nodes"),
RebalancingOptions: &sdk.ScheduledrebalancingV1RebalancingOptions{
MinNodes: readOptionalNumber[int, int32](launchConfigurationData, "rebalancing_min_nodes"),
ExecutionConditions: executionConditions,
MinNodes: readOptionalNumber[int, int32](launchConfigurationData, "rebalancing_min_nodes"),
KeepDrainTimeoutNodes: keepDrainTimeoutNodes,
ExecutionConditions: executionConditions,
},
Selector: selector,
}
Expand Down Expand Up @@ -286,6 +294,7 @@ func scheduleToState(schedule *sdk.ScheduledrebalancingV1RebalancingSchedule, d

if schedule.LaunchConfiguration.RebalancingOptions != nil {
launchConfig["rebalancing_min_nodes"] = schedule.LaunchConfiguration.RebalancingOptions.MinNodes
launchConfig["keep_drain_timeout_nodes"] = schedule.LaunchConfiguration.RebalancingOptions.KeepDrainTimeoutNodes

executionConditions := schedule.LaunchConfiguration.RebalancingOptions.ExecutionConditions
if executionConditions != nil {
Expand Down
1 change: 1 addition & 0 deletions castai/resource_rebalancing_schedule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ resource "castai_rebalancing_schedule" "test" {
node_ttl_seconds = 10
num_targeted_nodes = 3
rebalancing_min_nodes = 2
keep_drain_timeout_nodes = true
selector = jsonencode({
nodeSelectorTerms = [{
matchExpressions = [
Expand Down
4 changes: 4 additions & 0 deletions castai/sdk/api.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions docs/resources/rebalancing_schedule.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions examples/eks/eks_cluster_autoscaler_polices/castai.tf
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ resource "castai_rebalancing_schedule" "spots" {
node_ttl_seconds = 300
num_targeted_nodes = 3
rebalancing_min_nodes = 2
keep_drain_timeout_nodes = false
selector = jsonencode({
nodeSelectorTerms = [{
matchExpressions = [
Expand Down
1 change: 1 addition & 0 deletions examples/resources/castai_rebalancing_schedule/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ resource "castai_rebalancing_schedule" "spots" {
node_ttl_seconds = 300
num_targeted_nodes = 3
rebalancing_min_nodes = 2
keep_drain_timeout_nodes = false
selector = jsonencode({
nodeSelectorTerms = [{
matchExpressions = [
Expand Down

0 comments on commit cdbc10c

Please sign in to comment.