Skip to content

Commit 1368d14

Browse files
Add MaxRunDuration (#12840) (#9163)
[upstream:44ed8b0e5fae90e09b1c2989b0798e4a338ae3f0] Signed-off-by: Modular Magician <[email protected]>
1 parent e7d277b commit 1368d14

File tree

5 files changed

+204
-0
lines changed

5 files changed

+204
-0
lines changed

Diff for: .changelog/12840.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note: enhancement
2+
container: added `max_run_duration` to `node_config` in `google_container_cluster` and `google_container_node_pool`
3+
```

Diff for: google-beta/services/container/node_config.go

+11
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,12 @@ func schemaNodeConfig() *schema.Schema {
803803
ValidateFunc: validation.StringInSlice([]string{"STANDARD_ENCRYPTION", "EPHEMERAL_KEY_ENCRYPTION"}, false),
804804
Description: `LocalSsdEncryptionMode specified the method used for encrypting the local SSDs attached to the node.`,
805805
},
806+
"max_run_duration": {
807+
Type: schema.TypeString,
808+
Optional: true,
809+
ForceNew: true,
810+
Description: `The runtime of each node in the node pool in seconds, terminated by 's'. Example: "3600s".`,
811+
},
806812
},
807813
},
808814
}
@@ -1181,6 +1187,10 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
11811187
nc.LocalSsdEncryptionMode = v.(string)
11821188
}
11831189

1190+
if v, ok := nodeConfig["max_run_duration"]; ok {
1191+
nc.MaxRunDuration = v.(string)
1192+
}
1193+
11841194
if v, ok := nodeConfig["host_maintenance_policy"]; ok {
11851195
nc.HostMaintenancePolicy = expandHostMaintenancePolicy(v)
11861196
}
@@ -1559,6 +1569,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
15591569
"linux_node_config": flattenLinuxNodeConfig(c.LinuxNodeConfig),
15601570
"node_group": c.NodeGroup,
15611571
"advanced_machine_features": flattenAdvancedMachineFeaturesConfig(c.AdvancedMachineFeatures),
1572+
"max_run_duration": c.MaxRunDuration,
15621573
"sole_tenant_config": flattenSoleTenantConfig(c.SoleTenantConfig),
15631574
"fast_socket": flattenFastSocket(c.FastSocket),
15641575
"resource_manager_tags": flattenResourceManagerTags(c.ResourceManagerTags),

Diff for: google-beta/services/container/resource_container_cluster_test.go

+93
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,50 @@ func TestAccContainerCluster_withLocalSsdEncryptionMode(t *testing.T) {
461461
})
462462
}
463463

464+
func TestAccContainerCluster_withMaxRunDuration(t *testing.T) {
465+
t.Parallel()
466+
467+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
468+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
469+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
470+
npName := fmt.Sprintf("tf-test-node-pool-%s", acctest.RandString(t, 10))
471+
472+
acctest.VcrTest(t, resource.TestCase{
473+
PreCheck: func() { acctest.AccTestPreCheck(t) },
474+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
475+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
476+
Steps: []resource.TestStep{
477+
{
478+
Config: testAccContainerCluster_withMaxRunDuration(clusterName, npName, networkName, subnetworkName, "3600s"),
479+
},
480+
{
481+
ResourceName: "google_container_cluster.max_run_duration",
482+
ImportState: true,
483+
ImportStateVerify: true,
484+
ImportStateVerifyIgnore: []string{"deletion_protection"},
485+
},
486+
{
487+
Config: testAccContainerCluster_withMaxRunDuration(clusterName, npName, networkName, subnetworkName, "1800s"),
488+
},
489+
{
490+
ResourceName: "google_container_cluster.max_run_duration",
491+
ImportState: true,
492+
ImportStateVerify: true,
493+
ImportStateVerifyIgnore: []string{"deletion_protection"},
494+
},
495+
{
496+
Config: testAccContainerCluster_disableMaxRunDuration(clusterName, npName, networkName, subnetworkName),
497+
},
498+
{
499+
ResourceName: "google_container_cluster.max_run_duration",
500+
ImportState: true,
501+
ImportStateVerify: true,
502+
ImportStateVerifyIgnore: []string{"deletion_protection"},
503+
},
504+
},
505+
})
506+
}
507+
464508
func TestAccContainerCluster_withILBSubsetting(t *testing.T) {
465509
t.Parallel()
466510

@@ -6708,6 +6752,55 @@ resource "google_container_cluster" "local_ssd_encryption_mode" {
67086752
`, clusterName, npName, mode, networkName, subnetworkName)
67096753
}
67106754

6755+
func testAccContainerCluster_disableMaxRunDuration(clusterName, npName, networkName, subnetworkName string) string {
6756+
return fmt.Sprintf(`
6757+
resource "google_container_cluster" "max_run_duration" {
6758+
name = "%s"
6759+
location = "us-central1-a"
6760+
release_channel {
6761+
channel = "RAPID"
6762+
}
6763+
6764+
node_pool {
6765+
name = "%s"
6766+
initial_node_count = 1
6767+
node_config {
6768+
machine_type = "n1-standard-2"
6769+
}
6770+
}
6771+
6772+
deletion_protection = false
6773+
network = "%s"
6774+
subnetwork = "%s"
6775+
}
6776+
`, clusterName, npName, networkName, subnetworkName)
6777+
}
6778+
6779+
func testAccContainerCluster_withMaxRunDuration(clusterName, npName, networkName, subnetworkName, duration string) string {
6780+
return fmt.Sprintf(`
6781+
resource "google_container_cluster" "max_run_duration" {
6782+
name = "%s"
6783+
location = "us-central1-a"
6784+
release_channel {
6785+
channel = "RAPID"
6786+
}
6787+
6788+
node_pool {
6789+
name = "%s"
6790+
initial_node_count = 1
6791+
node_config {
6792+
machine_type = "n1-standard-2"
6793+
max_run_duration = "%s"
6794+
}
6795+
}
6796+
6797+
deletion_protection = false
6798+
network = "%s"
6799+
subnetwork = "%s"
6800+
}
6801+
`, clusterName, npName, duration, networkName, subnetworkName)
6802+
}
6803+
67116804
func testAccContainerCluster_withILBSubSetting(clusterName, npName, networkName, subnetworkName string) string {
67126805
return fmt.Sprintf(`
67136806
resource "google_container_cluster" "confidential_nodes" {

Diff for: google-beta/services/container/resource_container_node_pool_test.go

+95
Original file line numberDiff line numberDiff line change
@@ -4205,6 +4205,101 @@ resource "google_container_node_pool" "np" {
42054205
`, clusterName, mode, networkName, subnetworkName, np, mode)
42064206
}
42074207

4208+
func TestAccContainerNodePool_withMaxRunDuration(t *testing.T) {
4209+
t.Parallel()
4210+
4211+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
4212+
np := fmt.Sprintf("tf-test-cluster-nodepool-%s", acctest.RandString(t, 10))
4213+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
4214+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
4215+
4216+
acctest.VcrTest(t, resource.TestCase{
4217+
PreCheck: func() { acctest.AccTestPreCheck(t) },
4218+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4219+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
4220+
Steps: []resource.TestStep{
4221+
{
4222+
Config: testAccContainerNodePool_withMaxRunDuration(clusterName, np, networkName, subnetworkName, "3600s"),
4223+
},
4224+
{
4225+
ResourceName: "google_container_node_pool.np",
4226+
ImportState: true,
4227+
ImportStateVerify: true,
4228+
},
4229+
{
4230+
Config: testAccContainerNodePool_withMaxRunDuration(clusterName, np, networkName, subnetworkName, "1800s"),
4231+
},
4232+
{
4233+
ResourceName: "google_container_node_pool.np",
4234+
ImportState: true,
4235+
ImportStateVerify: true,
4236+
},
4237+
{
4238+
Config: testAccContainerNodePool_disableMaxRunDuration(clusterName, np, networkName, subnetworkName),
4239+
},
4240+
{
4241+
ResourceName: "google_container_node_pool.np",
4242+
ImportState: true,
4243+
ImportStateVerify: true,
4244+
},
4245+
},
4246+
})
4247+
}
4248+
4249+
func testAccContainerNodePool_withMaxRunDuration(clusterName, np, networkName, subnetworkName, duration string) string {
4250+
return fmt.Sprintf(`
4251+
resource "google_container_cluster" "cluster" {
4252+
name = "%s"
4253+
location = "us-central1-a"
4254+
initial_node_count = 1
4255+
node_config {
4256+
max_run_duration = "%s"
4257+
machine_type = "n1-standard-1"
4258+
}
4259+
deletion_protection = false
4260+
network = "%s"
4261+
subnetwork = "%s"
4262+
}
4263+
4264+
resource "google_container_node_pool" "np" {
4265+
name = "%s"
4266+
location = "us-central1-a"
4267+
cluster = google_container_cluster.cluster.name
4268+
initial_node_count = 1
4269+
node_config {
4270+
machine_type = "n1-standard-1"
4271+
max_run_duration = "%s"
4272+
}
4273+
}
4274+
`, clusterName, duration, networkName, subnetworkName, np, duration)
4275+
}
4276+
4277+
func testAccContainerNodePool_disableMaxRunDuration(clusterName, np, networkName, subnetworkName string) string {
4278+
return fmt.Sprintf(`
4279+
resource "google_container_cluster" "cluster" {
4280+
name = "%s"
4281+
location = "us-central1-a"
4282+
initial_node_count = 1
4283+
node_config {
4284+
machine_type = "n1-standard-1"
4285+
}
4286+
deletion_protection = false
4287+
network = "%s"
4288+
subnetwork = "%s"
4289+
}
4290+
4291+
resource "google_container_node_pool" "np" {
4292+
name = "%s"
4293+
location = "us-central1-a"
4294+
cluster = google_container_cluster.cluster.name
4295+
initial_node_count = 1
4296+
node_config {
4297+
machine_type = "n1-standard-1"
4298+
}
4299+
}
4300+
`, clusterName, networkName, subnetworkName, np)
4301+
}
4302+
42084303
func TestAccContainerNodePool_tpuTopology(t *testing.T) {
42094304
t.Parallel()
42104305
t.Skip("https://github.com/hashicorp/terraform-provider-google/issues/15254#issuecomment-1646277473")

Diff for: website/docs/r/container_cluster.html.markdown

+2
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,8 @@ gvnic {
918918
* `resource_labels` - (Optional) The GCP labels (key/value pairs) to be applied to each node. Refer [here](https://cloud.google.com/kubernetes-engine/docs/how-to/creating-managing-labels)
919919
for how these labels are applied to clusters, node pools and nodes.
920920

921+
* `max_run_duration` - (Optional) The runtime of each node in the node pool in seconds, terminated by 's'. Example: "3600s".
922+
921923
* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
922924
attached to each cluster node. Defaults to 0.
923925

0 commit comments

Comments
 (0)