Skip to content

Commit

Permalink
Make GKE taint GA
Browse files Browse the repository at this point in the history
  • Loading branch information
rileykarson committed Oct 23, 2019
1 parent 89c2b6b commit a7a35e8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 114 deletions.
76 changes: 24 additions & 52 deletions third_party/terraform/tests/resource_container_cluster_test.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -814,33 +814,6 @@ func TestAccContainerCluster_withNodeConfigScopeAlias(t *testing.T) {
})
}

<% unless version.nil? || version == 'ga' -%>
func TestAccContainerCluster_withNodeConfigTaints(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerClusterDestroy,
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withNodeConfigTaints(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_cluster.with_node_config", "node_config.0.taint.#", "2"),
),
},
{
ResourceName: "google_container_cluster.with_node_config",
ImportStateIdPrefix: "us-central1-f/",
ImportState: true,
ImportStateVerify: true,
},
// Once taints are in GA, consider merging this test with the _withNodeConfig test.
},
})
}
<% end -%>

func TestAccContainerCluster_withNodeConfigShieldedInstanceConfig(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -2402,6 +2375,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"
}
Expand Down Expand Up @@ -2438,6 +2423,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"
}
Expand All @@ -2459,31 +2456,6 @@ resource "google_container_cluster" "with_node_config_scope_alias" {
}`, acctest.RandString(10))
}

<% unless version.nil? || version == 'ga' -%>
func testAccContainerCluster_withNodeConfigTaints() string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_config" {
name = "cluster-test-%s"
zone = "us-central1-f"
initial_node_count = 1

node_config {
taint {
key = "taint_key"
value = "taint_value"
effect = "PREFER_NO_SCHEDULE"
}
taint {
key = "taint_key2"
value = "taint_value2"
effect = "NO_EXECUTE"
}
}
}`, acctest.RandString(10))
}
<% end -%>


func testAccContainerCluster_withNodeConfigShieldedInstanceConfig(clusterName string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "with_node_config" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,35 +163,6 @@ func TestAccContainerNodePool_withNodeConfig(t *testing.T) {
})
}

<% unless version.nil? || version == 'ga' -%>
func TestAccContainerNodePool_withNodeConfigTaints(t *testing.T) {
t.Parallel()

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckContainerNodePoolDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccContainerNodePool_withNodeConfigTaints(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_node_pool.np_with_node_config", "node_config.0.taint.#", "2"),
),
},
{
ResourceName: "google_container_node_pool.np_with_node_config",
ImportState: true,
ImportStateVerify: true,
// autoscaling.# = 0 is equivalent to no autoscaling at all,
// but will still cause an import diff
ImportStateVerifyIgnore: []string{"autoscaling.#"},
},
// Once taints are in GA, consider merging this test with the _withNodeConfig test.
},
})
}
<% end -%>

<% unless version.nil? || version == 'ga' -%>
func TestAccContainerNodePool_withWorkloadMetadataConfig(t *testing.T) {
t.Parallel()
Expand Down Expand Up @@ -1034,6 +1005,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"
}
Expand Down Expand Up @@ -1064,40 +1047,23 @@ resource "google_container_node_pool" "np_with_node_config" {
preemptible = true
min_cpu_platform = "Intel Broadwell"

// Updatable fields
image_type = "UBUNTU"
}
}`, cluster, nodePool)
}

<% unless version.nil? || version == 'ga' -%>
func testAccContainerNodePool_withNodeConfigTaints() string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "tf-cluster-nodepool-test-%s"
zone = "us-central1-a"
initial_node_count = 1
}
resource "google_container_node_pool" "np_with_node_config" {
name = "tf-nodepool-test-%s"
zone = "us-central1-a"
cluster = "${google_container_cluster.cluster.name}"
initial_node_count = 1
node_config {
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"
}
}`, acctest.RandString(10), acctest.RandString(10))
}`, cluster, nodePool)
}
<% end -%>

<% unless version.nil? || version == 'ga' -%>
func testAccContainerNodePool_withWorkloadMetadataConfig() string {
Expand Down
9 changes: 1 addition & 8 deletions third_party/terraform/utils/node_config.go.erb
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,6 @@ var schemaNodeConfig = &schema.Schema{
},

"taint": {
<% if version.nil? || version == 'ga' -%>
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.",
<% end -%>
Type: schema.TypeList,
Optional: true,
// Computed=true because GKE Sandbox will automatically add taints to nodes that can/cannot run sandboxed pods.
Expand Down Expand Up @@ -348,7 +345,6 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig {
nc.MinCpuPlatform = v.(string)
}

<% unless version == 'ga' -%>
if v, ok := nodeConfig["taint"]; ok && len(v.([]interface{})) > 0 {
taints := v.([]interface{})
nodeTaints := make([]*containerBeta.NodeTaint, 0, len(taints))
Expand All @@ -363,7 +359,6 @@ func expandNodeConfig(v interface{}) *containerBeta.NodeConfig {
}
nc.Taints = nodeTaints
}
<% end -%>

<% unless version == 'ga' -%>
if v, ok := nodeConfig["workload_metadata_config"]; ok && len(v.([]interface{})) > 0 {
Expand Down Expand Up @@ -405,8 +400,8 @@ func flattenNodeConfig(c *containerBeta.NodeConfig) []map[string]interface{} {
"preemptible": c.Preemptible,
"min_cpu_platform": c.MinCpuPlatform,
"shielded_instance_config": flattenShieldedInstanceConfig(c.ShieldedInstanceConfig),
<% unless version == 'ga' -%>
"taint": flattenTaints(c.Taints),
<% unless version == 'ga' -%>
"workload_metadata_config": flattenWorkloadMetadataConfig(c.WorkloadMetadataConfig),
"sandbox_config": flattenSandboxConfig(c.SandboxConfig),
<% end -%>
Expand Down Expand Up @@ -441,7 +436,6 @@ func flattenShieldedInstanceConfig(c *containerBeta.ShieldedInstanceConfig) []ma
return result
}

<% unless version.nil? || version == 'ga' -%>
func flattenTaints(c []*containerBeta.NodeTaint) []map[string]interface{} {
result := []map[string]interface{}{}
for _, taint := range c {
Expand All @@ -453,7 +447,6 @@ func flattenTaints(c []*containerBeta.NodeTaint) []map[string]interface{} {
}
return result
}
<% end -%>

<% unless version.nil? || version == 'ga' -%>
func flattenWorkloadMetadataConfig(c *containerBeta.WorkloadMetadataConfig) []map[string]interface{} {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a7a35e8

Please sign in to comment.