Skip to content

Commit c59fe19

Browse files
authored
Add writable cgroups to containerd config (#15511)
Signed-off-by: Chris Henzie <[email protected]>
1 parent 3cd2077 commit c59fe19

File tree

5 files changed

+371
-1
lines changed

5 files changed

+371
-1
lines changed

mmv1/third_party/terraform/services/container/node_config.go.tmpl

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ func schemaContainerdConfig() *schema.Schema {
7878
},
7979
}},
8080
},
81+
"writable_cgroups": {
82+
Type: schema.TypeList,
83+
Description: `Parameters for writable cgroups configuration.`,
84+
Optional: true,
85+
MaxItems: 1,
86+
Elem: &schema.Resource{
87+
Schema: map[string]*schema.Schema{
88+
"enabled": {
89+
Type: schema.TypeBool,
90+
Required: true,
91+
Description: `Whether writable cgroups are enabled.`,
92+
},
93+
},
94+
},
95+
},
8196
}},
8297
}
8398
}
@@ -1962,6 +1977,7 @@ func expandContainerdConfig(v interface{}) *container.ContainerdConfig {
19621977

19631978
cc := &container.ContainerdConfig{}
19641979
cc.PrivateRegistryAccessConfig = expandPrivateRegistryAccessConfig(cfg["private_registry_access_config"])
1980+
cc.WritableCgroups = expandWritableCgroups(cfg["writable_cgroups"])
19651981
return cc
19661982
}
19671983

@@ -2033,6 +2049,26 @@ func expandGCPSecretManagerCertificateConfig(v interface{}) *container.GCPSecret
20332049
return gcpSMConfig
20342050
}
20352051

2052+
func expandWritableCgroups(v interface{}) *container.WritableCgroups {
2053+
if v == nil {
2054+
return nil
2055+
}
2056+
ls := v.([]interface{})
2057+
if len(ls) == 0 {
2058+
return nil
2059+
}
2060+
if ls[0] == nil {
2061+
return &container.WritableCgroups{}
2062+
}
2063+
cfg := ls[0].(map[string]interface{})
2064+
2065+
wcg := &container.WritableCgroups{}
2066+
if enabled, ok := cfg["enabled"]; ok {
2067+
wcg.Enabled = enabled.(bool)
2068+
}
2069+
return wcg
2070+
}
2071+
20362072
func expandSoleTenantConfig(v interface{}) *container.SoleTenantConfig {
20372073
if v == nil {
20382074
return nil
@@ -2636,6 +2672,9 @@ func flattenContainerdConfig(c *container.ContainerdConfig) []map[string]interfa
26362672
if c.PrivateRegistryAccessConfig != nil {
26372673
r["private_registry_access_config"] = flattenPrivateRegistryAccessConfig(c.PrivateRegistryAccessConfig)
26382674
}
2675+
if c.WritableCgroups != nil {
2676+
r["writable_cgroups"] = flattenWritableCgroups(c.WritableCgroups)
2677+
}
26392678
return append(result, r)
26402679
}
26412680

@@ -2695,6 +2734,17 @@ func flattenGCPSecretManagerCertificateConfig(c *container.GCPSecretManagerCerti
26952734
return append(result, r)
26962735
}
26972736

2737+
func flattenWritableCgroups(c *container.WritableCgroups) []map[string]interface{} {
2738+
result := []map[string]interface{}{}
2739+
if c == nil {
2740+
return result
2741+
}
2742+
r := map[string]interface{}{
2743+
"enabled": c.Enabled,
2744+
}
2745+
return append(result, r)
2746+
}
2747+
26982748
func flattenConfidentialNodes(c *container.ConfidentialNodes) []map[string]interface{} {
26992749
result := []map[string]interface{}{}
27002750
if c != nil {

mmv1/third_party/terraform/services/container/resource_container_cluster_meta.yaml.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ fields:
249249
- api_field: 'nodeConfig.containerdConfig.privateRegistryAccessConfig.certificateAuthorityDomainConfig.fqdns'
250250
- api_field: 'nodeConfig.containerdConfig.privateRegistryAccessConfig.certificateAuthorityDomainConfig.gcpSecretManagerCertificateConfig.secretUri'
251251
- api_field: 'nodeConfig.containerdConfig.privateRegistryAccessConfig.enabled'
252+
- api_field: 'nodeConfig.containerdConfig.writableCgroups.enabled'
252253
- api_field: 'nodeConfig.diskSizeGb'
253254
- api_field: 'nodeConfig.diskType'
254255
- field: 'node_config.effective_taints.effect'
@@ -685,6 +686,7 @@ fields:
685686
- api_field: 'nodePoolDefaults.nodeConfigDefaults.containerdConfig.privateRegistryAccessConfig.certificateAuthorityDomainConfig.fqdns'
686687
- api_field: 'nodePoolDefaults.nodeConfigDefaults.containerdConfig.privateRegistryAccessConfig.certificateAuthorityDomainConfig.gcpSecretManagerCertificateConfig.secretUri'
687688
- api_field: 'nodePoolDefaults.nodeConfigDefaults.containerdConfig.privateRegistryAccessConfig.enabled'
689+
- api_field: 'nodePoolDefaults.nodeConfigDefaults.containerdConfig.writableCgroups.enabled'
688690
- api_field: 'nodePoolDefaults.nodeConfigDefaults.gcfsConfig.enabled'
689691
- field: 'node_pool_defaults.node_config_defaults.insecure_kubelet_readonly_port_enabled'
690692
api_field: 'nodePoolDefaults.nodeConfigDefaults.nodeKubeletConfig.insecureKubeletReadonlyPortEnabled'

mmv1/third_party/terraform/services/container/resource_container_cluster_test.go.tmpl

Lines changed: 203 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14118,6 +14118,208 @@ resource "google_container_cluster" "primary" {
1411814118
`, secretID, clusterName, customDomain, networkName, subnetworkName)
1411914119
}
1412014120

14121+
func TestAccContainerCluster_writableCgroups(t *testing.T) {
14122+
t.Parallel()
14123+
14124+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
14125+
nodePoolName := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10))
14126+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
14127+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
14128+
14129+
acctest.VcrTest(t, resource.TestCase{
14130+
PreCheck: func() { acctest.AccTestPreCheck(t) },
14131+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
14132+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
14133+
Steps: []resource.TestStep{
14134+
// Test enabling writable_cgroups for new node pools via node_pool_defaults.
14135+
{
14136+
Config: testAccContainerCluster_writableCgroupsEnabled(clusterName, networkName, subnetworkName),
14137+
Check: resource.ComposeAggregateTestCheckFunc(
14138+
resource.TestCheckResourceAttr(
14139+
"google_container_cluster.primary",
14140+
"node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled",
14141+
"true",
14142+
),
14143+
),
14144+
},
14145+
{
14146+
ResourceName: "google_container_cluster.primary",
14147+
ImportState: true,
14148+
ImportStateVerify: true,
14149+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14150+
},
14151+
// Test disabling writable_cgroups for new node pools via node_pool_defaults.
14152+
{
14153+
Config: testAccContainerCluster_writableCgroupsDisabled(clusterName, networkName, subnetworkName),
14154+
ConfigPlanChecks: resource.ConfigPlanChecks{
14155+
PreApply: []plancheck.PlanCheck{
14156+
acctest.ExpectNoDelete(),
14157+
},
14158+
},
14159+
Check: resource.ComposeAggregateTestCheckFunc(
14160+
resource.TestCheckResourceAttr(
14161+
"google_container_cluster.primary",
14162+
"node_pool_defaults.0.node_config_defaults.0.containerd_config.0.writable_cgroups.0.enabled",
14163+
"false",
14164+
),
14165+
),
14166+
},
14167+
{
14168+
ResourceName: "google_container_cluster.primary",
14169+
ImportState: true,
14170+
ImportStateVerify: true,
14171+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14172+
},
14173+
// Test configuring writable_cgroups on the cluster's default node pool directly via node_config.
14174+
{
14175+
Config: testAccContainerCluster_withNodeConfigWritableCgroups(clusterName, networkName, subnetworkName),
14176+
ConfigPlanChecks: resource.ConfigPlanChecks{
14177+
PreApply: []plancheck.PlanCheck{
14178+
acctest.ExpectNoDelete(),
14179+
},
14180+
},
14181+
Check: resource.ComposeAggregateTestCheckFunc(
14182+
resource.TestCheckResourceAttr(
14183+
"google_container_cluster.primary",
14184+
"node_config.0.containerd_config.0.writable_cgroups.0.enabled",
14185+
"true",
14186+
),
14187+
),
14188+
},
14189+
{
14190+
ResourceName: "google_container_cluster.primary",
14191+
ImportState: true,
14192+
ImportStateVerify: true,
14193+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14194+
},
14195+
// Test configuring writable_cgroups on a named node pool defined within the cluster.
14196+
// This change from a default to a named node pool is expected to force recreation.
14197+
{
14198+
Config: testAccContainerCluster_withNodePoolWritableCgroups(clusterName, nodePoolName, networkName, subnetworkName),
14199+
},
14200+
{
14201+
ResourceName: "google_container_cluster.primary",
14202+
ImportState: true,
14203+
ImportStateVerify: true,
14204+
ImportStateVerifyIgnore: []string{"min_master_version", "deletion_protection"},
14205+
},
14206+
},
14207+
})
14208+
}
14209+
14210+
func testAccContainerCluster_writableCgroupsEnabled(clusterName, networkName, subnetworkName string) string {
14211+
return fmt.Sprintf(`
14212+
data "google_container_engine_versions" "central1a" {
14213+
location = "us-central1-a"
14214+
}
14215+
14216+
resource "google_container_cluster" "primary" {
14217+
name = "%s"
14218+
location = "us-central1-a"
14219+
initial_node_count = 1
14220+
min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14221+
network = "%s"
14222+
subnetwork = "%s"
14223+
deletion_protection = false
14224+
14225+
node_pool_defaults {
14226+
node_config_defaults {
14227+
containerd_config {
14228+
writable_cgroups {
14229+
enabled = true
14230+
}
14231+
}
14232+
}
14233+
}
14234+
}
14235+
`, clusterName, networkName, subnetworkName)
14236+
}
14237+
14238+
func testAccContainerCluster_writableCgroupsDisabled(clusterName, networkName, subnetworkName string) string {
14239+
return fmt.Sprintf(`
14240+
data "google_container_engine_versions" "central1a" {
14241+
location = "us-central1-a"
14242+
}
14243+
14244+
resource "google_container_cluster" "primary" {
14245+
name = "%s"
14246+
location = "us-central1-a"
14247+
initial_node_count = 1
14248+
min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14249+
network = "%s"
14250+
subnetwork = "%s"
14251+
deletion_protection = false
14252+
14253+
node_pool_defaults {
14254+
node_config_defaults {
14255+
containerd_config {
14256+
writable_cgroups {
14257+
enabled = false
14258+
}
14259+
}
14260+
}
14261+
}
14262+
}
14263+
`, clusterName, networkName, subnetworkName)
14264+
}
14265+
14266+
func testAccContainerCluster_withNodePoolWritableCgroups(clusterName, nodePoolName, networkName, subnetworkName string) string {
14267+
return fmt.Sprintf(`
14268+
data "google_container_engine_versions" "central1a" {
14269+
location = "us-central1-a"
14270+
}
14271+
14272+
resource "google_container_cluster" "primary" {
14273+
name = "%s"
14274+
location = "us-central1-a"
14275+
min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14276+
network = "%s"
14277+
subnetwork = "%s"
14278+
deletion_protection = false
14279+
14280+
node_pool {
14281+
name = "%s"
14282+
initial_node_count = 1
14283+
node_config {
14284+
containerd_config {
14285+
writable_cgroups {
14286+
enabled = true
14287+
}
14288+
}
14289+
}
14290+
}
14291+
14292+
}
14293+
`, clusterName, networkName, subnetworkName, nodePoolName)
14294+
}
14295+
14296+
func testAccContainerCluster_withNodeConfigWritableCgroups(clusterName, networkName, subnetworkName string) string {
14297+
return fmt.Sprintf(`
14298+
data "google_container_engine_versions" "central1a" {
14299+
location = "us-central1-a"
14300+
}
14301+
14302+
resource "google_container_cluster" "primary" {
14303+
name = "%s"
14304+
location = "us-central1-a"
14305+
initial_node_count = 1
14306+
min_master_version = data.google_container_engine_versions.central1a.release_channel_latest_version["RAPID"]
14307+
network = "%s"
14308+
subnetwork = "%s"
14309+
deletion_protection = false
14310+
14311+
node_config {
14312+
containerd_config {
14313+
writable_cgroups {
14314+
enabled = true
14315+
}
14316+
}
14317+
}
14318+
14319+
}
14320+
`, clusterName, networkName, subnetworkName)
14321+
}
14322+
1412114323
func TestAccContainerCluster_withProviderDefaultLabels(t *testing.T) {
1412214324
// The test failed if VCR testing is enabled, because the cached provider config is used.
1412314325
// With the cached provider config, any changes in the provider default labels will not be applied.
@@ -15734,4 +15936,4 @@ resource "google_container_cluster" "with_kubelet_config" {
1573415936
}
1573515937
}
1573615938
`, clusterName, networkName, subnetworkName, npName, npName)
15737-
}
15939+
}

0 commit comments

Comments
 (0)