Skip to content

Commit 2744b15

Browse files
modular-magicianslevenick
authored andcommitted
Add flex start (#13691) (#9885)
[upstream:ab94f3ad60f67c52ca28d7208018751aaeb995ef] Signed-off-by: Modular Magician <[email protected]>
1 parent 90150af commit 2744b15

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed

.changelog/13691.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 `flex_start` to `node_config` in `google_container_cluster` and `google_container_node_pool`
3+
```

google-beta/services/container/node_config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -862,6 +862,12 @@ func schemaNodeConfig() *schema.Schema {
862862
ForceNew: true,
863863
Description: `The runtime of each node in the node pool in seconds, terminated by 's'. Example: "3600s".`,
864864
},
865+
"flex_start": {
866+
Type: schema.TypeBool,
867+
Optional: true,
868+
ForceNew: true,
869+
Description: `Enables Flex Start provisioning model for the node pool`,
870+
},
865871
},
866872
},
867873
}
@@ -1248,6 +1254,10 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
12481254
nc.MaxRunDuration = v.(string)
12491255
}
12501256

1257+
if v, ok := nodeConfig["flex_start"]; ok {
1258+
nc.FlexStart = v.(bool)
1259+
}
1260+
12511261
if v, ok := nodeConfig["host_maintenance_policy"]; ok {
12521262
nc.HostMaintenancePolicy = expandHostMaintenancePolicy(v)
12531263
}
@@ -1671,6 +1681,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
16711681
"node_group": c.NodeGroup,
16721682
"advanced_machine_features": flattenAdvancedMachineFeaturesConfig(c.AdvancedMachineFeatures),
16731683
"max_run_duration": c.MaxRunDuration,
1684+
"flex_start": c.FlexStart,
16741685
"sole_tenant_config": flattenSoleTenantConfig(c.SoleTenantConfig),
16751686
"fast_socket": flattenFastSocket(c.FastSocket),
16761687
"resource_manager_tags": flattenResourceManagerTags(c.ResourceManagerTags),

google-beta/services/container/resource_container_cluster_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,38 @@ func TestAccContainerCluster_withMaxRunDuration(t *testing.T) {
505505
})
506506
}
507507

508+
func TestAccContainerCluster_withFlexStart(t *testing.T) {
509+
t.Parallel()
510+
511+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
512+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
513+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
514+
npName := fmt.Sprintf("tf-test-node-pool-%s", acctest.RandString(t, 10))
515+
516+
acctest.VcrTest(t, resource.TestCase{
517+
PreCheck: func() { acctest.AccTestPreCheck(t) },
518+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
519+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
520+
Steps: []resource.TestStep{
521+
{
522+
Config: testAccContainerCluster_withFlexStart(clusterName, npName, networkName, subnetworkName),
523+
Check: resource.ComposeTestCheckFunc(
524+
resource.TestCheckResourceAttr("google_container_cluster.flex_start", "node_pool.0.node_config.0.machine_type", "n1-standard-1"),
525+
resource.TestCheckResourceAttr("google_container_cluster.flex_start",
526+
"node_pool.0.node_config.0.reservation_affinity.0.consume_reservation_type", "NO_RESERVATION"),
527+
resource.TestCheckResourceAttr("google_container_cluster.flex_start", "node_pool.0.node_config.0.flex_start", "true"),
528+
),
529+
},
530+
{
531+
ResourceName: "google_container_cluster.flex_start",
532+
ImportState: true,
533+
ImportStateVerify: true,
534+
ImportStateVerifyIgnore: []string{"deletion_protection", "min_master_version", "node_pool.0.node_config.0.taint"},
535+
},
536+
},
537+
})
538+
}
539+
508540
func TestAccContainerCluster_withILBSubsetting(t *testing.T) {
509541
t.Parallel()
510542

@@ -7045,6 +7077,52 @@ resource "google_container_cluster" "max_run_duration" {
70457077
`, clusterName, npName, duration, networkName, subnetworkName)
70467078
}
70477079

7080+
func testAccContainerCluster_withFlexStart(clusterName, npName, networkName, subnetworkName string) string {
7081+
return fmt.Sprintf(`
7082+
resource "google_container_cluster" "flex_start" {
7083+
min_master_version = "1.32.3-gke.1717000"
7084+
7085+
name = "%s"
7086+
location = "us-central1-a"
7087+
7088+
release_channel {
7089+
channel = "RAPID"
7090+
}
7091+
7092+
7093+
node_pool {
7094+
name = "%s"
7095+
initial_node_count = 0
7096+
autoscaling {
7097+
total_min_node_count = 0
7098+
total_max_node_count = 1
7099+
}
7100+
7101+
node_config {
7102+
machine_type = "n1-standard-1"
7103+
flex_start = true
7104+
max_run_duration = "604800s"
7105+
7106+
reservation_affinity {
7107+
consume_reservation_type = "NO_RESERVATION"
7108+
}
7109+
7110+
taint {
7111+
key = "taint_key"
7112+
value = "taint_value"
7113+
effect = "NO_SCHEDULE"
7114+
}
7115+
}
7116+
}
7117+
7118+
deletion_protection = false
7119+
network = "%s"
7120+
subnetwork = "%s"
7121+
7122+
}
7123+
`, clusterName, npName, networkName, subnetworkName)
7124+
}
7125+
70487126
func testAccContainerCluster_withILBSubSetting(clusterName, npName, networkName, subnetworkName string) string {
70497127
return fmt.Sprintf(`
70507128
resource "google_container_cluster" "confidential_nodes" {

google-beta/services/container/resource_container_node_pool_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4395,6 +4395,80 @@ resource "google_container_node_pool" "np" {
43954395
`, clusterName, networkName, subnetworkName, np)
43964396
}
43974397

4398+
func TestAccContainerNodePool_withFlexStart(t *testing.T) {
4399+
t.Parallel()
4400+
4401+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
4402+
np := fmt.Sprintf("tf-test-cluster-nodepool-%s", acctest.RandString(t, 10))
4403+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
4404+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
4405+
4406+
acctest.VcrTest(t, resource.TestCase{
4407+
PreCheck: func() { acctest.AccTestPreCheck(t) },
4408+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4409+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
4410+
Steps: []resource.TestStep{
4411+
{
4412+
Config: testAccContainerNodePool_withFlexStart(clusterName, np, networkName, subnetworkName),
4413+
Check: resource.ComposeTestCheckFunc(
4414+
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.machine_type", "n1-standard-1"),
4415+
resource.TestCheckResourceAttr("google_container_node_pool.np",
4416+
"node_config.0.reservation_affinity.0.consume_reservation_type", "NO_RESERVATION"),
4417+
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.flex_start", "true"),
4418+
),
4419+
},
4420+
{
4421+
ResourceName: "google_container_node_pool.np",
4422+
ImportState: true,
4423+
ImportStateVerify: true,
4424+
ImportStateVerifyIgnore: []string{"node_config.0.taint"},
4425+
},
4426+
},
4427+
})
4428+
}
4429+
4430+
func testAccContainerNodePool_withFlexStart(clusterName, np, networkName, subnetworkName string) string {
4431+
return fmt.Sprintf(`
4432+
resource "google_container_cluster" "cluster" {
4433+
min_master_version = "1.32.3-gke.1717000"
4434+
4435+
name = "%s"
4436+
location = "us-central1-a"
4437+
initial_node_count = 1
4438+
deletion_protection = false
4439+
network = "%s"
4440+
subnetwork = "%s"
4441+
}
4442+
4443+
resource "google_container_node_pool" "np" {
4444+
name = "%s"
4445+
location = "us-central1-a"
4446+
cluster = google_container_cluster.cluster.name
4447+
initial_node_count = 0
4448+
autoscaling {
4449+
total_min_node_count = 0
4450+
total_max_node_count = 1
4451+
}
4452+
4453+
node_config {
4454+
machine_type = "n1-standard-1"
4455+
flex_start = true
4456+
max_run_duration = "604800s"
4457+
4458+
reservation_affinity {
4459+
consume_reservation_type = "NO_RESERVATION"
4460+
}
4461+
4462+
taint {
4463+
key = "taint_key"
4464+
value = "taint_value"
4465+
effect = "NO_SCHEDULE"
4466+
}
4467+
}
4468+
}
4469+
`, clusterName, networkName, subnetworkName, np)
4470+
}
4471+
43984472
func TestAccContainerNodePool_tpuTopology(t *testing.T) {
43994473
t.Parallel()
44004474
t.Skip("https://github.com/hashicorp/terraform-provider-google/issues/15254#issuecomment-1646277473")

website/docs/r/container_cluster.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,8 @@ gvnic {
931931

932932
* `max_run_duration` - (Optional) The runtime of each node in the node pool in seconds, terminated by 's'. Example: "3600s".
933933

934+
* `flex_start` - (Optional) Enables Flex Start provisioning model for the node pool.
935+
934936
* `local_ssd_count` - (Optional) The amount of local SSD disks that will be
935937
attached to each cluster node. Defaults to 0.
936938

0 commit comments

Comments
 (0)