Skip to content

Commit 2b06b61

Browse files
Add support for new flags in Container node_kubelet_config. (#12985) (#9274)
[upstream:68ab860a2515113f7b839d63212ada3e54d38133] Signed-off-by: Modular Magician <[email protected]>
1 parent d5fe844 commit 2b06b61

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

.changelog/12985.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:enhancement
2+
container: added new fields `container_log_max_size`, `container_log_max_files`, `image_gc_low_threshold_percent`, `image_gc_high_threshold_percent`, `image_minimum_gc_age`, `image_maximum_gc_age`, and `allowed_unsafe_sysctls` to `node_kubelet_config` block.
3+
```

google-beta/services/container/node_config.go

+68-1
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,45 @@ func schemaNodeConfig() *schema.Schema {
616616
Optional: true,
617617
Description: `Controls the maximum number of processes allowed to run in a pod.`,
618618
},
619+
"container_log_max_size": {
620+
Type: schema.TypeString,
621+
Optional: true,
622+
Description: `Defines the maximum size of the container log file before it is rotated.`,
623+
},
624+
"container_log_max_files": {
625+
Type: schema.TypeInt,
626+
Optional: true,
627+
Description: `Defines the maximum number of container log files that can be present for a container.`,
628+
},
629+
"image_gc_low_threshold_percent": {
630+
Type: schema.TypeInt,
631+
Optional: true,
632+
Description: `Defines the percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to.`,
633+
},
634+
"image_gc_high_threshold_percent": {
635+
Type: schema.TypeInt,
636+
Optional: true,
637+
Description: `Defines the percent of disk usage after which image garbage collection is always run.`,
638+
},
639+
"image_minimum_gc_age": {
640+
Type: schema.TypeString,
641+
Optional: true,
642+
Description: `Defines the minimum age for an unused image before it is garbage collected.`,
643+
},
644+
"image_maximum_gc_age": {
645+
Type: schema.TypeString,
646+
Optional: true,
647+
Description: `Defines the maximum age an image can be unused before it is garbage collected.`,
648+
},
649+
"allowed_unsafe_sysctls": {
650+
Type: schema.TypeList,
651+
Optional: true,
652+
Description: `Defines a comma-separated allowlist of unsafe sysctls or sysctl patterns which can be set on the Pods.`,
653+
Elem: &schema.Schema{Type: schema.TypeString},
654+
},
619655
},
620656
},
621657
},
622-
623658
"linux_node_config": {
624659
Type: schema.TypeList,
625660
Optional: true,
@@ -1273,6 +1308,31 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
12731308
if podPidsLimit, ok := cfg["pod_pids_limit"]; ok {
12741309
kConfig.PodPidsLimit = int64(podPidsLimit.(int))
12751310
}
1311+
if containerLogMaxSize, ok := cfg["container_log_max_size"]; ok {
1312+
kConfig.ContainerLogMaxSize = containerLogMaxSize.(string)
1313+
}
1314+
if containerLogMaxFiles, ok := cfg["container_log_max_files"]; ok {
1315+
kConfig.ContainerLogMaxFiles = int64(containerLogMaxFiles.(int))
1316+
}
1317+
if imageGcLowThresholdPercent, ok := cfg["image_gc_low_threshold_percent"]; ok {
1318+
kConfig.ImageGcLowThresholdPercent = int64(imageGcLowThresholdPercent.(int))
1319+
}
1320+
if imageGcHighThresholdPercent, ok := cfg["image_gc_high_threshold_percent"]; ok {
1321+
kConfig.ImageGcHighThresholdPercent = int64(imageGcHighThresholdPercent.(int))
1322+
}
1323+
if imageMinimumGcAge, ok := cfg["image_minimum_gc_age"]; ok {
1324+
kConfig.ImageMinimumGcAge = imageMinimumGcAge.(string)
1325+
}
1326+
if imageMaximumGcAge, ok := cfg["image_maximum_gc_age"]; ok {
1327+
kConfig.ImageMaximumGcAge = imageMaximumGcAge.(string)
1328+
}
1329+
if allowedUnsafeSysctls, ok := cfg["allowed_unsafe_sysctls"]; ok {
1330+
sysctls := allowedUnsafeSysctls.([]interface{})
1331+
kConfig.AllowedUnsafeSysctls = make([]string, len(sysctls))
1332+
for i, s := range sysctls {
1333+
kConfig.AllowedUnsafeSysctls[i] = s.(string)
1334+
}
1335+
}
12761336
return kConfig
12771337
}
12781338

@@ -1868,6 +1928,13 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
18681928
"cpu_manager_policy": c.CpuManagerPolicy,
18691929
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
18701930
"pod_pids_limit": c.PodPidsLimit,
1931+
"container_log_max_size": c.ContainerLogMaxSize,
1932+
"container_log_max_files": c.ContainerLogMaxFiles,
1933+
"image_gc_low_threshold_percent": c.ImageGcLowThresholdPercent,
1934+
"image_gc_high_threshold_percent": c.ImageGcHighThresholdPercent,
1935+
"image_minimum_gc_age": c.ImageMinimumGcAge,
1936+
"image_maximum_gc_age": c.ImageMaximumGcAge,
1937+
"allowed_unsafe_sysctls": c.AllowedUnsafeSysctls,
18711938
})
18721939
}
18731940
return result

google-beta/services/container/resource_container_node_pool_test.go

+28-5
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
529529
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
530530
Steps: []resource.TestStep{
531531
{
532-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, "TRUE", true, 2048),
532+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, "TRUE", "100Mi", "1m", "10m", true, 2048, 10, 10, 85),
533533
ConfigPlanChecks: resource.ConfigPlanChecks{
534534
PreApply: []plancheck.PlanCheck{
535535
acctest.ExpectNoDelete(),
@@ -542,6 +542,20 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
542542
"node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled", "TRUE"),
543543
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
544544
"node_config.0.kubelet_config.0.pod_pids_limit", "2048"),
545+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
546+
"node_config.0.kubelet_config.0.container_log_max_size", "100Mi"),
547+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
548+
"node_config.0.kubelet_config.0.container_log_max_files", "10"),
549+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
550+
"node_config.0.kubelet_config.0.image_gc_low_threshold_percent", "10"),
551+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
552+
"node_config.0.kubelet_config.0.image_gc_high_threshold_percent", "85"),
553+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
554+
"node_config.0.kubelet_config.0.image_minimum_gc_age", "1m"),
555+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
556+
"node_config.0.kubelet_config.0.image_maximum_gc_age", "10m"),
557+
// resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
558+
// "node_config.0.kubelet_config.0.allowed_unsafe_sysctls.0", "kernel.shm*"),
545559
),
546560
},
547561
{
@@ -550,7 +564,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
550564
ImportStateVerify: true,
551565
},
552566
{
553-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, "FALSE", false, 1024),
567+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, "FALSE", "200Mi", "30s", "", false, 1024, 5, 50, 80),
554568
ConfigPlanChecks: resource.ConfigPlanChecks{
555569
PreApply: []plancheck.PlanCheck{
556570
acctest.ExpectNoDelete(),
@@ -588,7 +602,7 @@ func TestAccContainerNodePool_withInvalidKubeletCpuManagerPolicy(t *testing.T) {
588602
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
589603
Steps: []resource.TestStep{
590604
{
591-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, "TRUE", false, 1024),
605+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, "TRUE", "", "", "", false, 1024, 2, 70, 75),
592606
ExpectError: regexp.MustCompile(`.*to be one of \["?static"? "?none"? "?"?\].*`),
593607
},
594608
},
@@ -3154,7 +3168,8 @@ resource "google_container_node_pool" "with_sandbox_config" {
31543168
`, cluster, networkName, subnetworkName, np)
31553169
}
31563170

3157-
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string, quota bool, podPidsLimit int) string {
3171+
// TODO: add allowed_unsafe_sysctls in the test after GKE version 1.32.0-gke.1448000 is default version in regular channel and used in Terraform test.
3172+
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled, containerLogMaxSize, imageMinimumGcAge, imageMaximumGcAge string, quota bool, podPidsLimit, containerLogMaxFiles, imageGcLowThresholdPercent, imageGcHighThresholdPercent int) string {
31583173
return fmt.Sprintf(`
31593174
data "google_container_engine_versions" "central1a" {
31603175
location = "us-central1-a"
@@ -3185,6 +3200,13 @@ resource "google_container_node_pool" "with_kubelet_config" {
31853200
cpu_cfs_quota_period = %q
31863201
insecure_kubelet_readonly_port_enabled = "%s"
31873202
pod_pids_limit = %d
3203+
container_log_max_size = %q
3204+
container_log_max_files = %d
3205+
image_gc_low_threshold_percent = %d
3206+
image_gc_high_threshold_percent = %d
3207+
image_minimum_gc_age = %q
3208+
image_maximum_gc_age = %q
3209+
# allowed_unsafe_sysctls = ["kernel.shm*", "kernel.msg*", "kernel.sem", "fs.mqueue.*", "net.*"]
31883210
}
31893211
oauth_scopes = [
31903212
"https://www.googleapis.com/auth/logging.write",
@@ -3193,7 +3215,7 @@ resource "google_container_node_pool" "with_kubelet_config" {
31933215
logging_variant = "DEFAULT"
31943216
}
31953217
}
3196-
`, cluster, networkName, subnetworkName, np, policy, quota, period, insecureKubeletReadonlyPortEnabled, podPidsLimit)
3218+
`, cluster, networkName, subnetworkName, np, policy, quota, period, insecureKubeletReadonlyPortEnabled, podPidsLimit, containerLogMaxSize, containerLogMaxFiles, imageGcLowThresholdPercent, imageGcHighThresholdPercent, imageMinimumGcAge, imageMaximumGcAge)
31973219
}
31983220

31993221
func testAccContainerNodePool_withLinuxNodeConfig(cluster, np, tcpMem, networkName, subnetworkName string) string {
@@ -3215,6 +3237,7 @@ func testAccContainerNodePool_withLinuxNodeConfig(cluster, np, tcpMem, networkNa
32153237
"net.ipv4.tcp_rmem" = "%s"
32163238
"net.ipv4.tcp_wmem" = "%s"
32173239
"net.ipv4.tcp_tw_reuse" = 1
3240+
"kernel.shmmni" = 8192
32183241
}
32193242
}
32203243
`, tcpMem, tcpMem)

website/docs/r/container_cluster.html.markdown

+18
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,24 @@ such as `"300ms"`. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m",
13491349

13501350
* `pod_pids_limit` - (Optional) Controls the maximum number of processes allowed to run in a pod. The value must be greater than or equal to 1024 and less than 4194304.
13511351

1352+
* `container_log_max_size` - (Optional) Defines the maximum size of the
1353+
container log file before it is rotated. Specified as a positive number and a
1354+
unit suffix, such as `"100Ki"`, `"10Mi"`. Valid units are "Ki", "Mi", "Gi".
1355+
The value must be between `"10Mi"` and `"500Mi"`, inclusive. And the total container log size
1356+
(`container_log_max_size` * `container_log_max_files`) cannot exceed 1% of the total storage of the node.
1357+
1358+
* `container_log_max_files` - (Optional) Defines the maximum number of container log files that can be present for a container. The integer must be between 2 and 10, inclusive.
1359+
1360+
* `image_gc_low_threshold_percent` - (Optional) Defines the percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to. The integer must be between 10 and 85, inclusive.
1361+
1362+
* `image_gc_high_threshold_percent` - (Optional) Defines the percent of disk usage after which image garbage collection is always run. The integer must be between 10 and 85, inclusive.
1363+
1364+
* `image_minimum_gc_age` - (Optional) Defines the minimum age for an unused image before it is garbage collected. Specified as a sequence of decimal numbers, each with optional fraction and a unit suffix, such as `"300s"`, `"1.5m"`. The value cannot be greater than "2m".
1365+
1366+
* `image_maximum_gc_age` - (Optional) Defines the maximum age an image can be unused before it is garbage collected. Specified as a sequence of decimal numbers, each with optional fraction and a unit suffix, such as `"300s"`, `"1.5m"`, and `"2h45m"`. Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". The value must be a positive duration.
1367+
1368+
* `allowed_unsafe_sysctls` - (Optional) Defines a comma-separated allowlist of unsafe sysctls or sysctl patterns which can be set on the Pods. The allowed sysctl groups are `kernel.shm*`, `kernel.msg*`, `kernel.sem`, `fs.mqueue.*`, and `net.*`.
1369+
13521370
<a name="nested_linux_node_config"></a>The `linux_node_config` block supports:
13531371

13541372
* `sysctls` - (Optional) The Linux kernel parameters to be applied to the nodes

0 commit comments

Comments
 (0)