From ece98870508ef15c56c40e84fb91360ba9a469ee Mon Sep 17 00:00:00 2001 From: Maciej Sikora <96724614+msikora-rtb@users.noreply.github.com> Date: Tue, 20 May 2025 16:43:04 +0200 Subject: [PATCH] feat: enables blue-green upgrades (#3102) --- modules/gke-nodepool/README.md | 14 +++++++------- modules/gke-nodepool/main.tf | 15 +++++++++++++++ modules/gke-nodepool/variables.tf | 9 +++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/gke-nodepool/README.md b/modules/gke-nodepool/README.md index 7e549fb7d..6a9f6d141 100644 --- a/modules/gke-nodepool/README.md +++ b/modules/gke-nodepool/README.md @@ -191,7 +191,7 @@ module "cluster-1-nodepool-dws" { |---|---|:---:|:---:|:---:| | [cluster_name](variables.tf#L23) | Cluster name. | string | ✓ | | | [location](variables.tf#L48) | Cluster location. | string | ✓ | | -| [project_id](variables.tf#L199) | Cluster project id. | string | ✓ | | +| [project_id](variables.tf#L208) | Cluster project id. | string | ✓ | | | [cluster_id](variables.tf#L17) | Cluster id. Optional, but providing cluster_id is recommended to prevent cluster misconfiguration in some of the edge cases. | string | | null | | [gke_version](variables.tf#L28) | Kubernetes nodes version. Ignored if auto_upgrade is set in management_config. | string | | null | | [k8s_labels](variables.tf#L34) | Kubernetes labels applied to each node. | map(string) | | {} | @@ -202,12 +202,12 @@ module "cluster-1-nodepool-dws" { | [node_config](variables.tf#L89) | Node-level configuration. | object({…}) | | {} | | [node_count](variables.tf#L154) | Number of nodes per instance group. Initial value can only be changed by recreation, current is ignored when autoscaling is used. | object({…}) | | {…} | | [node_locations](variables.tf#L166) | Node locations. | list(string) | | null | -| [nodepool_config](variables.tf#L172) | Nodepool-level configuration. | object({…}) | | null | -| [reservation_affinity](variables.tf#L204) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | -| [service_account](variables.tf#L214) | Nodepool service account. If this variable is set to null, the default GCE service account will be used. If set and email is null, a service account will be created. If scopes are null a default will be used. | object({…}) | | {} | -| [sole_tenant_nodegroup](variables.tf#L226) | Sole tenant node group. | string | | null | -| [tags](variables.tf#L232) | Network tags applied to nodes. | list(string) | | null | -| [taints](variables.tf#L238) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | +| [nodepool_config](variables.tf#L172) | Nodepool-level configuration. | object({…}) | | null | +| [reservation_affinity](variables.tf#L213) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | +| [service_account](variables.tf#L223) | Nodepool service account. If this variable is set to null, the default GCE service account will be used. If set and email is null, a service account will be created. If scopes are null a default will be used. | object({…}) | | {} | +| [sole_tenant_nodegroup](variables.tf#L235) | Sole tenant node group. | string | | null | +| [tags](variables.tf#L241) | Network tags applied to nodes. | list(string) | | null | +| [taints](variables.tf#L247) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | ## Outputs diff --git a/modules/gke-nodepool/main.tf b/modules/gke-nodepool/main.tf index b0d567071..6caaeef6b 100644 --- a/modules/gke-nodepool/main.tf +++ b/modules/gke-nodepool/main.tf @@ -157,6 +157,21 @@ resource "google_container_node_pool" "nodepool" { content { max_surge = try(var.nodepool_config.upgrade_settings.max_surge, null) max_unavailable = try(var.nodepool_config.upgrade_settings.max_unavailable, null) + strategy = try(var.nodepool_config.upgrade_settings.strategy, null) + dynamic "blue_green_settings" { + for_each = try(var.nodepool_config.upgrade_settings.blue_green_settings, null) != null ? [""] : [] + content { + node_pool_soak_duration = var.nodepool_config.upgrade_settings.blue_green_settings.node_pool_soak_duration + dynamic "standard_rollout_policy" { + for_each = try(var.nodepool_config.upgrade_settings.blue_green_settings.standard_rollout_policy, null) != null ? [""] : [] + content { + batch_percentage = var.nodepool_config.upgrade_settings.blue_green_settings.standard_rollout_policy.batch_percentage + batch_node_count = var.nodepool_config.upgrade_settings.blue_green_settings.standard_rollout_policy.batch_node_count + batch_soak_duration = var.nodepool_config.upgrade_settings.blue_green_settings.standard_rollout_policy.batch_soak_duration + } + } + } + } } } diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 20044ba7b..951c07cbe 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -191,6 +191,15 @@ variable "nodepool_config" { upgrade_settings = optional(object({ max_surge = number max_unavailable = number + strategy = optional(string) + blue_green_settings = optional(object({ + node_pool_soak_duration = optional(string) + standard_rollout_policy = optional(object({ + batch_percentage = optional(number) + batch_node_count = optional(number) + batch_soak_duration = optional(string) + })) + })) })) }) default = null