Skip to content

Commit fee773f

Browse files
Add support for cgroup_mode in node_pool_auto_config (#12382) (#20460)
[upstream:c3694fbae88f0857de97ab135cb75c6104ed524a] Signed-off-by: Modular Magician <[email protected]>
1 parent 03714e5 commit fee773f

File tree

5 files changed

+156
-0
lines changed

5 files changed

+156
-0
lines changed

.changelog/12382.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added `node_pool_autoconfig.linux_node_config.cgroup_mode` field to `google_container_cluster` resource
3+
```

google/services/container/node_config.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,29 @@ func schemaNodePoolAutoConfigNodeKubeletConfig() *schema.Schema {
787787
}
788788
}
789789

790+
// Separate since this currently only supports a single value -- a subset of
791+
// the overall LinuxNodeConfig
792+
func schemaNodePoolAutoConfigLinuxNodeConfig() *schema.Schema {
793+
return &schema.Schema{
794+
Type: schema.TypeList,
795+
Optional: true,
796+
MaxItems: 1,
797+
Description: `Linux node configuration options.`,
798+
Elem: &schema.Resource{
799+
Schema: map[string]*schema.Schema{
800+
"cgroup_mode": {
801+
Type: schema.TypeString,
802+
Optional: true,
803+
Computed: true,
804+
ValidateFunc: validation.StringInSlice([]string{"CGROUP_MODE_UNSPECIFIED", "CGROUP_MODE_V1", "CGROUP_MODE_V2"}, false),
805+
Description: `cgroupMode specifies the cgroup mode to be used on the node.`,
806+
DiffSuppressFunc: tpgresource.EmptyOrDefaultStringSuppress("CGROUP_MODE_UNSPECIFIED"),
807+
},
808+
},
809+
},
810+
}
811+
}
812+
790813
func expandNodeConfigDefaults(configured interface{}) *container.NodeConfigDefaults {
791814
configs := configured.([]interface{})
792815
if len(configs) == 0 || configs[0] == nil {

google/services/container/resource_container_cluster.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,7 @@ func ResourceContainerCluster() *schema.Resource {
13631363
Elem: &schema.Resource{
13641364
Schema: map[string]*schema.Schema{
13651365
"node_kubelet_config": schemaNodePoolAutoConfigNodeKubeletConfig(),
1366+
"linux_node_config": schemaNodePoolAutoConfigLinuxNodeConfig(),
13661367
"network_tags": {
13671368
Type: schema.TypeList,
13681369
Optional: true,
@@ -2596,6 +2597,34 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
25962597
}
25972598
}
25982599

2600+
if linuxNodeConfig, ok := d.GetOk("node_pool_auto_config.0.linux_node_config"); ok {
2601+
name := containerClusterFullName(project, location, clusterName)
2602+
req := &container.UpdateClusterRequest{
2603+
Update: &container.ClusterUpdate{
2604+
DesiredNodePoolAutoConfigLinuxNodeConfig: expandLinuxNodeConfig(linuxNodeConfig),
2605+
},
2606+
}
2607+
2608+
err = transport_tpg.Retry(transport_tpg.RetryOptions{
2609+
RetryFunc: func() error {
2610+
clusterUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.Update(name, req)
2611+
if config.UserProjectOverride {
2612+
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
2613+
}
2614+
op, err = clusterUpdateCall.Do()
2615+
return err
2616+
},
2617+
})
2618+
if err != nil {
2619+
return errwrap.Wrapf("Error updating LinuxNodeConfig: {{err}}", err)
2620+
}
2621+
2622+
err = ContainerOperationWait(config, op, project, location, "updating LinuxNodeConfig", userAgent, d.Timeout(schema.TimeoutCreate))
2623+
if err != nil {
2624+
return errwrap.Wrapf("Error while waiting to update LinuxNodeConfig: {{err}}", err)
2625+
}
2626+
}
2627+
25992628
if err := resourceContainerClusterRead(d, meta); err != nil {
26002629
return err
26012630
}
@@ -4180,6 +4209,24 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
41804209
log.Printf("[INFO] GKE cluster %s node pool auto config resource manager tags have been updated", d.Id())
41814210
}
41824211

4212+
if d.HasChange("node_pool_auto_config.0.linux_node_config") {
4213+
req := &container.UpdateClusterRequest{
4214+
Update: &container.ClusterUpdate{
4215+
DesiredNodePoolAutoConfigLinuxNodeConfig: expandLinuxNodeConfig(
4216+
d.Get("node_pool_auto_config.0.linux_node_config"),
4217+
),
4218+
},
4219+
}
4220+
4221+
updateF := updateFunc(req, "updating GKE cluster node pool auto config linux node config")
4222+
// Call update serially.
4223+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4224+
return err
4225+
}
4226+
4227+
log.Printf("[INFO] GKE cluster %s node pool auto config linux_node_config parameters have been updated", d.Id())
4228+
}
4229+
41834230
d.Partial(false)
41844231

41854232
if _, err := containerClusterAwaitRestingState(config, project, location, clusterName, userAgent, d.Timeout(schema.TimeoutUpdate)); err != nil {
@@ -6224,6 +6271,11 @@ func flattenNodePoolAutoConfig(c *container.NodePoolAutoConfig) []map[string]int
62246271
if c.ResourceManagerTags != nil {
62256272
result["resource_manager_tags"] = flattenResourceManagerTags(c.ResourceManagerTags)
62266273
}
6274+
if c.LinuxNodeConfig != nil {
6275+
result["linux_node_config"] = []map[string]interface{}{
6276+
{"cgroup_mode": c.LinuxNodeConfig.CgroupMode},
6277+
}
6278+
}
62276279

62286280
return []map[string]interface{}{result}
62296281
}

google/services/container/resource_container_cluster_test.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11631,3 +11631,79 @@ resource "google_container_cluster" "primary" {
1163111631
}
1163211632
}`, name, enabled)
1163311633
}
11634+
11635+
func TestAccContainerCluster_withCgroupMode(t *testing.T) {
11636+
t.Parallel()
11637+
11638+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
11639+
acctest.VcrTest(t, resource.TestCase{
11640+
PreCheck: func() { acctest.AccTestPreCheck(t) },
11641+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
11642+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
11643+
Steps: []resource.TestStep{
11644+
{
11645+
Config: testAccContainerCluster_withCgroupMode(clusterName, "CGROUP_MODE_V2"),
11646+
Check: resource.ComposeAggregateTestCheckFunc(
11647+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "node_pool_auto_config.0.linux_node_config.0.cgroup_mode"),
11648+
resource.TestCheckResourceAttr("google_container_cluster.primary", "node_pool_auto_config.0.linux_node_config.0.cgroup_mode", "CGROUP_MODE_V2"),
11649+
),
11650+
},
11651+
{
11652+
ResourceName: "google_container_cluster.primary",
11653+
ImportState: true,
11654+
ImportStateVerify: true,
11655+
ImportStateVerifyIgnore: []string{"deletion_protection"},
11656+
},
11657+
},
11658+
})
11659+
}
11660+
11661+
func TestAccContainerCluster_withCgroupModeUpdate(t *testing.T) {
11662+
t.Parallel()
11663+
11664+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
11665+
acctest.VcrTest(t, resource.TestCase{
11666+
PreCheck: func() { acctest.AccTestPreCheck(t) },
11667+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
11668+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
11669+
Steps: []resource.TestStep{
11670+
{
11671+
Config: testAccContainerCluster_autopilot_minimal(clusterName),
11672+
},
11673+
{
11674+
ResourceName: "google_container_cluster.primary",
11675+
ImportState: true,
11676+
ImportStateVerify: true,
11677+
ImportStateVerifyIgnore: []string{"deletion_protection"},
11678+
},
11679+
{
11680+
Config: testAccContainerCluster_withCgroupMode(clusterName, "CGROUP_MODE_V2"),
11681+
Check: resource.ComposeAggregateTestCheckFunc(
11682+
resource.TestCheckResourceAttrSet("google_container_cluster.primary", "node_pool_auto_config.0.linux_node_config.0.cgroup_mode"),
11683+
resource.TestCheckResourceAttr("google_container_cluster.primary", "node_pool_auto_config.0.linux_node_config.0.cgroup_mode", "CGROUP_MODE_V2"),
11684+
),
11685+
},
11686+
{
11687+
ResourceName: "google_container_cluster.primary",
11688+
ImportState: true,
11689+
ImportStateVerify: true,
11690+
ImportStateVerifyIgnore: []string{"deletion_protection"},
11691+
},
11692+
},
11693+
})
11694+
}
11695+
11696+
func testAccContainerCluster_withCgroupMode(name string, cgroupMode string) string {
11697+
return fmt.Sprintf(`
11698+
resource "google_container_cluster" "primary" {
11699+
name = "%s"
11700+
enable_autopilot = true
11701+
deletion_protection = false
11702+
node_pool_auto_config {
11703+
linux_node_config {
11704+
cgroup_mode = "%s"
11705+
}
11706+
}
11707+
}
11708+
`, name, cgroupMode)
11709+
}

website/docs/r/container_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,6 +1110,8 @@ Structure is [documented below](#nested_node_kubelet_config).
11101110

11111111
* `network_tags` (Optional) - The network tag config for the cluster's automatically provisioned node pools. Structure is [documented below](#nested_network_tags).
11121112

1113+
* `linux_node_config` (Optional) - Linux system configuration for the cluster's automatically provisioned node pools. Only `cgroup_mode` field is supported in `node_pool_auto_config`. Structure is [documented below](#nested_linux_node_config).
1114+
11131115
<a name="nested_node_kubelet_config"></a>The `node_kubelet_config` block supports:
11141116

11151117
* `insecure_kubelet_readonly_port_enabled` - (Optional) Controls whether the kubelet read-only port is enabled. It is strongly recommended to set this to `FALSE`. Possible values: `TRUE`, `FALSE`.

0 commit comments

Comments
 (0)