Skip to content

Commit 850c418

Browse files
feat: Add support for gVisor per node pool (#1001)
* feat: Add support for gVisor per node pool * fix image type, add test Co-authored-by: Bharath KKB <[email protected]>
1 parent d2f1105 commit 850c418

File tree

12 files changed

+25
-27
lines changed

12 files changed

+25
-27
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ resource "google_container_node_pool" "pools" {
495495

496496
node_config {
497497
{% if beta_cluster %}
498-
image_type = lookup(each.value, "image_type", var.sandbox_enabled ? "COS_CONTAINERD" : "COS")
498+
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
499499
{% else %}
500500
image_type = lookup(each.value, "image_type", "COS")
501501
{% endif %}
@@ -577,8 +577,7 @@ resource "google_container_node_pool" "pools" {
577577
}
578578
{% if beta_cluster %}
579579
dynamic "sandbox_config" {
580-
for_each = local.cluster_sandbox_enabled
581-
580+
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
582581
content {
583582
sandbox_type = sandbox_config.value
584583
}

autogen/main/main.tf.tmpl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ locals {
105105

106106
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
107107

108-
cluster_sandbox_enabled = var.sandbox_enabled ? ["gvisor"] : []
109-
110108
{% endif %}
111109

112110
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{

examples/node_pool/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ module "gke" {
7070
},
7171
{
7272
name = "pool-03"
73+
machine_type = "n1-standard-2"
7374
node_locations = "${var.region}-b,${var.region}-c"
7475
autoscaling = false
7576
node_count = 2
7677
disk_type = "pd-standard"
77-
image_type = "COS"
7878
auto_upgrade = true
7979
service_account = var.compute_engine_service_account
8080
pod_range = "test"
81+
sandbox_enabled = true
8182
},
8283
]
8384

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ resource "google_container_node_pool" "pools" {
447447
}
448448

449449
node_config {
450-
image_type = lookup(each.value, "image_type", var.sandbox_enabled ? "COS_CONTAINERD" : "COS")
450+
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
451451
machine_type = lookup(each.value, "machine_type", "e2-medium")
452452
labels = merge(
453453
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
@@ -523,8 +523,7 @@ resource "google_container_node_pool" "pools" {
523523
}
524524
}
525525
dynamic "sandbox_config" {
526-
for_each = local.cluster_sandbox_enabled
527-
526+
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
528527
content {
529528
sandbox_type = sandbox_config.value
530529
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ locals {
9696

9797
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
9898

99-
cluster_sandbox_enabled = var.sandbox_enabled ? ["gvisor"] : []
100-
10199

102100
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
103101
security_group = var.authenticator_security_group

modules/beta-private-cluster/cluster.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ resource "google_container_node_pool" "pools" {
363363
}
364364

365365
node_config {
366-
image_type = lookup(each.value, "image_type", var.sandbox_enabled ? "COS_CONTAINERD" : "COS")
366+
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
367367
machine_type = lookup(each.value, "machine_type", "e2-medium")
368368
labels = merge(
369369
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
@@ -439,8 +439,7 @@ resource "google_container_node_pool" "pools" {
439439
}
440440
}
441441
dynamic "sandbox_config" {
442-
for_each = local.cluster_sandbox_enabled
443-
442+
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
444443
content {
445444
sandbox_type = sandbox_config.value
446445
}

modules/beta-private-cluster/main.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ locals {
9696

9797
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
9898

99-
cluster_sandbox_enabled = var.sandbox_enabled ? ["gvisor"] : []
100-
10199

102100
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
103101
security_group = var.authenticator_security_group

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ resource "google_container_node_pool" "pools" {
428428
}
429429

430430
node_config {
431-
image_type = lookup(each.value, "image_type", var.sandbox_enabled ? "COS_CONTAINERD" : "COS")
431+
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
432432
machine_type = lookup(each.value, "machine_type", "e2-medium")
433433
labels = merge(
434434
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
@@ -504,8 +504,7 @@ resource "google_container_node_pool" "pools" {
504504
}
505505
}
506506
dynamic "sandbox_config" {
507-
for_each = local.cluster_sandbox_enabled
508-
507+
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
509508
content {
510509
sandbox_type = sandbox_config.value
511510
}

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ locals {
9696

9797
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
9898

99-
cluster_sandbox_enabled = var.sandbox_enabled ? ["gvisor"] : []
100-
10199

102100
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
103101
security_group = var.authenticator_security_group

modules/beta-public-cluster/cluster.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ resource "google_container_node_pool" "pools" {
344344
}
345345

346346
node_config {
347-
image_type = lookup(each.value, "image_type", var.sandbox_enabled ? "COS_CONTAINERD" : "COS")
347+
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
348348
machine_type = lookup(each.value, "machine_type", "e2-medium")
349349
labels = merge(
350350
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
@@ -420,8 +420,7 @@ resource "google_container_node_pool" "pools" {
420420
}
421421
}
422422
dynamic "sandbox_config" {
423-
for_each = local.cluster_sandbox_enabled
424-
423+
for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
425424
content {
426425
sandbox_type = sandbox_config.value
427426
}

modules/beta-public-cluster/main.tf

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ locals {
9696

9797
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
9898

99-
cluster_sandbox_enabled = var.sandbox_enabled ? ["gvisor"] : []
100-
10199

102100
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
103101
security_group = var.authenticator_security_group

test/integration/node_pool/controls/gcloud.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@
351351
including(
352352
"name" => "pool-03",
353353
"config" => including(
354-
"machineType" => "e2-medium",
354+
"machineType" => "n1-standard-2",
355355
),
356356
)
357357
)
@@ -408,6 +408,7 @@
408408
"all-pools-example" => "true",
409409
"cluster_name" => cluster_name,
410410
"node_pool" => "pool-03",
411+
"sandbox.gke.io/runtime"=>"gvisor"
411412
},
412413
),
413414
)
@@ -441,6 +442,17 @@
441442
)
442443
end
443444

445+
it "has the expected image" do
446+
expect(data['nodePools']).to include(
447+
including(
448+
"name" => "pool-03",
449+
"config" => including(
450+
"imageType" => "COS_CONTAINERD",
451+
),
452+
)
453+
)
454+
end
455+
444456
it "has the expected linux node config sysctls" do
445457
expect(data['nodePools']).to include(
446458
including(

0 commit comments

Comments
 (0)