Skip to content

Commit

Permalink
Merge pull request #3463 from ighosh98/experimental
Browse files Browse the repository at this point in the history
make upgrade settings configurable
  • Loading branch information
ighosh98 authored Dec 24, 2024
2 parents a4ece8e + b9b98a1 commit b07ae5b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions modules/scheduler/gke-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ limitations under the License.
| <a name="input_system_node_pool_taints"></a> [system\_node\_pool\_taints](#input\_system\_node\_pool\_taints) | Taints to be applied to the system node pool. | <pre>list(object({<br/> key = string<br/> value = any<br/> effect = string<br/> }))</pre> | <pre>[<br/> {<br/> "effect": "NO_SCHEDULE",<br/> "key": "components.gke.io/gke-managed-components",<br/> "value": true<br/> }<br/>]</pre> | no |
| <a name="input_timeout_create"></a> [timeout\_create](#input\_timeout\_create) | Timeout for creating a node pool | `string` | `null` | no |
| <a name="input_timeout_update"></a> [timeout\_update](#input\_timeout\_update) | Timeout for updating a node pool | `string` | `null` | no |
| <a name="input_upgrade_settings"></a> [upgrade\_settings](#input\_upgrade\_settings) | Defines gke cluster upgrade settings. It is highly recommended that you define all max\_surge and max\_unavailable.<br/>If max\_surge is not specified, it would be set to a default value of 0.<br/>If max\_unavailable is not specified, it would be set to a default value of 1. | <pre>object({<br/> strategy = string<br/> max_surge = optional(number)<br/> max_unavailable = optional(number)<br/> })</pre> | <pre>{<br/> "max_surge": 0,<br/> "max_unavailable": 1,<br/> "strategy": "SURGE"<br/>}</pre> | no |
| <a name="input_zone"></a> [zone](#input\_zone) | Zone for a zonal cluster | `string` | `null` | no |

## Outputs
Expand Down
29 changes: 27 additions & 2 deletions modules/scheduler/gke-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ locals {
labels = merge(var.labels, { ghpc_module = "gke-cluster", ghpc_role = "scheduler" })
}

locals {
upgrade_settings = {
strategy = var.upgrade_settings.strategy
max_surge = coalesce(var.upgrade_settings.max_surge, 0)
max_unavailable = coalesce(var.upgrade_settings.max_unavailable, 1)
}
}

locals {
dash = var.prefix_with_deployment_name && var.name_suffix != "" ? "-" : ""
prefix = var.prefix_with_deployment_name ? var.deployment_name : ""
Expand Down Expand Up @@ -218,8 +226,9 @@ resource "google_container_node_pool" "system_node_pools" {
}

upgrade_settings {
max_surge = 1
max_unavailable = 0
strategy = local.upgrade_settings.strategy
max_surge = local.upgrade_settings.max_surge
max_unavailable = local.upgrade_settings.max_unavailable
}

management {
Expand Down Expand Up @@ -279,6 +288,22 @@ resource "google_container_node_pool" "system_node_pools" {
node_config[0].labels,
node_config[0].taint,
]
precondition {
condition = contains(["SURGE"], local.upgrade_settings.strategy)
error_message = "Only SURGE strategy is supported"
}
precondition {
condition = local.upgrade_settings.max_unavailable >= 0
error_message = "max_unavailable should be set to 0 or greater"
}
precondition {
condition = local.upgrade_settings.max_surge >= 0
error_message = "max_surge should be set to 0 or greater"
}
precondition {
condition = local.upgrade_settings.max_unavailable > 0 || local.upgrade_settings.max_surge > 0
error_message = "At least one of max_unavailable or max_surge must greater than 0"
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions modules/scheduler/gke-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,21 @@ variable "zone" {
default = null
type = string
}

variable "upgrade_settings" {
description = <<-EOT
Defines gke cluster upgrade settings. It is highly recommended that you define all max_surge and max_unavailable.
If max_surge is not specified, it would be set to a default value of 0.
If max_unavailable is not specified, it would be set to a default value of 1.
EOT
type = object({
strategy = string
max_surge = optional(number)
max_unavailable = optional(number)
})
default = {
strategy = "SURGE"
max_surge = 0
max_unavailable = 1
}
}

0 comments on commit b07ae5b

Please sign in to comment.