Skip to content

Commit 9efcf42

Browse files
committed
Add shutdown_grace_period_seconds and shutdown_grace_period_critical_pods_seconds fields to GKE cluster kubelet_config
1 parent 4bf5fb7 commit 9efcf42

3 files changed

Lines changed: 148 additions & 21 deletions

File tree

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,18 @@ func schemaNodeConfig() *schema.Schema {
892892
Optional: true,
893893
Description: `Defines the maximum allowed grace period (in seconds) to use when terminating pods in response to a soft eviction threshold being met.`,
894894
},
895+
"shutdown_grace_period_seconds": {
896+
Type: schema.TypeInt,
897+
Optional: true,
898+
Computed: true,
899+
Description: `Controls the total duration of time (in seconds) the node delays shutdown.`,
900+
},
901+
"shutdown_grace_period_critical_pods_seconds": {
902+
Type: schema.TypeInt,
903+
Optional: true,
904+
Computed: true,
905+
Description: `Controls the portion of total grace period (in seconds) that is specifically reserved for terminating critical pods.`,
906+
},
895907
"eviction_soft": {
896908
Type: schema.TypeList,
897909
Optional: true,
@@ -1451,6 +1463,18 @@ func schemaNodePoolAutoConfigNodeKubeletConfig() *schema.Schema {
14511463
Elem: &schema.Resource{
14521464
Schema: map[string]*schema.Schema{
14531465
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
1466+
"shutdown_grace_period_seconds": {
1467+
Type: schema.TypeInt,
1468+
Optional: true,
1469+
Computed: true,
1470+
Description: `Controls the total duration of time (in seconds) the node delays shutdown.`,
1471+
},
1472+
"shutdown_grace_period_critical_pods_seconds": {
1473+
Type: schema.TypeInt,
1474+
Optional: true,
1475+
Computed: true,
1476+
Description: `Controls the portion of total grace period (in seconds) that is specifically reserved for terminating critical pods.`,
1477+
},
14541478
},
14551479
},
14561480
}
@@ -2055,6 +2079,14 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
20552079
if evictionMaxPodGracePeriodSeconds, ok := cfg["eviction_max_pod_grace_period_seconds"]; ok {
20562080
kConfig.EvictionMaxPodGracePeriodSeconds = int64(evictionMaxPodGracePeriodSeconds.(int))
20572081
}
2082+
if shutdownGracePeriodSeconds, ok := cfg["shutdown_grace_period_seconds"]; ok {
2083+
kConfig.ShutdownGracePeriodSeconds = int64(shutdownGracePeriodSeconds.(int))
2084+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "ShutdownGracePeriodSeconds")
2085+
}
2086+
if shutdownGracePeriodCriticalPodsSeconds, ok := cfg["shutdown_grace_period_critical_pods_seconds"]; ok {
2087+
kConfig.ShutdownGracePeriodCriticalPodsSeconds = int64(shutdownGracePeriodCriticalPodsSeconds.(int))
2088+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "ShutdownGracePeriodCriticalPodsSeconds")
2089+
}
20582090
if v, ok := cfg["eviction_soft"]; ok && len(v.([]interface{})) > 0 {
20592091
es := v.([]interface{})[0].(map[string]interface{})
20602092
evictionSoft := &container.EvictionSignals{}
@@ -3276,6 +3308,8 @@ func flattenKubeletConfig(c *container.NodeKubeletConfig) []map[string]interface
32763308
"single_process_oom_kill": c.SingleProcessOomKill,
32773309
"max_parallel_image_pulls": c.MaxParallelImagePulls,
32783310
"eviction_max_pod_grace_period_seconds": c.EvictionMaxPodGracePeriodSeconds,
3311+
"shutdown_grace_period_seconds": c.ShutdownGracePeriodSeconds,
3312+
"shutdown_grace_period_critical_pods_seconds": c.ShutdownGracePeriodCriticalPodsSeconds,
32793313
"eviction_soft": flattenEvictionSignals(c.EvictionSoft),
32803314
"eviction_soft_grace_period": flattenEvictionGracePeriod(c.EvictionSoftGracePeriod),
32813315
"eviction_minimum_reclaim": flattenEvictionMinimumReclaim(c.EvictionMinimumReclaim),
@@ -3311,6 +3345,8 @@ func flattenNodePoolAutoConfigNodeKubeletConfig(c *container.NodeKubeletConfig)
33113345
if c != nil {
33123346
result = append(result, map[string]interface{}{
33133347
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(c),
3348+
"shutdown_grace_period_seconds": c.ShutdownGracePeriodSeconds,
3349+
"shutdown_grace_period_critical_pods_seconds": c.ShutdownGracePeriodCriticalPodsSeconds,
33143350
})
33153351
}
33163352
return result

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

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,6 +2576,39 @@ func TestAccContainerCluster_withKubeletConfig(t *testing.T) {
25762576
})
25772577
}
25782578

2579+
func TestAccContainerCluster_withKubeletConfigShutdownGracePeriod(t *testing.T) {
2580+
t.Parallel()
2581+
2582+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
2583+
networkName := tpgcompute.BootstrapSharedTestNetwork(t, "gke-cluster")
2584+
subnetworkName := tpgcompute.BootstrapSubnet(t, "gke-cluster", networkName)
2585+
2586+
acctest.VcrTest(t, resource.TestCase{
2587+
PreCheck: func() { acctest.AccTestPreCheck(t) },
2588+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
2589+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
2590+
Steps: []resource.TestStep{
2591+
{
2592+
Config: testAccContainerCluster_withKubeletConfigShutdownGracePeriod(clusterName, networkName, subnetworkName, 120, 30),
2593+
Check: resource.ComposeTestCheckFunc(
2594+
resource.TestCheckResourceAttr(
2595+
"google_container_cluster.with_kubelet_config_shutdown",
2596+
"node_config.0.kubelet_config.0.shutdown_grace_period_seconds", "120"),
2597+
resource.TestCheckResourceAttr(
2598+
"google_container_cluster.with_kubelet_config_shutdown",
2599+
"node_config.0.kubelet_config.0.shutdown_grace_period_critical_pods_seconds", "30"),
2600+
),
2601+
},
2602+
{
2603+
ResourceName: "google_container_cluster.with_kubelet_config_shutdown",
2604+
ImportState: true,
2605+
ImportStateVerify: true,
2606+
ImportStateVerifyIgnore: []string{"deletion_protection"},
2607+
},
2608+
},
2609+
})
2610+
}
2611+
25792612
func TestAccContainerCluster_withNodeConfigFastSocket(t *testing.T) {
25802613
t.Parallel()
25812614

@@ -17457,6 +17490,28 @@ resource "google_container_cluster" "with_kubelet_config" {
1745717490
`, clusterName, networkName, subnetworkName, cpuManagerPolicy, memoryManagerPolicy, topologyManagerPolicy, topologyManagerScope)
1745817491
}
1745917492

17493+
func testAccContainerCluster_withKubeletConfigShutdownGracePeriod(clusterName, networkName, subnetworkName string, shutdownGracePeriodSeconds, shutdownGracePeriodCriticalPodsSeconds int) string {
17494+
return fmt.Sprintf(`
17495+
resource "google_container_cluster" "with_kubelet_config_shutdown" {
17496+
name = %q
17497+
location = "us-central1-a"
17498+
initial_node_count = 1
17499+
network = %q
17500+
subnetwork = %q
17501+
deletion_protection = false
17502+
17503+
node_config {
17504+
machine_type = "c4-standard-2"
17505+
spot = true
17506+
kubelet_config {
17507+
shutdown_grace_period_seconds = %d
17508+
shutdown_grace_period_critical_pods_seconds = %d
17509+
}
17510+
}
17511+
}
17512+
`, clusterName, networkName, subnetworkName, shutdownGracePeriodSeconds, shutdownGracePeriodCriticalPodsSeconds)
17513+
}
17514+
1746017515
func testAccContainerCluster_withCpuCfsQuotaPool(clusterName, npName, networkName, subnetworkName string) string {
1746117516
return fmt.Sprintf(`
1746217517
resource "google_container_cluster" "with_kubelet_config" {

mmv1/third_party/tgc_next/pkg/services/container/node_config.go

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,18 @@ func schemaNodeConfig() *schema.Schema {
853853
Optional: true,
854854
Description: `Defines the maximum allowed grace period (in seconds) to use when terminating pods in response to a soft eviction threshold being met.`,
855855
},
856+
"shutdown_grace_period_seconds": {
857+
Type: schema.TypeInt,
858+
Optional: true,
859+
Computed: true,
860+
Description: `Controls the total duration of time (in seconds) the node delays shutdown.`,
861+
},
862+
"shutdown_grace_period_critical_pods_seconds": {
863+
Type: schema.TypeInt,
864+
Optional: true,
865+
Computed: true,
866+
Description: `Controls the portion of total grace period (in seconds) that is specifically reserved for terminating critical pods.`,
867+
},
856868
"eviction_soft": {
857869
Type: schema.TypeList,
858870
Optional: true,
@@ -1371,6 +1383,18 @@ func schemaNodePoolAutoConfigNodeKubeletConfig() *schema.Schema {
13711383
Elem: &schema.Resource{
13721384
Schema: map[string]*schema.Schema{
13731385
"insecure_kubelet_readonly_port_enabled": schemaInsecureKubeletReadonlyPortEnabled(),
1386+
"shutdown_grace_period_seconds": {
1387+
Type: schema.TypeInt,
1388+
Optional: true,
1389+
Computed: true,
1390+
Description: `Controls the total duration of time (in seconds) the node delays shutdown.`,
1391+
},
1392+
"shutdown_grace_period_critical_pods_seconds": {
1393+
Type: schema.TypeInt,
1394+
Optional: true,
1395+
Computed: true,
1396+
Description: `Controls the portion of total grace period (in seconds) that is specifically reserved for terminating critical pods.`,
1397+
},
13741398
},
13751399
},
13761400
}
@@ -1903,6 +1927,14 @@ func expandKubeletConfig(v interface{}) *container.NodeKubeletConfig {
19031927
if evictionMaxPodGracePeriodSeconds, ok := cfg["eviction_max_pod_grace_period_seconds"]; ok {
19041928
kConfig.EvictionMaxPodGracePeriodSeconds = int64(evictionMaxPodGracePeriodSeconds.(int))
19051929
}
1930+
if shutdownGracePeriodSeconds, ok := cfg["shutdown_grace_period_seconds"]; ok {
1931+
kConfig.ShutdownGracePeriodSeconds = int64(shutdownGracePeriodSeconds.(int))
1932+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "ShutdownGracePeriodSeconds")
1933+
}
1934+
if shutdownGracePeriodCriticalPodsSeconds, ok := cfg["shutdown_grace_period_critical_pods_seconds"]; ok {
1935+
kConfig.ShutdownGracePeriodCriticalPodsSeconds = int64(shutdownGracePeriodCriticalPodsSeconds.(int))
1936+
kConfig.ForceSendFields = append(kConfig.ForceSendFields, "ShutdownGracePeriodCriticalPodsSeconds")
1937+
}
19061938
if v, ok := cfg["eviction_soft"]; ok && len(v.([]interface{})) > 0 {
19071939
es := v.([]interface{})[0].(map[string]interface{})
19081940
evictionSoft := &container.EvictionSignals{}
@@ -3058,27 +3090,29 @@ func flattenKubeletConfig(v interface{}) []map[string]interface{} {
30583090
return nil
30593091
}
30603092
transformed := map[string]interface{}{
3061-
"cpu_cfs_quota": c["cpuCfsQuota"],
3062-
"cpu_cfs_quota_period": c["cpuCfsQuotaPeriod"],
3063-
"cpu_manager_policy": c["cpuManagerPolicy"],
3064-
"memory_manager": flattenMemoryManager(c["memoryManager"]),
3065-
"topology_manager": flattenTopologyManager(c["topologyManager"]),
3066-
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(v),
3067-
"pod_pids_limit": c["podPidsLimit"],
3068-
"container_log_max_size": c["containerLogMaxSize"],
3069-
"container_log_max_files": c["containerLogMaxFiles"],
3070-
"image_gc_low_threshold_percent": c["imageGcLowThresholdPercent"],
3071-
"image_gc_high_threshold_percent": c["imageGcHighThresholdPercent"],
3072-
"image_minimum_gc_age": c["imageMinimumGcAge"],
3073-
"image_maximum_gc_age": c["imageMaximumGcAge"],
3074-
"allowed_unsafe_sysctls": c["allowedUnsafeSysctls"],
3075-
"single_process_oom_kill": c["singleProcessOomKill"],
3076-
"max_parallel_image_pulls": c["maxParallelImagePulls"],
3077-
"eviction_max_pod_grace_period_seconds": c["evictionMaxPodGracePeriodSeconds"],
3078-
"eviction_soft": flattenEvictionSignals(c["evictionSoft"]),
3079-
"eviction_soft_grace_period": flattenEvictionGracePeriod(c["evictionSoftGracePeriod"]),
3080-
"eviction_minimum_reclaim": flattenEvictionMinimumReclaim(c["evictionMinimumReclaim"]),
3081-
"crash_loop_back_off": flattenCrashLoopBackOffConfig(c["crashLoopBackOff"]),
3093+
"cpu_cfs_quota": c["cpuCfsQuota"],
3094+
"cpu_cfs_quota_period": c["cpuCfsQuotaPeriod"],
3095+
"cpu_manager_policy": c["cpuManagerPolicy"],
3096+
"memory_manager": flattenMemoryManager(c["memoryManager"]),
3097+
"topology_manager": flattenTopologyManager(c["topologyManager"]),
3098+
"insecure_kubelet_readonly_port_enabled": flattenInsecureKubeletReadonlyPortEnabled(v),
3099+
"pod_pids_limit": c["podPidsLimit"],
3100+
"container_log_max_size": c["containerLogMaxSize"],
3101+
"container_log_max_files": c["containerLogMaxFiles"],
3102+
"image_gc_low_threshold_percent": c["imageGcLowThresholdPercent"],
3103+
"image_gc_high_threshold_percent": c["imageGcHighThresholdPercent"],
3104+
"image_minimum_gc_age": c["imageMinimumGcAge"],
3105+
"image_maximum_gc_age": c["imageMaximumGcAge"],
3106+
"allowed_unsafe_sysctls": c["allowedUnsafeSysctls"],
3107+
"single_process_oom_kill": c["singleProcessOomKill"],
3108+
"max_parallel_image_pulls": c["maxParallelImagePulls"],
3109+
"eviction_max_pod_grace_period_seconds": c["evictionMaxPodGracePeriodSeconds"],
3110+
"shutdown_grace_period_seconds": c["shutdownGracePeriodSeconds"],
3111+
"shutdown_grace_period_critical_pods_seconds": c["shutdownGracePeriodCriticalPodsSeconds"],
3112+
"eviction_soft": flattenEvictionSignals(c["evictionSoft"]),
3113+
"eviction_soft_grace_period": flattenEvictionGracePeriod(c["evictionSoftGracePeriod"]),
3114+
"eviction_minimum_reclaim": flattenEvictionMinimumReclaim(c["evictionMinimumReclaim"]),
3115+
"crash_loop_back_off": flattenCrashLoopBackOffConfig(c["crashLoopBackOff"]),
30823116
}
30833117

30843118
return []map[string]interface{}{transformed}
@@ -3145,6 +3179,8 @@ func flattenNodePoolAutoConfigNodeKubeletConfig(v interface{}) []map[string]inte
31453179
transformed := map[string]interface{}{}
31463180
if c != nil {
31473181
transformed["insecure_kubelet_readonly_port_enabled"] = flattenInsecureKubeletReadonlyPortEnabled(c)
3182+
transformed["shutdown_grace_period_seconds"] = c["shutdownGracePeriodSeconds"]
3183+
transformed["shutdown_grace_period_critical_pods_seconds"] = c["shutdownGracePeriodCriticalPodsSeconds"]
31483184
}
31493185

31503186
return []map[string]interface{}{transformed}

0 commit comments

Comments
 (0)