From d491b02cfa175aeb0d50ab186494430d1cc3996e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Thu, 27 Jun 2024 18:28:58 +0200 Subject: [PATCH 1/8] Adding placement policy to gke-nodepool module --- modules/gke-nodepool/README.md | 22 +++++++++++----------- modules/gke-nodepool/variables.tf | 1 + 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/modules/gke-nodepool/README.md b/modules/gke-nodepool/README.md index 41338cfacb..694726b76e 100644 --- a/modules/gke-nodepool/README.md +++ b/modules/gke-nodepool/README.md @@ -143,23 +143,23 @@ module "cluster-1-nodepool-gpu-1" { |---|---|:---:|:---:|:---:| | [cluster_name](variables.tf#L23) | Cluster name. | string | ✓ | | | [location](variables.tf#L48) | Cluster location. | string | ✓ | | -| [project_id](variables.tf#L177) | Cluster project id. | string | ✓ | | +| [project_id](variables.tf#L178) | 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) | | {} | | [labels](variables.tf#L41) | The resource labels to be applied each node (vm). | map(string) | | {} | | [max_pods_per_node](variables.tf#L53) | Maximum number of pods per node. | number | | null | | [name](variables.tf#L59) | Optional nodepool name. | string | | null | -| [node_config](variables.tf#L65) | Node-level configuration. | object({…}) | | {…} | -| [node_count](variables.tf#L124) | 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#L136) | Node locations. | list(string) | | null | -| [nodepool_config](variables.tf#L142) | Nodepool-level configuration. | object({…}) | | null | -| [pod_range](variables.tf#L164) | Pod secondary range configuration. | object({…}) | | null | -| [reservation_affinity](variables.tf#L182) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | -| [service_account](variables.tf#L192) | 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#L203) | Sole tenant node group. | string | | null | -| [tags](variables.tf#L209) | Network tags applied to nodes. | list(string) | | null | -| [taints](variables.tf#L215) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | +| [node_config](variables.tf#L65) | Node-level configuration. | object({…}) | | {…} | +| [node_count](variables.tf#L125) | 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#L137) | Node locations. | list(string) | | null | +| [nodepool_config](variables.tf#L143) | Nodepool-level configuration. | object({…}) | | null | +| [pod_range](variables.tf#L165) | Pod secondary range configuration. | object({…}) | | null | +| [reservation_affinity](variables.tf#L183) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | +| [service_account](variables.tf#L193) | 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#L204) | Sole tenant node group. | string | | null | +| [tags](variables.tf#L210) | Network tags applied to nodes. | list(string) | | null | +| [taints](variables.tf#L216) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | ## Outputs diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 066390e438..702af93440 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -96,6 +96,7 @@ variable "node_config" { machine_type = optional(string) metadata = optional(map(string)) min_cpu_platform = optional(string) + placement_policy = optional(string) preemptible = optional(bool) sandbox_config_gvisor = optional(bool) shielded_instance_config = optional(object({ From 71022c7c767d781ccbae7929a5b153dd8378b286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 19:39:44 +0200 Subject: [PATCH 2/8] Adding placement policy for GKE nodepool --- modules/gke-nodepool/main.tf | 10 +++++++++- modules/gke-nodepool/variables.tf | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/gke-nodepool/main.tf b/modules/gke-nodepool/main.tf index 659dfc4b7e..50898fc097 100644 --- a/modules/gke-nodepool/main.tf +++ b/modules/gke-nodepool/main.tf @@ -77,7 +77,6 @@ resource "google_container_node_pool" "nodepool" { initial_node_count = var.node_count.initial node_count = var.node_count.current node_locations = var.node_locations - # placement_policy = var.nodepool_config.placement_policy dynamic "autoscaling" { for_each = ( @@ -129,6 +128,15 @@ resource "google_container_node_pool" "nodepool" { } } + dynamic "placement_policy" { + for_each = try(var.nodepool_config.placement_policy, null) != null ? [""] : [] + content { + type = try(var.nodepool_config.placement_policy.type, null) + policy_name = try(var.nodepool_config.placement_policy.policy_name, null) + tpu_topology = try(var.nodepool_config.tpu_topology.type, null) + } + } + node_config { boot_disk_kms_key = var.node_config.boot_disk_kms_key disk_size_gb = var.node_config.disk_size_gb diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 702af93440..49b9a6119f 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -175,6 +175,16 @@ variable "pod_range" { default = null } +variable "placement_policy" { + description = "Placement policy for the node pool. Contains a type attribute that must be COMPACT." + type = object({ + type = string + policy_name = optional(string) + tpu_topology = optional(string) + }) + default = null +} + variable "project_id" { description = "Cluster project id." type = string From 03e261af9d3fc3dce4e00811844e40de1fc7b348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 19:41:57 +0200 Subject: [PATCH 3/8] updated README --- modules/gke-nodepool/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/modules/gke-nodepool/README.md b/modules/gke-nodepool/README.md index 694726b76e..f553525a14 100644 --- a/modules/gke-nodepool/README.md +++ b/modules/gke-nodepool/README.md @@ -143,7 +143,7 @@ module "cluster-1-nodepool-gpu-1" { |---|---|:---:|:---:|:---:| | [cluster_name](variables.tf#L23) | Cluster name. | string | ✓ | | | [location](variables.tf#L48) | Cluster location. | string | ✓ | | -| [project_id](variables.tf#L178) | Cluster project id. | string | ✓ | | +| [project_id](variables.tf#L188) | 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) | | {} | @@ -154,12 +154,13 @@ module "cluster-1-nodepool-gpu-1" { | [node_count](variables.tf#L125) | 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#L137) | Node locations. | list(string) | | null | | [nodepool_config](variables.tf#L143) | Nodepool-level configuration. | object({…}) | | null | +| [placement_policy](variables.tf#L178) | Placement policy for the node pool. Contains a type attribute that must be COMPACT. | object({…}) | | null | | [pod_range](variables.tf#L165) | Pod secondary range configuration. | object({…}) | | null | -| [reservation_affinity](variables.tf#L183) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | -| [service_account](variables.tf#L193) | 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#L204) | Sole tenant node group. | string | | null | -| [tags](variables.tf#L210) | Network tags applied to nodes. | list(string) | | null | -| [taints](variables.tf#L216) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | +| [reservation_affinity](variables.tf#L193) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | +| [service_account](variables.tf#L203) | 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#L214) | Sole tenant node group. | string | | null | +| [tags](variables.tf#L220) | Network tags applied to nodes. | list(string) | | null | +| [taints](variables.tf#L226) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | ## Outputs From 584e3eb66c4164105ddec4292e240e267d1defa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 21:19:39 +0200 Subject: [PATCH 4/8] variables for placement_policy --- modules/gke-nodepool/variables.tf | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 49b9a6119f..4cd7ac7b1f 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -96,7 +96,6 @@ variable "node_config" { machine_type = optional(string) metadata = optional(map(string)) min_cpu_platform = optional(string) - placement_policy = optional(string) preemptible = optional(bool) sandbox_config_gvisor = optional(bool) shielded_instance_config = optional(object({ @@ -153,7 +152,11 @@ variable "nodepool_config" { auto_repair = optional(bool) auto_upgrade = optional(bool) })) - # placement_policy = optional(bool) + placement_policy = optional(object({ + type = string + policy_name = optional(string) + tpu_topology = optional(string) + })) upgrade_settings = optional(object({ max_surge = number max_unavailable = number @@ -175,16 +178,6 @@ variable "pod_range" { default = null } -variable "placement_policy" { - description = "Placement policy for the node pool. Contains a type attribute that must be COMPACT." - type = object({ - type = string - policy_name = optional(string) - tpu_topology = optional(string) - }) - default = null -} - variable "project_id" { description = "Cluster project id." type = string From 80e3be30a94914021e78a29a6379d1645136c3c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 21:27:45 +0200 Subject: [PATCH 5/8] formatting --- modules/gke-nodepool/variables.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 4cd7ac7b1f..c970c5b1bd 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -153,8 +153,8 @@ variable "nodepool_config" { auto_upgrade = optional(bool) })) placement_policy = optional(object({ - type = string - policy_name = optional(string) + type = string + policy_name = optional(string) tpu_topology = optional(string) })) upgrade_settings = optional(object({ From f2297c1658f664348eca6d66ccea74cbecd595ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 21:31:35 +0200 Subject: [PATCH 6/8] Updated README --- modules/gke-nodepool/README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/gke-nodepool/README.md b/modules/gke-nodepool/README.md index f553525a14..453fff8d62 100644 --- a/modules/gke-nodepool/README.md +++ b/modules/gke-nodepool/README.md @@ -143,24 +143,23 @@ module "cluster-1-nodepool-gpu-1" { |---|---|:---:|:---:|:---:| | [cluster_name](variables.tf#L23) | Cluster name. | string | ✓ | | | [location](variables.tf#L48) | Cluster location. | string | ✓ | | -| [project_id](variables.tf#L188) | Cluster project id. | string | ✓ | | +| [project_id](variables.tf#L181) | 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) | | {} | | [labels](variables.tf#L41) | The resource labels to be applied each node (vm). | map(string) | | {} | | [max_pods_per_node](variables.tf#L53) | Maximum number of pods per node. | number | | null | | [name](variables.tf#L59) | Optional nodepool name. | string | | null | -| [node_config](variables.tf#L65) | Node-level configuration. | object({…}) | | {…} | -| [node_count](variables.tf#L125) | 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#L137) | Node locations. | list(string) | | null | -| [nodepool_config](variables.tf#L143) | Nodepool-level configuration. | object({…}) | | null | -| [placement_policy](variables.tf#L178) | Placement policy for the node pool. Contains a type attribute that must be COMPACT. | object({…}) | | null | -| [pod_range](variables.tf#L165) | Pod secondary range configuration. | object({…}) | | null | -| [reservation_affinity](variables.tf#L193) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | -| [service_account](variables.tf#L203) | 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#L214) | Sole tenant node group. | string | | null | -| [tags](variables.tf#L220) | Network tags applied to nodes. | list(string) | | null | -| [taints](variables.tf#L226) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | +| [node_config](variables.tf#L65) | Node-level configuration. | object({…}) | | {…} | +| [node_count](variables.tf#L124) | 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#L136) | Node locations. | list(string) | | null | +| [nodepool_config](variables.tf#L142) | Nodepool-level configuration. | object({…}) | | null | +| [pod_range](variables.tf#L168) | Pod secondary range configuration. | object({…}) | | null | +| [reservation_affinity](variables.tf#L186) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | +| [service_account](variables.tf#L196) | 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#L207) | Sole tenant node group. | string | | null | +| [tags](variables.tf#L213) | Network tags applied to nodes. | list(string) | | null | +| [taints](variables.tf#L219) | Kubernetes taints applied to all nodes. | map(object({…})) | | {} | ## Outputs From dd48bf7022d767a72da19b8f08e6be313d4e688c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Tue, 2 Jul 2024 21:35:22 +0200 Subject: [PATCH 7/8] fixing typo --- modules/gke-nodepool/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/gke-nodepool/main.tf b/modules/gke-nodepool/main.tf index 50898fc097..2228d616f2 100644 --- a/modules/gke-nodepool/main.tf +++ b/modules/gke-nodepool/main.tf @@ -133,7 +133,7 @@ resource "google_container_node_pool" "nodepool" { content { type = try(var.nodepool_config.placement_policy.type, null) policy_name = try(var.nodepool_config.placement_policy.policy_name, null) - tpu_topology = try(var.nodepool_config.tpu_topology.type, null) + tpu_topology = try(var.nodepool_config.placement_policy.tpu_topology, null) } } From bd540a320a295b40f0fd514575b9a616bb276ac1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Legrand?= Date: Wed, 3 Jul 2024 12:09:20 +0200 Subject: [PATCH 8/8] removing useless trys --- modules/gke-nodepool/main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/gke-nodepool/main.tf b/modules/gke-nodepool/main.tf index 2228d616f2..b94ef697c8 100644 --- a/modules/gke-nodepool/main.tf +++ b/modules/gke-nodepool/main.tf @@ -131,9 +131,9 @@ resource "google_container_node_pool" "nodepool" { dynamic "placement_policy" { for_each = try(var.nodepool_config.placement_policy, null) != null ? [""] : [] content { - type = try(var.nodepool_config.placement_policy.type, null) - policy_name = try(var.nodepool_config.placement_policy.policy_name, null) - tpu_topology = try(var.nodepool_config.placement_policy.tpu_topology, null) + type = var.nodepool_config.placement_policy.type + policy_name = var.nodepool_config.placement_policy.policy_name + tpu_topology = var.nodepool_config.placement_policy.tpu_topology } }