diff --git a/autogen/main/README.md b/autogen/main/README.md index bce0a854e3..b2482f977d 100644 --- a/autogen/main/README.md +++ b/autogen/main/README.md @@ -213,6 +213,7 @@ The node_pools variable takes the following parameters: | min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional | | name | The name of the node pool | | Required | {% if beta_cluster %} +| placement_policy | Placement type to set for nodes in a node pool. Can be set as [COMPACT](https://cloud.google.com/kubernetes-engine/docs/how-to/compact-placement#overview) if desired | Optional | | pod_range | The ID of the secondary range for pod IPs. | | Optional | {% endif %} | node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required | diff --git a/autogen/main/cluster.tf.tmpl b/autogen/main/cluster.tf.tmpl index 5f68a77d2a..64d3567a61 100644 --- a/autogen/main/cluster.tf.tmpl +++ b/autogen/main/cluster.tf.tmpl @@ -613,6 +613,13 @@ resource "google_container_node_pool" "pools" { } {% if beta_cluster %} + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/modules/beta-private-cluster-update-variant/README.md b/modules/beta-private-cluster-update-variant/README.md index ef95ab409e..cacb841390 100644 --- a/modules/beta-private-cluster-update-variant/README.md +++ b/modules/beta-private-cluster-update-variant/README.md @@ -334,6 +334,7 @@ The node_pools variable takes the following parameters: | max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional | | min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional | | name | The name of the node pool | | Required | +| placement_policy | Placement type to set for nodes in a node pool. Can be set as [COMPACT](https://cloud.google.com/kubernetes-engine/docs/how-to/compact-placement#overview) if desired | Optional | | pod_range | The ID of the secondary range for pod IPs. | | Optional | | node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required | | node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional | diff --git a/modules/beta-private-cluster-update-variant/cluster.tf b/modules/beta-private-cluster-update-variant/cluster.tf index c021af1f67..34d1a1e1cf 100644 --- a/modules/beta-private-cluster-update-variant/cluster.tf +++ b/modules/beta-private-cluster-update-variant/cluster.tf @@ -540,6 +540,13 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/modules/beta-private-cluster/README.md b/modules/beta-private-cluster/README.md index 512e50367b..cf3fe7381c 100644 --- a/modules/beta-private-cluster/README.md +++ b/modules/beta-private-cluster/README.md @@ -312,6 +312,7 @@ The node_pools variable takes the following parameters: | max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional | | min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional | | name | The name of the node pool | | Required | +| placement_policy | Placement type to set for nodes in a node pool. Can be set as [COMPACT](https://cloud.google.com/kubernetes-engine/docs/how-to/compact-placement#overview) if desired | Optional | | pod_range | The ID of the secondary range for pod IPs. | | Optional | | node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required | | node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional | diff --git a/modules/beta-private-cluster/cluster.tf b/modules/beta-private-cluster/cluster.tf index fed5ed5b72..37a9b6b8ef 100644 --- a/modules/beta-private-cluster/cluster.tf +++ b/modules/beta-private-cluster/cluster.tf @@ -449,6 +449,13 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/modules/beta-public-cluster-update-variant/README.md b/modules/beta-public-cluster-update-variant/README.md index d0e1b7380f..bc6a5bdfcd 100644 --- a/modules/beta-public-cluster-update-variant/README.md +++ b/modules/beta-public-cluster-update-variant/README.md @@ -321,6 +321,7 @@ The node_pools variable takes the following parameters: | max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional | | min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional | | name | The name of the node pool | | Required | +| placement_policy | Placement type to set for nodes in a node pool. Can be set as [COMPACT](https://cloud.google.com/kubernetes-engine/docs/how-to/compact-placement#overview) if desired | Optional | | pod_range | The ID of the secondary range for pod IPs. | | Optional | | node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required | | node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional | diff --git a/modules/beta-public-cluster-update-variant/cluster.tf b/modules/beta-public-cluster-update-variant/cluster.tf index 9bc1020c95..68ef8dad72 100644 --- a/modules/beta-public-cluster-update-variant/cluster.tf +++ b/modules/beta-public-cluster-update-variant/cluster.tf @@ -521,6 +521,13 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/modules/beta-public-cluster/README.md b/modules/beta-public-cluster/README.md index 27b6152267..a2d47544ac 100644 --- a/modules/beta-public-cluster/README.md +++ b/modules/beta-public-cluster/README.md @@ -299,6 +299,7 @@ The node_pools variable takes the following parameters: | max_unavailable | The number of nodes that can be simultaneously unavailable during an upgrade. Increasing max_unavailable raises the number of nodes that can be upgraded in parallel. Can be set to 0 or greater. | 0 | Optional | | min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional | | name | The name of the node pool | | Required | +| placement_policy | Placement type to set for nodes in a node pool. Can be set as [COMPACT](https://cloud.google.com/kubernetes-engine/docs/how-to/compact-placement#overview) if desired | Optional | | pod_range | The ID of the secondary range for pod IPs. | | Optional | | node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required | | node_locations | The list of zones in which the cluster's nodes are located. Nodes must be in the region of their regional cluster or in the same region as their cluster's zone for zonal clusters. Defaults to cluster level node locations if nothing is specified | " " | Optional | diff --git a/modules/beta-public-cluster/cluster.tf b/modules/beta-public-cluster/cluster.tf index a44396fe19..345aa6013f 100644 --- a/modules/beta-public-cluster/cluster.tf +++ b/modules/beta-public-cluster/cluster.tf @@ -430,6 +430,13 @@ resource "google_container_node_pool" "pools" { } } + dynamic "placement_policy" { + for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : [] + content { + type = lookup(placement_policy.value, "placement_policy", null) + } + } + dynamic "network_config" { for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : [] content { diff --git a/test/fixtures/beta_cluster/main.tf b/test/fixtures/beta_cluster/main.tf index 2509fdd613..fe6cd61923 100644 --- a/test/fixtures/beta_cluster/main.tf +++ b/test/fixtures/beta_cluster/main.tf @@ -44,6 +44,18 @@ module "this" { ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name compute_engine_service_account = "create" + node_pools = [ + { + name = "pool-01" + machine_type = "n2-standard-2" + min_count = 1 + max_count = 2 + auto_upgrade = true + // Beta feature + placement_policy = "COMPACT" + }, + ] + // Beta features istio = true diff --git a/test/integration/beta_cluster/controls/gcloud.rb b/test/integration/beta_cluster/controls/gcloud.rb index 99f477e099..10d64fc7ab 100644 --- a/test/integration/beta_cluster/controls/gcloud.rb +++ b/test/integration/beta_cluster/controls/gcloud.rb @@ -167,7 +167,7 @@ expect(node_pools).to include( including( "autoscaling" => including( - "maxNodeCount" => 100, + "maxNodeCount" => 2, ), ) ) @@ -177,7 +177,7 @@ expect(node_pools).to include( including( "config" => including( - "machineType" => "e2-medium", + "machineType" => "n2-standard-2", ), ) ) @@ -199,7 +199,7 @@ "config" => including( "labels" => including( "cluster_name" => cluster_name, - "node_pool" => "default-node-pool", + "node_pool" => "pool-01", ), ), ) @@ -212,7 +212,7 @@ "config" => including( "tags" => match_array([ "gke-#{cluster_name}", - "gke-#{cluster_name}-default-node-pool", + "gke-#{cluster_name}-pool-01", ]), ), ) @@ -228,6 +228,16 @@ ) ) end + + it "has placement policy set to COMPACT" do + expect(node_pools).to include( + including( + "placementPolicy" => including( + "type" => "COMPACT", + ), + ) + ) + end end end end