Skip to content

Commit

Permalink
Merge pull request #3434 from ighosh98/experimental
Browse files Browse the repository at this point in the history
[Cherry Pick] Making upgrade settings configurable
  • Loading branch information
ighosh98 authored Dec 19, 2024
2 parents 98c49fe + 0fd8bb1 commit a4ece8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
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
}
}

0 comments on commit a4ece8e

Please sign in to comment.