Skip to content

Commit f47978f

Browse files
Add flex start (#13691) (#22508)
[upstream:ab94f3ad60f67c52ca28d7208018751aaeb995ef] Signed-off-by: Modular Magician <[email protected]>
1 parent 6862ecd commit f47978f

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,12 @@ func schemaNodeConfig() *schema.Schema {
830830
ForceNew: true,
831831
Description: `The runtime of each node in the node pool in seconds, terminated by 's'. Example: "3600s".`,
832832
},
833+
"flex_start": {
834+
Type: schema.TypeBool,
835+
Optional: true,
836+
ForceNew: true,
837+
Description: `Enables Flex Start provisioning model for the node pool`,
838+
},
833839
},
834840
},
835841
}
@@ -1209,6 +1215,10 @@ func expandNodeConfig(v interface{}) *container.NodeConfig {
12091215
nc.MaxRunDuration = v.(string)
12101216
}
12111217

1218+
if v, ok := nodeConfig["flex_start"]; ok {
1219+
nc.FlexStart = v.(bool)
1220+
}
1221+
12121222
if v, ok := nodeConfig["confidential_nodes"]; ok {
12131223
nc.ConfidentialNodes = expandConfidentialNodes(v)
12141224
}
@@ -1608,6 +1618,7 @@ func flattenNodeConfig(c *container.NodeConfig, v interface{}) []map[string]inte
16081618
"node_group": c.NodeGroup,
16091619
"advanced_machine_features": flattenAdvancedMachineFeaturesConfig(c.AdvancedMachineFeatures),
16101620
"max_run_duration": c.MaxRunDuration,
1621+
"flex_start": c.FlexStart,
16111622
"sole_tenant_config": flattenSoleTenantConfig(c.SoleTenantConfig),
16121623
"fast_socket": flattenFastSocket(c.FastSocket),
16131624
"resource_manager_tags": flattenResourceManagerTags(c.ResourceManagerTags),

google/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

@@ -6603,6 +6635,52 @@ resource "google_container_cluster" "max_run_duration" {
66036635
`, clusterName, npName, duration, networkName, subnetworkName)
66046636
}
66056637

6638+
func testAccContainerCluster_withFlexStart(clusterName, npName, networkName, subnetworkName string) string {
6639+
return fmt.Sprintf(`
6640+
resource "google_container_cluster" "flex_start" {
6641+
min_master_version = "1.32.3-gke.1717000"
6642+
6643+
name = "%s"
6644+
location = "us-central1-a"
6645+
6646+
release_channel {
6647+
channel = "RAPID"
6648+
}
6649+
6650+
6651+
node_pool {
6652+
name = "%s"
6653+
initial_node_count = 0
6654+
autoscaling {
6655+
total_min_node_count = 0
6656+
total_max_node_count = 1
6657+
}
6658+
6659+
node_config {
6660+
machine_type = "n1-standard-1"
6661+
flex_start = true
6662+
max_run_duration = "604800s"
6663+
6664+
reservation_affinity {
6665+
consume_reservation_type = "NO_RESERVATION"
6666+
}
6667+
6668+
taint {
6669+
key = "taint_key"
6670+
value = "taint_value"
6671+
effect = "NO_SCHEDULE"
6672+
}
6673+
}
6674+
}
6675+
6676+
deletion_protection = false
6677+
network = "%s"
6678+
subnetwork = "%s"
6679+
6680+
}
6681+
`, clusterName, npName, networkName, subnetworkName)
6682+
}
6683+
66066684
func testAccContainerCluster_withILBSubSetting(clusterName, npName, networkName, subnetworkName string) string {
66076685
return fmt.Sprintf(`
66086686
resource "google_container_cluster" "confidential_nodes" {

google/services/container/resource_container_node_pool_test.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4327,6 +4327,80 @@ resource "google_container_node_pool" "np" {
43274327
`, clusterName, networkName, subnetworkName, np)
43284328
}
43294329

4330+
func TestAccContainerNodePool_withFlexStart(t *testing.T) {
4331+
t.Parallel()
4332+
4333+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
4334+
np := fmt.Sprintf("tf-test-cluster-nodepool-%s", acctest.RandString(t, 10))
4335+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
4336+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
4337+
4338+
acctest.VcrTest(t, resource.TestCase{
4339+
PreCheck: func() { acctest.AccTestPreCheck(t) },
4340+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
4341+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
4342+
Steps: []resource.TestStep{
4343+
{
4344+
Config: testAccContainerNodePool_withFlexStart(clusterName, np, networkName, subnetworkName),
4345+
Check: resource.ComposeTestCheckFunc(
4346+
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.machine_type", "n1-standard-1"),
4347+
resource.TestCheckResourceAttr("google_container_node_pool.np",
4348+
"node_config.0.reservation_affinity.0.consume_reservation_type", "NO_RESERVATION"),
4349+
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.flex_start", "true"),
4350+
),
4351+
},
4352+
{
4353+
ResourceName: "google_container_node_pool.np",
4354+
ImportState: true,
4355+
ImportStateVerify: true,
4356+
ImportStateVerifyIgnore: []string{"node_config.0.taint"},
4357+
},
4358+
},
4359+
})
4360+
}
4361+
4362+
func testAccContainerNodePool_withFlexStart(clusterName, np, networkName, subnetworkName string) string {
4363+
return fmt.Sprintf(`
4364+
resource "google_container_cluster" "cluster" {
4365+
min_master_version = "1.32.3-gke.1717000"
4366+
4367+
name = "%s"
4368+
location = "us-central1-a"
4369+
initial_node_count = 1
4370+
deletion_protection = false
4371+
network = "%s"
4372+
subnetwork = "%s"
4373+
}
4374+
4375+
resource "google_container_node_pool" "np" {
4376+
name = "%s"
4377+
location = "us-central1-a"
4378+
cluster = google_container_cluster.cluster.name
4379+
initial_node_count = 0
4380+
autoscaling {
4381+
total_min_node_count = 0
4382+
total_max_node_count = 1
4383+
}
4384+
4385+
node_config {
4386+
machine_type = "n1-standard-1"
4387+
flex_start = true
4388+
max_run_duration = "604800s"
4389+
4390+
reservation_affinity {
4391+
consume_reservation_type = "NO_RESERVATION"
4392+
}
4393+
4394+
taint {
4395+
key = "taint_key"
4396+
value = "taint_value"
4397+
effect = "NO_SCHEDULE"
4398+
}
4399+
}
4400+
}
4401+
`, clusterName, networkName, subnetworkName, np)
4402+
}
4403+
43304404
func TestAccContainerNodePool_tpuTopology(t *testing.T) {
43314405
t.Parallel()
43324406
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)