Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: node_pools_cgroup_mode var does not correctly handle the "all" map key #2224

Merged
merged 12 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -1111,6 +1111,7 @@ resource "google_container_node_pool" "windows_pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : {cgroup = local.node_pools_cgroup_mode[each.value["name"]]}
)) != 0 ? [1] : []

Expand All @@ -1119,7 +1120,7 @@ resource "google_container_node_pool" "windows_pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}
{% endif %}
Expand Down
17 changes: 9 additions & 8 deletions autogen/main/variables_defaults.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,15 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)
node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : ""]
),
var.node_pools_cgroup_mode

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
zipmap(
[for node_pool in var.node_pools : node_pool["name"]],
[for node_pool in var.node_pools : ""]
),
var.node_pools_cgroup_mode
)
}
{% endif %}
3 changes: 2 additions & 1 deletion cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -812,7 +813,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
5 changes: 5 additions & 0 deletions examples/node_pool/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,9 @@ module "gke" {
"net.core.netdev_max_backlog" = "20000"
}
}

node_pools_cgroup_mode = {
all = "CGROUP_MODE_V1"
pool-01 = "CGROUP_MODE_V2"
apeabody marked this conversation as resolved.
Show resolved Hide resolved
}
}
3 changes: 2 additions & 1 deletion modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -983,7 +984,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -902,7 +903,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/beta-private-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -953,7 +954,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
3 changes: 2 additions & 1 deletion modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -872,7 +873,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/beta-public-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
3 changes: 2 additions & 1 deletion modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -922,7 +923,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
3 changes: 2 additions & 1 deletion modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,7 @@ resource "google_container_node_pool" "pools" {
for_each = length(merge(
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]],
local.node_pools_cgroup_mode["all"] == "" ? {} : { cgroup = local.node_pools_cgroup_mode["all"] },
local.node_pools_cgroup_mode[each.value["name"]] == "" ? {} : { cgroup = local.node_pools_cgroup_mode[each.value["name"]] }
)) != 0 ? [1] : []

Expand All @@ -842,7 +843,7 @@ resource "google_container_node_pool" "pools" {
local.node_pools_linux_node_configs_sysctls["all"],
local.node_pools_linux_node_configs_sysctls[each.value["name"]]
)
cgroup_mode = local.node_pools_cgroup_mode[each.value["name"]] == "" ? null : local.node_pools_cgroup_mode[each.value["name"]]
cgroup_mode = coalesce(local.node_pools_cgroup_mode[each.value["name"]], local.node_pools_cgroup_mode["all"], null)
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
10 changes: 5 additions & 5 deletions test/integration/node_pool/testdata/TestNodePool.json
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@
"config": {
"diskSizeGb": 100,
"diskType": "pd-standard",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V2",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V1",
"imageType": "COS_CONTAINERD",
"machineType": "e2-medium",
"metadata": {
Expand Down Expand Up @@ -425,7 +425,7 @@
],
"diskSizeGb": 30,
"diskType": "pd-standard",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V2",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V1",
"imageType": "COS_CONTAINERD",
"labels": {
"all-pools-example": "true",
Expand Down Expand Up @@ -505,7 +505,7 @@
"config": {
"diskSizeGb": 100,
"diskType": "pd-standard",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V2",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V1",
"imageType": "COS_CONTAINERD",
"kubeletConfig": {
"cpuCfsQuota": true,
Expand Down Expand Up @@ -603,7 +603,7 @@
"config": {
"diskSizeGb": 100,
"diskType": "pd-standard",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V2",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V1",
"imageType": "COS_CONTAINERD",
"labels": {
"all-pools-example": "true",
Expand Down Expand Up @@ -698,7 +698,7 @@
},
"diskSizeGb": 100,
"diskType": "pd-standard",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V2",
"effectiveCgroupMode": "EFFECTIVE_CGROUP_MODE_V1",
"imageType": "COS_CONTAINERD",
"labels": {
"all-pools-example": "true",
Expand Down
1 change: 1 addition & 0 deletions variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ locals {
),
var.node_pools_linux_node_configs_sysctls
)

node_pools_cgroup_mode = merge(
{ all = "" },
{ default-node-pool = "" },
Expand Down
Loading