Skip to content

Commit e4cfd72

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

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

.changelog/12985.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 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/services/container/node_config.go

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,10 +579,45 @@ func schemaNodeConfig() *schema.Schema {
579579
Optional: true,
580580
Description: `Controls the maximum number of processes allowed to run in a pod.`,
581581
},
582+
"container_log_max_size": {
583+
Type: schema.TypeString,
584+
Optional: true,
585+
Description: `Defines the maximum size of the container log file before it is rotated.`,
586+
},
587+
"container_log_max_files": {
588+
Type: schema.TypeInt,
589+
Optional: true,
590+
Description: `Defines the maximum number of container log files that can be present for a container.`,
591+
},
592+
"image_gc_low_threshold_percent": {
593+
Type: schema.TypeInt,
594+
Optional: true,
595+
Description: `Defines the percent of disk usage before which image garbage collection is never run. Lowest disk usage to garbage collect to.`,
596+
},
597+
"image_gc_high_threshold_percent": {
598+
Type: schema.TypeInt,
599+
Optional: true,
600+
Description: `Defines the percent of disk usage after which image garbage collection is always run.`,
601+
},
602+
"image_minimum_gc_age": {
603+
Type: schema.TypeString,
604+
Optional: true,
605+
Description: `Defines the minimum age for an unused image before it is garbage collected.`,
606+
},
607+
"image_maximum_gc_age": {
608+
Type: schema.TypeString,
609+
Optional: true,
610+
Description: `Defines the maximum age an image can be unused before it is garbage collected.`,
611+
},
612+
"allowed_unsafe_sysctls": {
613+
Type: schema.TypeList,
614+
Optional: true,
615+
Description: `Defines a comma-separated allowlist of unsafe sysctls or sysctl patterns which can be set on the Pods.`,
616+
Elem: &schema.Schema{Type: schema.TypeString},
617+
},
582618
},
583619
},
584620
},
585-
586621
"linux_node_config": {
587622
Type: schema.TypeList,
588623
Optional: true,
@@ -1220,6 +1255,31 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
12201255
if podPidsLimit, ok := cfg["pod_pids_limit"]; ok {
12211256
kConfig.PodPidsLimit = int64(podPidsLimit.(int))
12221257
}
1258+
if containerLogMaxSize, ok := cfg["container_log_max_size"]; ok {
1259+
kConfig.ContainerLogMaxSize = containerLogMaxSize.(string)
1260+
}
1261+
if containerLogMaxFiles, ok := cfg["container_log_max_files"]; ok {
1262+
kConfig.ContainerLogMaxFiles = int64(containerLogMaxFiles.(int))
1263+
}
1264+
if imageGcLowThresholdPercent, ok := cfg["image_gc_low_threshold_percent"]; ok {
1265+
kConfig.ImageGcLowThresholdPercent = int64(imageGcLowThresholdPercent.(int))
1266+
}
1267+
if imageGcHighThresholdPercent, ok := cfg["image_gc_high_threshold_percent"]; ok {
1268+
kConfig.ImageGcHighThresholdPercent = int64(imageGcHighThresholdPercent.(int))
1269+
}
1270+
if imageMinimumGcAge, ok := cfg["image_minimum_gc_age"]; ok {
1271+
kConfig.ImageMinimumGcAge = imageMinimumGcAge.(string)
1272+
}
1273+
if imageMaximumGcAge, ok := cfg["image_maximum_gc_age"]; ok {
1274+
kConfig.ImageMaximumGcAge = imageMaximumGcAge.(string)
1275+
}
1276+
if allowedUnsafeSysctls, ok := cfg["allowed_unsafe_sysctls"]; ok {
1277+
sysctls := allowedUnsafeSysctls.([]interface{})
1278+
kConfig.AllowedUnsafeSysctls = make([]string, len(sysctls))
1279+
for i, s := range sysctls {
1280+
kConfig.AllowedUnsafeSysctls[i] = s.(string)
1281+
}
1282+
}
12231283
return kConfig
12241284
}
12251285

@@ -1729,6 +1789,13 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
17291789
"cpu_manager_policy": c.CpuManagerPolicy,
17301790
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
17311791
"pod_pids_limit": c.PodPidsLimit,
1792+
"container_log_max_size": c.ContainerLogMaxSize,
1793+
"container_log_max_files": c.ContainerLogMaxFiles,
1794+
"image_gc_low_threshold_percent": c.ImageGcLowThresholdPercent,
1795+
"image_gc_high_threshold_percent": c.ImageGcHighThresholdPercent,
1796+
"image_minimum_gc_age": c.ImageMinimumGcAge,
1797+
"image_maximum_gc_age": c.ImageMaximumGcAge,
1798+
"allowed_unsafe_sysctls": c.AllowedUnsafeSysctls,
17321799
})
17331800
}
17341801
return result

google/services/container/resource_container_node_pool_test.go

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
500500
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
501501
Steps: []resource.TestStep{
502502
{
503-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, "TRUE", true, 2048),
503+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "static", "100ms", networkName, subnetworkName, "TRUE", "100Mi", "1m", "10m", true, 2048, 10, 10, 85),
504504
ConfigPlanChecks: resource.ConfigPlanChecks{
505505
PreApply: []plancheck.PlanCheck{
506506
acctest.ExpectNoDelete(),
@@ -513,6 +513,20 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
513513
"node_config.0.kubelet_config.0.insecure_kubelet_readonly_port_enabled", "TRUE"),
514514
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
515515
"node_config.0.kubelet_config.0.pod_pids_limit", "2048"),
516+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
517+
"node_config.0.kubelet_config.0.container_log_max_size", "100Mi"),
518+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
519+
"node_config.0.kubelet_config.0.container_log_max_files", "10"),
520+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
521+
"node_config.0.kubelet_config.0.image_gc_low_threshold_percent", "10"),
522+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
523+
"node_config.0.kubelet_config.0.image_gc_high_threshold_percent", "85"),
524+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
525+
"node_config.0.kubelet_config.0.image_minimum_gc_age", "1m"),
526+
resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
527+
"node_config.0.kubelet_config.0.image_maximum_gc_age", "10m"),
528+
// resource.TestCheckResourceAttr("google_container_node_pool.with_kubelet_config",
529+
// "node_config.0.kubelet_config.0.allowed_unsafe_sysctls.0", "kernel.shm*"),
516530
),
517531
},
518532
{
@@ -521,7 +535,7 @@ func TestAccContainerNodePool_withKubeletConfig(t *testing.T) {
521535
ImportStateVerify: true,
522536
},
523537
{
524-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, "FALSE", false, 1024),
538+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "", "", networkName, subnetworkName, "FALSE", "200Mi", "30s", "", false, 1024, 5, 50, 80),
525539
ConfigPlanChecks: resource.ConfigPlanChecks{
526540
PreApply: []plancheck.PlanCheck{
527541
acctest.ExpectNoDelete(),
@@ -559,7 +573,7 @@ func TestAccContainerNodePool_withInvalidKubeletCpuManagerPolicy(t *testing.T) {
559573
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
560574
Steps: []resource.TestStep{
561575
{
562-
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, "TRUE", false, 1024),
576+
Config: testAccContainerNodePool_withKubeletConfig(cluster, np, "dontexist", "100us", networkName, subnetworkName, "TRUE", "", "", "", false, 1024, 2, 70, 75),
563577
ExpectError: regexp.MustCompile(`.*to be one of \["?static"? "?none"? "?"?\].*`),
564578
},
565579
},
@@ -2997,7 +3011,8 @@ resource "google_container_node_pool" "with_workload_metadata_config" {
29973011
`, projectID, cluster, networkName, subnetworkName, np)
29983012
}
29993013

3000-
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled string, quota bool, podPidsLimit int) string {
3014+
// 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.
3015+
func testAccContainerNodePool_withKubeletConfig(cluster, np, policy, period, networkName, subnetworkName, insecureKubeletReadonlyPortEnabled, containerLogMaxSize, imageMinimumGcAge, imageMaximumGcAge string, quota bool, podPidsLimit, containerLogMaxFiles, imageGcLowThresholdPercent, imageGcHighThresholdPercent int) string {
30013016
return fmt.Sprintf(`
30023017
data "google_container_engine_versions" "central1a" {
30033018
location = "us-central1-a"
@@ -3028,6 +3043,13 @@ resource "google_container_node_pool" "with_kubelet_config" {
30283043
cpu_cfs_quota_period = %q
30293044
insecure_kubelet_readonly_port_enabled = "%s"
30303045
pod_pids_limit = %d
3046+
container_log_max_size = %q
3047+
container_log_max_files = %d
3048+
image_gc_low_threshold_percent = %d
3049+
image_gc_high_threshold_percent = %d
3050+
image_minimum_gc_age = %q
3051+
image_maximum_gc_age = %q
3052+
# allowed_unsafe_sysctls = ["kernel.shm*", "kernel.msg*", "kernel.sem", "fs.mqueue.*", "net.*"]
30313053
}
30323054
oauth_scopes = [
30333055
"https://www.googleapis.com/auth/logging.write",
@@ -3036,7 +3058,7 @@ resource "google_container_node_pool" "with_kubelet_config" {
30363058
logging_variant = "DEFAULT"
30373059
}
30383060
}
3039-
`, cluster, networkName, subnetworkName, np, policy, quota, period, insecureKubeletReadonlyPortEnabled, podPidsLimit)
3061+
`, cluster, networkName, subnetworkName, np, policy, quota, period, insecureKubeletReadonlyPortEnabled, podPidsLimit, containerLogMaxSize, containerLogMaxFiles, imageGcLowThresholdPercent, imageGcHighThresholdPercent, imageMinimumGcAge, imageMaximumGcAge)
30403062
}
30413063

30423064
func testAccContainerNodePool_withLinuxNodeConfig(cluster, np, tcpMem, networkName, subnetworkName string) string {
@@ -3058,6 +3080,7 @@ func testAccContainerNodePool_withLinuxNodeConfig(cluster, np, tcpMem, networkNa
30583080
"net.ipv4.tcp_rmem" = "%s"
30593081
"net.ipv4.tcp_wmem" = "%s"
30603082
"net.ipv4.tcp_tw_reuse" = 1
3083+
"kernel.shmmni" = 8192
30613084
}
30623085
}
30633086
`, tcpMem, tcpMem)

website/docs/r/container_cluster.html.markdown

Lines changed: 18 additions & 0 deletions
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)