Skip to content

Commit afae604

Browse files
feat(container_node_pool): support cgroup mode (#8997) (#16103)
[upstream:8fa653aed5646ee55483612fa4d1a0706eb326bb] Signed-off-by: Tsubasa Nagasawa <[email protected]> Signed-off-by: Modular Magician <[email protected]>
1 parent 3e9b7cf commit afae604

File tree

4 files changed

+124
-21
lines changed

4 files changed

+124
-21
lines changed

.changelog/8997.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `node_config.linux_node_config.cgroup_mode` field to `google_container_node_pool`
3+
```

google/services/container/node_config.go

+37-6
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,18 @@ func schemaNodeConfig() *schema.Schema {
501501
Schema: map[string]*schema.Schema{
502502
"sysctls": {
503503
Type: schema.TypeMap,
504-
Required: true,
504+
Optional: true,
505505
Elem: &schema.Schema{Type: schema.TypeString},
506506
Description: `The Linux kernel parameters to be applied to the nodes and all pods running on the nodes.`,
507507
},
508+
"cgroup_mode": {
509+
Type: schema.TypeString,
510+
Optional: true,
511+
Computed: true,
512+
ValidateFunc: validation.StringInSlice([]string{"CGROUP_MODE_UNSPECIFIED", "CGROUP_MODE_V1", "CGROUP_MODE_V2"}, false),
513+
Description: `cgroupMode specifies the cgroup mode to be used on the node.`,
514+
DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("CGROUP_MODE_UNSPECIFIED"),
515+
},
508516
},
509517
},
510518
},
@@ -950,17 +958,39 @@ func expandLinuxNodeConfig(v interface{}) *container.LinuxNodeConfig {
950958
return &container.LinuxNodeConfig{}
951959
}
952960
cfg := ls[0].(map[string]interface{})
961+
962+
linuxNodeConfig := &container.LinuxNodeConfig{}
963+
sysctls := expandSysctls(cfg)
964+
if sysctls != nil {
965+
linuxNodeConfig.Sysctls = sysctls
966+
}
967+
cgroupMode := expandCgroupMode(cfg)
968+
if len(cgroupMode) != 0 {
969+
linuxNodeConfig.CgroupMode = cgroupMode
970+
}
971+
972+
return linuxNodeConfig
973+
}
974+
975+
func expandSysctls(cfg map[string]interface{}) map[string]string {
953976
sysCfgRaw, ok := cfg["sysctls"]
954977
if !ok {
955978
return nil
956979
}
957-
m := make(map[string]string)
980+
sysctls := make(map[string]string)
958981
for k, v := range sysCfgRaw.(map[string]interface{}) {
959-
m[k] = v.(string)
982+
sysctls[k] = v.(string)
960983
}
961-
return &container.LinuxNodeConfig{
962-
Sysctls: m,
984+
return sysctls
985+
}
986+
987+
func expandCgroupMode(cfg map[string]interface{}) string {
988+
cgroupMode, ok := cfg["cgroup_mode"]
989+
if !ok {
990+
return ""
963991
}
992+
993+
return cgroupMode.(string)
964994
}
965995

966996
func expandSoleTenantConfig(v interface{}) *container.SoleTenantConfig {
@@ -1249,7 +1279,8 @@ func flattenLinuxNodeConfig(c *container.LinuxNodeConfig) []map[string]interface
12491279
result := []map[string]interface{}{}
12501280
if c != nil {
12511281
result = append(result, map[string]interface{}{
1252-
"sysctls": c.Sysctls,
1282+
"sysctls": c.Sysctls,
1283+
"cgroup_mode": c.CgroupMode,
12531284
})
12541285
}
12551286
return result

google/services/container/resource_container_node_pool_test.go

+65
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,38 @@ func TestAccContainerNodePool_withLinuxNodeConfig(t *testing.T) {
441441
})
442442
}
443443

444+
func TestAccContainerNodePool_withCgroupMode(t *testing.T) {
445+
t.Parallel()
446+
447+
cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
448+
np := fmt.Sprintf("tf-test-np-%s", acctest.RandString(t, 10))
449+
450+
acctest.VcrTest(t, resource.TestCase{
451+
PreCheck: func() { acctest.AccTestPreCheck(t) },
452+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
453+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
454+
Steps: []resource.TestStep{
455+
{
456+
Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_V2"),
457+
},
458+
{
459+
ResourceName: "google_container_node_pool.np",
460+
ImportState: true,
461+
ImportStateVerify: true,
462+
},
463+
// Perform an update.
464+
{
465+
Config: testAccContainerNodePool_withCgroupMode(cluster, np, "CGROUP_MODE_UNSPECIFIED"),
466+
},
467+
{
468+
ResourceName: "google_container_node_pool.np",
469+
ImportState: true,
470+
ImportStateVerify: true,
471+
},
472+
},
473+
})
474+
}
475+
444476
func TestAccContainerNodePool_withNetworkConfig(t *testing.T) {
445477
t.Parallel()
446478

@@ -2452,6 +2484,39 @@ resource "google_container_node_pool" "with_linux_node_config" {
24522484
`, cluster, np, linuxNodeConfig)
24532485
}
24542486

2487+
func testAccContainerNodePool_withCgroupMode(cluster, np string, mode string) string {
2488+
return fmt.Sprintf(`
2489+
data "google_container_engine_versions" "central1a" {
2490+
location = "us-central1-a"
2491+
}
2492+
2493+
resource "google_container_cluster" "cluster" {
2494+
name = "%s"
2495+
location = "us-central1-a"
2496+
initial_node_count = 1
2497+
min_master_version = data.google_container_engine_versions.central1a.latest_master_version
2498+
deletion_protection = false
2499+
}
2500+
2501+
resource "google_container_node_pool" "np" {
2502+
name = "%s"
2503+
location = "us-central1-a"
2504+
cluster = google_container_cluster.cluster.name
2505+
initial_node_count = 1
2506+
node_config {
2507+
image_type = "COS_CONTAINERD"
2508+
linux_node_config {
2509+
cgroup_mode = "%s"
2510+
}
2511+
oauth_scopes = [
2512+
"https://www.googleapis.com/auth/logging.write",
2513+
"https://www.googleapis.com/auth/monitoring",
2514+
]
2515+
}
2516+
}
2517+
`, cluster, np, mode)
2518+
}
2519+
24552520
func testAccContainerNodePool_withNetworkConfig(cluster, np, network string) string {
24562521
return fmt.Sprintf(`
24572522
resource "google_compute_network" "container_network" {

website/docs/r/container_cluster.html.markdown

+19-15
Original file line numberDiff line numberDiff line change
@@ -920,19 +920,7 @@ kubelet_config {
920920
}
921921
```
922922

923-
* `linux_node_config` - (Optional)
924-
Linux node configuration, currently supported attributes can be found [here](https://cloud.google.com/sdk/gcloud/reference/beta/container/node-pools/create#--system-config-from-file).
925-
Note that validations happen all server side. All attributes are optional.
926-
Structure is [documented below](#nested_linux_node_config).
927-
928-
```hcl
929-
linux_node_config {
930-
sysctls = {
931-
"net.core.netdev_max_backlog" = "10000"
932-
"net.core.rmem_max" = "10000"
933-
}
934-
}
935-
```
923+
* `linux_node_config` - (Optional) Parameters that can be configured on Linux nodes. Structure is [documented below](#nested_linux_node_config).
936924

937925
* `node_group` - (Optional) Setting this field will assign instances of this pool to run on the specified node group. This is useful for running workloads on [sole tenant nodes](https://cloud.google.com/compute/docs/nodes/sole-tenant-nodes).
938926

@@ -1238,9 +1226,25 @@ not specifying the `kubelet_config` block should be the equivalent of specifying
12381226

12391227
<a name="nested_linux_node_config"></a>The `linux_node_config` block supports:
12401228

1241-
* `sysctls` - (Required) The Linux kernel parameters to be applied to the nodes
1229+
* `sysctls` - (Optional) The Linux kernel parameters to be applied to the nodes
12421230
and all pods running on the nodes. Specified as a map from the key, such as
1243-
`net.core.wmem_max`, to a string value.
1231+
`net.core.wmem_max`, to a string value. Currently supported attributes can be found [here](https://cloud.google.com/sdk/gcloud/reference/beta/container/node-pools/create#--system-config-from-file).
1232+
Note that validations happen all server side. All attributes are optional.
1233+
1234+
```hcl
1235+
linux_node_config {
1236+
sysctls = {
1237+
"net.core.netdev_max_backlog" = "10000"
1238+
"net.core.rmem_max" = "10000"
1239+
}
1240+
}
1241+
```
1242+
1243+
* `cgroup_mode` - (Optional) Possible cgroup modes that can be used.
1244+
Accepted values are:
1245+
* `CGROUP_MODE_UNSPECIFIED`: CGROUP_MODE_UNSPECIFIED is when unspecified cgroup configuration is used. The default for the GKE node OS image will be used.
1246+
* `CGROUP_MODE_V1`: CGROUP_MODE_V1 specifies to use cgroupv1 for the cgroup configuration on the node image.
1247+
* `CGROUP_MODE_V2`: CGROUP_MODE_V2 specifies to use cgroupv2 for the cgroup configuration on the node image.
12441248

12451249
<a name="nested_vertical_pod_autoscaling"></a>The `vertical_pod_autoscaling` block supports:
12461250

0 commit comments

Comments
 (0)