From 0b27e312a66749f54563f51d15ff79f6b20dd997 Mon Sep 17 00:00:00 2001 From: apichick Date: Thu, 26 Jun 2025 20:26:09 +0200 Subject: [PATCH] Added node_pool_auto_config to GKE cluster (#3196) --- modules/gke-cluster-standard/README.md | 7 ++++--- modules/gke-cluster-standard/main.tf | 12 ++++++++++++ modules/gke-cluster-standard/variables.tf | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/modules/gke-cluster-standard/README.md b/modules/gke-cluster-standard/README.md index 2c8b9820b..fca8d922b 100644 --- a/modules/gke-cluster-standard/README.md +++ b/modules/gke-cluster-standard/README.md @@ -488,8 +488,8 @@ module "cluster-1" { |---|---|:---:|:---:|:---:| | [location](variables.tf#L269) | Cluster zone or region. | string | ✓ | | | [name](variables.tf#L384) | Cluster name. | string | ✓ | | -| [project_id](variables.tf#L418) | Cluster project id. | string | ✓ | | -| [vpc_config](variables.tf#L429) | VPC-level configuration. | object({…}) | ✓ | | +| [project_id](variables.tf#L435) | Cluster project id. | string | ✓ | | +| [vpc_config](variables.tf#L446) | VPC-level configuration. | object({…}) | ✓ | | | [access_config](variables.tf#L17) | Control plane endpoint and nodes access configurations. | object({…}) | | {} | | [backup_configs](variables.tf#L45) | Configuration for Backup for GKE. | object({…}) | | {} | | [cluster_autoscaling](variables.tf#L67) | Enable and configure limits for Node Auto-Provisioning with Cluster Autoscaler. | object({…}) | | null | @@ -507,7 +507,8 @@ module "cluster-1" { | [monitoring_config](variables.tf#L330) | Monitoring configuration. Google Cloud Managed Service for Prometheus is enabled by default. | object({…}) | | {} | | [node_config](variables.tf#L389) | Node-level configuration. | object({…}) | | {} | | [node_locations](variables.tf#L411) | Zones in which the cluster's nodes are located. | list(string) | | [] | -| [release_channel](variables.tf#L423) | Release channel for GKE upgrades. | string | | null | +| [node_pool_auto_config](variables.tf#L418) | Node pool configs that apply to auto-provisioned node pools in autopilot clusters and node auto-provisioning-enabled clusters. | object({…}) | | {} | +| [release_channel](variables.tf#L440) | Release channel for GKE upgrades. | string | | null | ## Outputs diff --git a/modules/gke-cluster-standard/main.tf b/modules/gke-cluster-standard/main.tf index ae2083bbb..51e53dd9e 100644 --- a/modules/gke-cluster-standard/main.tf +++ b/modules/gke-cluster-standard/main.tf @@ -88,6 +88,18 @@ resource "google_container_cluster" "cluster" { } } } + node_pool_auto_config { + network_tags { + tags = var.node_pool_auto_config.network_tags + } + resource_manager_tags = var.node_pool_auto_config.resource_manager_tags + node_kubelet_config { + insecure_kubelet_readonly_port_enabled = upper(var.node_pool_auto_config.kubelet_readonly_port_enabled) + } + linux_node_config { + cgroup_mode = var.node_pool_auto_config.cgroup_mode + } + } addons_config { cloudrun_config { disabled = !var.enable_addons.cloudrun diff --git a/modules/gke-cluster-standard/variables.tf b/modules/gke-cluster-standard/variables.tf index 6ced01a27..4d33815f2 100644 --- a/modules/gke-cluster-standard/variables.tf +++ b/modules/gke-cluster-standard/variables.tf @@ -415,6 +415,23 @@ variable "node_locations" { nullable = false } +variable "node_pool_auto_config" { + description = "Node pool configs that apply to auto-provisioned node pools in autopilot clusters and node auto-provisioning-enabled clusters." + type = object({ + cgroup_mode = optional(string) + kubelet_readonly_port_enabled = optional(bool, true) + network_tags = optional(list(string), []) + resource_manager_tags = optional(map(string), {}) + }) + default = {} + nullable = false + validation { + condition = contains(["CGROUPMODE_UNSPECIFIED", "CGROUPMODE_V1", "CGROUPMODE_V2"], + coalesce(var.node_pool_auto_config.cgroup_mode, "CGROUPMODE_UNSPECIFIED")) + error_message = "node_pool_auto_config.cgroup_mode must be CGROUPMODE_UNSPECIFIED, CGROUPMODE_V1 or CGROUPMODE_V2" + } +} + variable "project_id" { description = "Cluster project id." type = string