From 8a06ec26952cbdd8e498b6dfd8915176b40dce9b Mon Sep 17 00:00:00 2001 From: Alex R Date: Fri, 12 Nov 2021 00:07:36 +0300 Subject: [PATCH 1/4] Add spotVM for GKE Node Pools Signed-off-by: Alex R --- mmv1/third_party/terraform/utils/node_config.go.erb | 10 ++++++++++ .../website/docs/r/container_cluster.html.markdown | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/mmv1/third_party/terraform/utils/node_config.go.erb b/mmv1/third_party/terraform/utils/node_config.go.erb index 090e317b264c..99887c540637 100644 --- a/mmv1/third_party/terraform/utils/node_config.go.erb +++ b/mmv1/third_party/terraform/utils/node_config.go.erb @@ -204,6 +204,14 @@ func schemaNodeConfig() *schema.Schema { Description: `Whether the nodes are created as preemptible VM instances.`, }, + "spot": { + Type: schema.TypeBool, + Optional: true, + ForceNew: true, + Default: false, + Description: `Whether the nodes are created as spot VM instances.`, + }, + "service_account": { Type: schema.TypeString, Optional: true, @@ -497,6 +505,7 @@ func expandNodeConfig(v interface{}) *container.NodeConfig { // Preemptible Is Optional+Default, so it always has a value nc.Preemptible = nodeConfig["preemptible"].(bool) + nc.Spot = nodeConfig["spot"].(bool) if v, ok := nodeConfig["min_cpu_platform"]; ok { nc.MinCpuPlatform = v.(string) @@ -638,6 +647,7 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} { "labels": c.Labels, "tags": c.Tags, "preemptible": c.Preemptible, + "spot": c.Spot, "min_cpu_platform": c.MinCpuPlatform, "shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig), "taint": flattenTaints(c.Taints), diff --git a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown index 316112f1a5a6..dfc6181d29ab 100644 --- a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -678,6 +678,10 @@ gcfs_config { are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm) for more information. Defaults to false. +* `spot` - (Optional) A boolean that represents whether the underlying node VMs + are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms) + for more information. Defaults to false. + * `sandbox_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods) configuration. When enabling this feature you must specify `image_type = "COS_CONTAINERD"` and `node_version = "1.12.7-gke.17"` or later to use it. Structure is [documented below](#nested_sandbox_config). From 0df93cc500df18b0fe608a5d0159fe0ef972bfcf Mon Sep 17 00:00:00 2001 From: Alex R Date: Fri, 12 Nov 2021 00:35:24 +0300 Subject: [PATCH 2/4] Add spot test Signed-off-by: Alex R --- .../terraform/tests/resource_container_node_pool_test.go.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb index ce1f4cf7c594..b20fb2d950cc 100644 --- a/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb @@ -1478,6 +1478,7 @@ resource "google_container_node_pool" "with_workload_metadata_config" { cluster = google_container_cluster.cluster.name initial_node_count = 1 node_config { + spot = true oauth_scopes = [ "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", From 163836a90cb161742881199efb0d332e265c12db Mon Sep 17 00:00:00 2001 From: Alex R Date: Sat, 13 Nov 2021 12:17:57 +0300 Subject: [PATCH 3/4] Guard for beta only Signed-off-by: Alex R --- .../tests/resource_container_node_pool_test.go.erb | 2 ++ mmv1/third_party/terraform/utils/node_config.go.erb | 6 ++++++ .../website/docs/r/container_cluster.html.markdown | 2 ++ 3 files changed, 10 insertions(+) diff --git a/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb b/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb index b20fb2d950cc..9baab935d66c 100644 --- a/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb +++ b/mmv1/third_party/terraform/tests/resource_container_node_pool_test.go.erb @@ -1478,7 +1478,9 @@ resource "google_container_node_pool" "with_workload_metadata_config" { cluster = google_container_cluster.cluster.name initial_node_count = 1 node_config { +<% unless version == 'ga' -%> spot = true +<% end -%> oauth_scopes = [ "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring", diff --git a/mmv1/third_party/terraform/utils/node_config.go.erb b/mmv1/third_party/terraform/utils/node_config.go.erb index 99887c540637..864cdfb2af65 100644 --- a/mmv1/third_party/terraform/utils/node_config.go.erb +++ b/mmv1/third_party/terraform/utils/node_config.go.erb @@ -204,6 +204,7 @@ func schemaNodeConfig() *schema.Schema { Description: `Whether the nodes are created as preemptible VM instances.`, }, +<% unless version == 'ga' -%> "spot": { Type: schema.TypeBool, Optional: true, @@ -211,6 +212,7 @@ func schemaNodeConfig() *schema.Schema { Default: false, Description: `Whether the nodes are created as spot VM instances.`, }, +<% end -%> "service_account": { Type: schema.TypeString, @@ -505,7 +507,9 @@ func expandNodeConfig(v interface{}) *container.NodeConfig { // Preemptible Is Optional+Default, so it always has a value nc.Preemptible = nodeConfig["preemptible"].(bool) +<% unless version == 'ga' -%> nc.Spot = nodeConfig["spot"].(bool) +<% end -%> if v, ok := nodeConfig["min_cpu_platform"]; ok { nc.MinCpuPlatform = v.(string) @@ -647,7 +651,9 @@ func flattenNodeConfig(c *container.NodeConfig) []map[string]interface{} { "labels": c.Labels, "tags": c.Tags, "preemptible": c.Preemptible, +<% unless version == 'ga' -%> "spot": c.Spot, +<% end -%> "min_cpu_platform": c.MinCpuPlatform, "shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig), "taint": flattenTaints(c.Taints), diff --git a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown index dfc6181d29ab..d6ba56ef4765 100644 --- a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -678,9 +678,11 @@ gcfs_config { are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm) for more information. Defaults to false. +<% unless version == 'ga' -%> * `spot` - (Optional) A boolean that represents whether the underlying node VMs are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms) for more information. Defaults to false. +<% end -%> * `sandbox_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods) configuration. When enabling this feature you must specify `image_type = "COS_CONTAINERD"` and `node_version = "1.12.7-gke.17"` or later to use it. Structure is [documented below](#nested_sandbox_config). From d255bc37ba08029646251b559a346ec9ec65fb0c Mon Sep 17 00:00:00 2001 From: Alex R Date: Sat, 13 Nov 2021 17:37:26 +0300 Subject: [PATCH 4/4] Add beta note to docs Signed-off-by: Alex R --- .../website/docs/r/container_cluster.html.markdown | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown index d6ba56ef4765..689ec9ee6701 100644 --- a/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown +++ b/mmv1/third_party/terraform/website/docs/r/container_cluster.html.markdown @@ -678,11 +678,9 @@ gcfs_config { are preemptible. See the [official documentation](https://cloud.google.com/container-engine/docs/preemptible-vm) for more information. Defaults to false. -<% unless version == 'ga' -%> -* `spot` - (Optional) A boolean that represents whether the underlying node VMs - are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms) - for more information. Defaults to false. -<% end -%> +* `spot` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) A boolean + that represents whether the underlying node VMs are spot. See the [official documentation](https://cloud.google.com/kubernetes-engine/docs/concepts/spot-vms) + for more information. Defaults to false. * `sandbox_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) [GKE Sandbox](https://cloud.google.com/kubernetes-engine/docs/how-to/sandbox-pods) configuration. When enabling this feature you must specify `image_type = "COS_CONTAINERD"` and `node_version = "1.12.7-gke.17"` or later to use it. Structure is [documented below](#nested_sandbox_config).