Skip to content

Commit c0f5881

Browse files
authored
feat:adds placement policy argument to the beta modules (terraform-google-modules#1385)
1 parent 1fd7184 commit c0f5881

File tree

12 files changed

+66
-4
lines changed

12 files changed

+66
-4
lines changed

autogen/main/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ The node_pools variable takes the following parameters:
213213
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
214214
| name | The name of the node pool | | Required |
215215
{% if beta_cluster %}
216+
| 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 |
216217
| pod_range | The ID of the secondary range for pod IPs. | | Optional |
217218
{% endif %}
218219
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required |

autogen/main/cluster.tf.tmpl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,13 @@ resource "google_container_node_pool" "pools" {
613613
}
614614

615615
{% if beta_cluster %}
616+
dynamic "placement_policy" {
617+
for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : []
618+
content {
619+
type = lookup(placement_policy.value, "placement_policy", null)
620+
}
621+
}
622+
616623
dynamic "network_config" {
617624
for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : []
618625
content {

modules/beta-private-cluster-update-variant/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ The node_pools variable takes the following parameters:
334334
| 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 |
335335
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
336336
| name | The name of the node pool | | Required |
337+
| 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 |
337338
| pod_range | The ID of the secondary range for pod IPs. | | Optional |
338339
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required |
339340
| 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 |

modules/beta-private-cluster-update-variant/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,13 @@ resource "google_container_node_pool" "pools" {
540540
}
541541
}
542542

543+
dynamic "placement_policy" {
544+
for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : []
545+
content {
546+
type = lookup(placement_policy.value, "placement_policy", null)
547+
}
548+
}
549+
543550
dynamic "network_config" {
544551
for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : []
545552
content {

modules/beta-private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ The node_pools variable takes the following parameters:
312312
| 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 |
313313
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
314314
| name | The name of the node pool | | Required |
315+
| 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 |
315316
| pod_range | The ID of the secondary range for pod IPs. | | Optional |
316317
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required |
317318
| 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 |

modules/beta-private-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,13 @@ resource "google_container_node_pool" "pools" {
449449
}
450450
}
451451

452+
dynamic "placement_policy" {
453+
for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : []
454+
content {
455+
type = lookup(placement_policy.value, "placement_policy", null)
456+
}
457+
}
458+
452459
dynamic "network_config" {
453460
for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : []
454461
content {

modules/beta-public-cluster-update-variant/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ The node_pools variable takes the following parameters:
321321
| 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 |
322322
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
323323
| name | The name of the node pool | | Required |
324+
| 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 |
324325
| pod_range | The ID of the secondary range for pod IPs. | | Optional |
325326
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required |
326327
| 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 |

modules/beta-public-cluster-update-variant/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,13 @@ resource "google_container_node_pool" "pools" {
521521
}
522522
}
523523

524+
dynamic "placement_policy" {
525+
for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : []
526+
content {
527+
type = lookup(placement_policy.value, "placement_policy", null)
528+
}
529+
}
530+
524531
dynamic "network_config" {
525532
for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : []
526533
content {

modules/beta-public-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ The node_pools variable takes the following parameters:
299299
| 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 |
300300
| min_count | Minimum number of nodes in the NodePool. Must be >=0 and <= max_count. Should be used when autoscaling is true | 1 | Optional |
301301
| name | The name of the node pool | | Required |
302+
| 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 |
302303
| pod_range | The ID of the secondary range for pod IPs. | | Optional |
303304
| node_count | The number of nodes in the nodepool when autoscaling is false. Otherwise defaults to 1. Only valid for non-autoscaling clusters | | Required |
304305
| 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 |

modules/beta-public-cluster/cluster.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,13 @@ resource "google_container_node_pool" "pools" {
430430
}
431431
}
432432

433+
dynamic "placement_policy" {
434+
for_each = length(lookup(each.value, "placement_policy", "")) > 0 ? [each.value] : []
435+
content {
436+
type = lookup(placement_policy.value, "placement_policy", null)
437+
}
438+
}
439+
433440
dynamic "network_config" {
434441
for_each = length(lookup(each.value, "pod_range", "")) > 0 ? [each.value] : []
435442
content {

test/fixtures/beta_cluster/main.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ module "this" {
4444
ip_range_services = google_compute_subnetwork.main.secondary_ip_range[1].range_name
4545
compute_engine_service_account = "create"
4646

47+
node_pools = [
48+
{
49+
name = "pool-01"
50+
machine_type = "n2-standard-2"
51+
min_count = 1
52+
max_count = 2
53+
auto_upgrade = true
54+
// Beta feature
55+
placement_policy = "COMPACT"
56+
},
57+
]
58+
4759
// Beta features
4860
istio = true
4961

test/integration/beta_cluster/controls/gcloud.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
expect(node_pools).to include(
168168
including(
169169
"autoscaling" => including(
170-
"maxNodeCount" => 100,
170+
"maxNodeCount" => 2,
171171
),
172172
)
173173
)
@@ -177,7 +177,7 @@
177177
expect(node_pools).to include(
178178
including(
179179
"config" => including(
180-
"machineType" => "e2-medium",
180+
"machineType" => "n2-standard-2",
181181
),
182182
)
183183
)
@@ -199,7 +199,7 @@
199199
"config" => including(
200200
"labels" => including(
201201
"cluster_name" => cluster_name,
202-
"node_pool" => "default-node-pool",
202+
"node_pool" => "pool-01",
203203
),
204204
),
205205
)
@@ -212,7 +212,7 @@
212212
"config" => including(
213213
"tags" => match_array([
214214
"gke-#{cluster_name}",
215-
"gke-#{cluster_name}-default-node-pool",
215+
"gke-#{cluster_name}-pool-01",
216216
]),
217217
),
218218
)
@@ -228,6 +228,16 @@
228228
)
229229
)
230230
end
231+
232+
it "has placement policy set to COMPACT" do
233+
expect(node_pools).to include(
234+
including(
235+
"placementPolicy" => including(
236+
"type" => "COMPACT",
237+
),
238+
)
239+
)
240+
end
231241
end
232242
end
233243
end

0 commit comments

Comments
 (0)