Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cherry Pick] Making upgrade settings configurable #3434

Merged
merged 3 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/compute/gke-node-pool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ limitations under the License.
| <a name="input_timeout_update"></a> [timeout\_update](#input\_timeout\_update) | Timeout for updating a node pool | `string` | `null` | no |
| <a name="input_total_max_nodes"></a> [total\_max\_nodes](#input\_total\_max\_nodes) | DEPRECATED: Use autoscaling\_total\_max\_nodes. | `number` | `null` | no |
| <a name="input_total_min_nodes"></a> [total\_min\_nodes](#input\_total\_min\_nodes) | DEPRECATED: Use autoscaling\_total\_min\_nodes. | `number` | `null` | no |
| <a name="input_upgrade_settings"></a> [upgrade\_settings](#input\_upgrade\_settings) | Defines node pool 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_zones"></a> [zones](#input\_zones) | A list of zones to be used. Zones must be in region of cluster. If null, cluster zones will be inherited. Note `zones` not `zone`; does not work with `zone` deployment variable. | `list(string)` | `null` | no |

## Outputs
Expand Down
30 changes: 27 additions & 3 deletions modules/compute/gke-node-pool/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-node-pool", ghpc_role = "compute" })
}

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 {
has_gpu = length(local.guest_accelerator) > 0
gpu_taint = local.has_gpu ? [{
Expand Down Expand Up @@ -60,9 +68,9 @@ resource "google_container_node_pool" "node_pool" {
}

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

dynamic "placement_policy" {
Expand Down Expand Up @@ -262,6 +270,22 @@ resource "google_container_node_pool" "node_pool" {
)
error_message = "Shared Extended reservations are not supported by GKE."
}
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/compute/gke-node-pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,21 @@ variable "node_version" {
type = string
default = null
}

variable "upgrade_settings" {
description = <<-EOT
Defines node pool 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
}
}
Loading