From 1f7ca82025b330bf74d08354e22b8b8e541b27c4 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Wed, 23 Oct 2019 22:24:41 +0000 Subject: [PATCH] Make GKE taint fields available in GA Signed-off-by: Modular Magician --- google/node_config.go | 29 ++++++++++++++++++- google/resource_container_cluster_test.go | 24 +++++++++++++++ google/resource_container_node_pool_test.go | 24 +++++++++++++++ .../docs/r/container_cluster.html.markdown | 11 +++++-- 4 files changed, 84 insertions(+), 4 deletions(-) diff --git a/google/node_config.go b/google/node_config.go index 16ca28a31ab..55f8d9664f5 100644 --- a/google/node_config.go +++ b/google/node_config.go @@ -172,7 +172,6 @@ var schemaNodeConfig = &schema.Schema{ }, "taint": { - Removed: "This field is in beta. Use it in the the google-beta provider instead. See https://terraform.io/docs/providers/google/provider_versions.html for more details.", Type: schema.TypeList, Optional: true, // Computed=true because GKE Sandbox will automatically add taints to nodes that can/cannot run sandboxed pods. @@ -341,6 +340,21 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig { nc.MinCpuPlatform = v.(string) } + if v, ok := nodeConfig["taint"]; ok && len(v.([]interface{})) > 0 { + taints := v.([]interface{}) + nodeTaints := make([]*containerBeta.NodeTaint, 0, len(taints)) + for _, raw := range taints { + data := raw.(map[string]interface{}) + taint := &containerBeta.NodeTaint{ + Key: data["key"].(string), + Value: data["value"].(string), + Effect: data["effect"].(string), + } + nodeTaints = append(nodeTaints, taint) + } + nc.Taints = nodeTaints + } + return nc } @@ -365,6 +379,7 @@ func flattenNodeConfig(c *containerBeta.NodeConfig) []map[string]interface{} { "preemptible": c.Preemptible, "min_cpu_platform": c.MinCpuPlatform, "shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig), + "taint": flattenTaints(c.Taints), }) if len(c.OauthScopes) > 0 { @@ -396,6 +411,18 @@ func flattenShieldedInstanceConfig(c *containerBeta.ShieldedInstanceConfig) []ma return result } +func flattenTaints(c []*containerBeta.NodeTaint) []map[string]interface{} { + result := []map[string]interface{}{} + for _, taint := range c { + result = append(result, map[string]interface{}{ + "key": taint.Key, + "value": taint.Value, + "effect": taint.Effect, + }) + } + return result +} + func taintDiffSuppress(k, old, new string, d *schema.ResourceData) bool { if strings.HasSuffix(k, "#") { oldCount, oldErr := strconv.Atoi(old) diff --git a/google/resource_container_cluster_test.go b/google/resource_container_cluster_test.go index cd7d7ef22fd..2b562877bbc 100644 --- a/google/resource_container_cluster_test.go +++ b/google/resource_container_cluster_test.go @@ -1686,6 +1686,18 @@ resource "google_container_cluster" "with_node_config" { preemptible = true min_cpu_platform = "Intel Broadwell" + taint { + key = "taint_key" + value = "taint_value" + effect = "PREFER_NO_SCHEDULE" + } + + taint { + key = "taint_key2" + value = "taint_value2" + effect = "NO_EXECUTE" + } + // Updatable fields image_type = "COS" } @@ -1722,6 +1734,18 @@ resource "google_container_cluster" "with_node_config" { preemptible = true min_cpu_platform = "Intel Broadwell" + taint { + key = "taint_key" + value = "taint_value" + effect = "PREFER_NO_SCHEDULE" + } + + taint { + key = "taint_key2" + value = "taint_value2" + effect = "NO_EXECUTE" + } + // Updatable fields image_type = "UBUNTU" } diff --git a/google/resource_container_node_pool_test.go b/google/resource_container_node_pool_test.go index 914e8356f6a..548c512af8d 100644 --- a/google/resource_container_node_pool_test.go +++ b/google/resource_container_node_pool_test.go @@ -840,6 +840,18 @@ resource "google_container_node_pool" "np_with_node_config" { preemptible = true min_cpu_platform = "Intel Broadwell" + taint { + key = "taint_key" + value = "taint_value" + effect = "PREFER_NO_SCHEDULE" + } + + taint { + key = "taint_key2" + value = "taint_value2" + effect = "NO_EXECUTE" + } + // Updatable fields image_type = "COS" } @@ -870,6 +882,18 @@ resource "google_container_node_pool" "np_with_node_config" { preemptible = true min_cpu_platform = "Intel Broadwell" + taint { + key = "taint_key" + value = "taint_value" + effect = "PREFER_NO_SCHEDULE" + } + + taint { + key = "taint_key2" + value = "taint_value2" + effect = "NO_EXECUTE" + } + // Updatable fields image_type = "UBUNTU" } diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index c95311f9eb2..6193ac57f9f 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -567,9 +567,14 @@ The `node_config` block supports: * `tags` - (Optional) The list of instance tags applied to all nodes. Tags are used to identify valid sources or targets for network firewalls. -* `taint` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) List of - [kubernetes taints](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) - to apply to each node. Structure is documented below. +* `taint` - (Optional) A list of [Kubernetes taints](https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/) +to apply to nodes. GKE's API can only set this field on cluster creation. +However, GKE will add taints to your nodes if you enable certain features such +as GPUs. If this field is set, any diffs on this field will cause Terraform to +recreate the underlying resource. Taint values can be updated safely in +Kubernetes (eg. through `kubectl`), and it's recommended that you do not use +this field to manage taints. If you do, `lifecycle.ignore_changes` is +recommended. Structure is documented below. * `workload_metadata_config` - (Optional, [Beta](https://terraform.io/docs/providers/google/provider_versions.html)) Metadata configuration to expose to workloads on the node pool. Structure is documented below.