From 4395d10edf25ad8220a6ff7c49151cb20e7bce8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Wed, 21 Dec 2022 12:56:17 +0100 Subject: [PATCH] Fixes for GKE * Fix non-empty plan when spot instances are used * Add cluster_id and recommend its use, as this prevents inconsitencies when only cluster is recreated (with no changes on node pool) --- blueprints/networking/shared-vpc-gke/main.tf | 1 + modules/gke-cluster/main.tf | 3 +- modules/gke-nodepool/README.md | 35 ++++++++++---------- modules/gke-nodepool/main.tf | 2 +- modules/gke-nodepool/variables.tf | 6 ++++ 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/blueprints/networking/shared-vpc-gke/main.tf b/blueprints/networking/shared-vpc-gke/main.tf index 2e770377f1..97bf45d247 100644 --- a/blueprints/networking/shared-vpc-gke/main.tf +++ b/blueprints/networking/shared-vpc-gke/main.tf @@ -227,6 +227,7 @@ module "cluster-1-nodepool-1" { project_id = module.project-svc-gke.project_id location = module.cluster-1.0.location cluster_name = module.cluster-1.0.name + cluster_id = module.cluster-1.0.id service_account = { create = true } diff --git a/modules/gke-cluster/main.tf b/modules/gke-cluster/main.tf index 3ef14391a1..5b5cd95f3a 100644 --- a/modules/gke-cluster/main.tf +++ b/modules/gke-cluster/main.tf @@ -17,7 +17,8 @@ resource "google_container_cluster" "cluster" { lifecycle { ignore_changes = [ - node_config[0].boot_disk_kms_key + node_config[0].boot_disk_kms_key, + node_config[0].spot ] } provider = google-beta diff --git a/modules/gke-nodepool/README.md b/modules/gke-nodepool/README.md index e1201b1d20..50e9d08cb1 100644 --- a/modules/gke-nodepool/README.md +++ b/modules/gke-nodepool/README.md @@ -83,23 +83,24 @@ module "cluster-1-nodepool-1" { | name | description | type | required | default | |---|---|:---:|:---:|:---:| -| [cluster_name](variables.tf#L17) | Cluster name. | string | ✓ | | -| [location](variables.tf#L35) | Cluster location. | string | ✓ | | -| [project_id](variables.tf#L143) | Cluster project id. | string | ✓ | | -| [gke_version](variables.tf#L22) | Kubernetes nodes version. Ignored if auto_upgrade is set in management_config. | string | | null | -| [labels](variables.tf#L28) | Kubernetes labels applied to each node. | map(string) | | {} | -| [max_pods_per_node](variables.tf#L40) | Maximum number of pods per node. | number | | null | -| [name](variables.tf#L46) | Optional nodepool name. | string | | null | -| [node_config](variables.tf#L52) | Node-level configuration. | object({…}) | | {…} | -| [node_count](variables.tf#L91) | 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#L103) | Node locations. | list(string) | | null | -| [nodepool_config](variables.tf#L109) | Nodepool-level configuration. | object({…}) | | null | -| [pod_range](variables.tf#L131) | Pod secondary range configuration. | object({…}) | | null | -| [reservation_affinity](variables.tf#L148) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | -| [service_account](variables.tf#L158) | 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#L169) | Sole tenant node group. | string | | null | -| [tags](variables.tf#L175) | Network tags applied to nodes. | list(string) | | null | -| [taints](variables.tf#L181) | Kubernetes taints applied to all nodes. | list(object({…})) | | null | +| [cluster_name](variables.tf#L23) | Cluster name. | string | ✓ | | +| [location](variables.tf#L41) | Cluster location. | string | ✓ | | +| [project_id](variables.tf#L149) | 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 | +| [labels](variables.tf#L34) | Kubernetes labels applied to each node. | map(string) | | {} | +| [max_pods_per_node](variables.tf#L46) | Maximum number of pods per node. | number | | null | +| [name](variables.tf#L52) | Optional nodepool name. | string | | null | +| [node_config](variables.tf#L58) | Node-level configuration. | object({…}) | | {…} | +| [node_count](variables.tf#L97) | 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#L109) | Node locations. | list(string) | | null | +| [nodepool_config](variables.tf#L115) | Nodepool-level configuration. | object({…}) | | null | +| [pod_range](variables.tf#L137) | Pod secondary range configuration. | object({…}) | | null | +| [reservation_affinity](variables.tf#L154) | Configuration of the desired reservation which instances could take capacity from. | object({…}) | | null | +| [service_account](variables.tf#L164) | 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#L175) | Sole tenant node group. | string | | null | +| [tags](variables.tf#L181) | Network tags applied to nodes. | list(string) | | null | +| [taints](variables.tf#L187) | Kubernetes taints applied to all nodes. | list(object({…})) | | null | ## Outputs diff --git a/modules/gke-nodepool/main.tf b/modules/gke-nodepool/main.tf index 0c35c8d0f8..ad0c053f35 100644 --- a/modules/gke-nodepool/main.tf +++ b/modules/gke-nodepool/main.tf @@ -70,7 +70,7 @@ resource "google_service_account" "service_account" { resource "google_container_node_pool" "nodepool" { provider = google-beta project = var.project_id - cluster = var.cluster_name + cluster = coalesce(var.cluster_id, var.cluster_name) location = var.location name = var.name version = var.gke_version diff --git a/modules/gke-nodepool/variables.tf b/modules/gke-nodepool/variables.tf index 15c8a15155..e0d3e967a5 100644 --- a/modules/gke-nodepool/variables.tf +++ b/modules/gke-nodepool/variables.tf @@ -14,6 +14,12 @@ * limitations under the License. */ +variable "cluster_id" { + description = "Cluster id. Optional, but providing cluster_id is recommended to prevent cluster misconfiguration in some of the edge cases." + type = string + default = null +} + variable "cluster_name" { description = "Cluster name." type = string