Skip to content

Commit

Permalink
feat: Add support for gVisor per node pool (#1001)
Browse files Browse the repository at this point in the history
* feat: Add support for gVisor per node pool

* fix image type, add test

Co-authored-by: Bharath KKB <[email protected]>
  • Loading branch information
LukaszCzarnotaSabre and bharathkkb committed Oct 18, 2021
1 parent 2c4a2b1 commit 73f39df
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
6 changes: 4 additions & 2 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@ resource "google_container_node_pool" "pools" {
{% endif %}

node_config {
{% if beta_cluster %}
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
{% else %}
image_type = lookup(each.value, "image_type", "COS")
machine_type = lookup(each.value, "machine_type", "e2-medium")
labels = merge(
Expand Down Expand Up @@ -519,8 +522,7 @@ resource "google_container_node_pool" "pools" {
}
{% if beta_cluster %}
dynamic "sandbox_config" {
for_each = local.cluster_sandbox_enabled

for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
content {
sandbox_type = sandbox_config.value
}
Expand Down
4 changes: 3 additions & 1 deletion examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ module "gke" {
},
{
name = "pool-03"
machine_type = "n1-standard-2"
node_locations = "${var.region}-b,${var.region}-c"
autoscaling = false
node_count = 2
disk_type = "pd-standard"
image_type = "COS"
auto_upgrade = true
service_account = var.compute_engine_service_account
pod_range = "test"
sandbox_enabled = true
},
]

Expand Down
5 changes: 2 additions & 3 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ resource "google_container_node_pool" "pools" {
}

node_config {
image_type = lookup(each.value, "image_type", "COS")
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
machine_type = lookup(each.value, "machine_type", "e2-medium")
labels = merge(
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
Expand Down Expand Up @@ -475,8 +475,7 @@ resource "google_container_node_pool" "pools" {
}
}
dynamic "sandbox_config" {
for_each = local.cluster_sandbox_enabled

for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
content {
sandbox_type = sandbox_config.value
}
Expand Down
5 changes: 2 additions & 3 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ resource "google_container_node_pool" "pools" {
}

node_config {
image_type = lookup(each.value, "image_type", "COS")
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
machine_type = lookup(each.value, "machine_type", "e2-medium")
labels = merge(
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
Expand Down Expand Up @@ -403,8 +403,7 @@ resource "google_container_node_pool" "pools" {
}
}
dynamic "sandbox_config" {
for_each = local.cluster_sandbox_enabled

for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
content {
sandbox_type = sandbox_config.value
}
Expand Down
5 changes: 2 additions & 3 deletions modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ resource "google_container_node_pool" "pools" {
}

node_config {
image_type = lookup(each.value, "image_type", "COS")
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
machine_type = lookup(each.value, "machine_type", "e2-medium")
labels = merge(
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
Expand Down Expand Up @@ -456,8 +456,7 @@ resource "google_container_node_pool" "pools" {
}
}
dynamic "sandbox_config" {
for_each = local.cluster_sandbox_enabled

for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
content {
sandbox_type = sandbox_config.value
}
Expand Down
5 changes: 2 additions & 3 deletions modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ resource "google_container_node_pool" "pools" {
}

node_config {
image_type = lookup(each.value, "image_type", "COS")
image_type = lookup(each.value, "image_type", lookup(each.value, "sandbox_enabled", var.sandbox_enabled) ? "COS_CONTAINERD" : "COS")
machine_type = lookup(each.value, "machine_type", "e2-medium")
labels = merge(
lookup(lookup(local.node_pools_labels, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
Expand Down Expand Up @@ -384,8 +384,7 @@ resource "google_container_node_pool" "pools" {
}
}
dynamic "sandbox_config" {
for_each = local.cluster_sandbox_enabled

for_each = tobool((lookup(each.value, "sandbox_enabled", var.sandbox_enabled))) ? ["gvisor"] : []
content {
sandbox_type = sandbox_config.value
}
Expand Down
41 changes: 40 additions & 1 deletion test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
including(
"name" => "pool-03",
"config" => including(
"machineType" => "e2-medium",
"machineType" => "n1-standard-2",
),
)
)
Expand Down Expand Up @@ -376,6 +376,7 @@
"all-pools-example" => "true",
"cluster_name" => cluster_name,
"node_pool" => "pool-03",
"sandbox.gke.io/runtime"=>"gvisor"
},
),
)
Expand All @@ -396,6 +397,44 @@
)
)
end

it "has the expected pod range" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"networkConfig" => including(
"podIpv4CidrBlock" => "172.16.0.0/18",
"podRange" => "test"
)
)
)
end

it "has the expected image" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"imageType" => "COS_CONTAINERD",
),
)
)
end

it "has the expected linux node config sysctls" do
expect(data['nodePools']).to include(
including(
"name" => "pool-03",
"config" => including(
"linuxNodeConfig" => including(
"sysctls" => including(
"net.core.netdev_max_backlog" => "20000"
)
)
)
)
)
end
end
end
end
Expand Down

0 comments on commit 73f39df

Please sign in to comment.