Skip to content

Commit

Permalink
Graduate support of GKE Queued Provisioning to GA (#10053) (#17549)
Browse files Browse the repository at this point in the history
[upstream:dd27044950e3806f23f260a14c04eada189880a0]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 12, 2024
1 parent 4da62e7 commit ac9f220
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/10053.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: promoted `google_container_node_pool.queued_provisioning` to GA (ga)
```
35 changes: 35 additions & 0 deletions google/services/container/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ var schemaNodePool = map[string]*schema.Schema{
},
},

"queued_provisioning": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: `Specifies the configuration of queued provisioning`,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
ForceNew: true,
Description: `Whether nodes in this node pool are obtainable solely through the ProvisioningRequest API`,
},
},
},
},

"max_pods_per_node": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -911,6 +929,15 @@ func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool,
}
}

if v, ok := d.GetOk(prefix + "queued_provisioning"); ok {
if v.([]interface{}) != nil && v.([]interface{})[0] != nil {
queued_provisioning := v.([]interface{})[0].(map[string]interface{})
np.QueuedProvisioning = &container.QueuedProvisioning{
Enabled: queued_provisioning["enabled"].(bool),
}
}
}

if v, ok := d.GetOk(prefix + "max_pods_per_node"); ok {
np.MaxPodsConstraint = &container.MaxPodsConstraint{
MaxPodsPerNode: int64(v.(int)),
Expand Down Expand Up @@ -1104,6 +1131,14 @@ func flattenNodePool(d *schema.ResourceData, config *transport_tpg.Config, np *c
}
}

if np.QueuedProvisioning != nil {
nodePool["queued_provisioning"] = []map[string]interface{}{
{
"enabled": np.QueuedProvisioning.Enabled,
},
}
}

if np.MaxPodsConstraint != nil {
nodePool["max_pods_per_node"] = np.MaxPodsConstraint.MaxPodsPerNode
}
Expand Down
72 changes: 72 additions & 0 deletions google/services/container/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,78 @@ resource "google_container_node_pool" "np" {
`, cluster, networkName, subnetworkName, policyName, np)
}

func TestAccContainerNodePool_enableQueuedProvisioning(t *testing.T) {
t.Parallel()

cluster := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
np := fmt.Sprintf("tf-test-nodepool-%s", acctest.RandString(t, 10))
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckContainerNodePoolDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerNodePool_enableQueuedProvisioning(cluster, np, networkName, subnetworkName, true),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_config.0.machine_type", "n1-standard-2"),
resource.TestCheckResourceAttr("google_container_node_pool.np",
"node_config.0.reservation_affinity.0.consume_reservation_type", "NO_RESERVATION"),
resource.TestCheckResourceAttr("google_container_node_pool.np", "queued_provisioning.0.enabled", "true"),
),
},
{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
},
},
})
}

func testAccContainerNodePool_enableQueuedProvisioning(cluster, np, networkName, subnetworkName string, enabled bool) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
min_master_version = "1.28"
deletion_protection = false
network = "%s"
subnetwork = "%s"
}
resource "google_container_node_pool" "np" {
name = "%s"
location = "us-central1-a"
cluster = google_container_cluster.cluster.name
autoscaling {
total_min_node_count = 0
total_max_node_count = 1
}
node_config {
machine_type = "n1-standard-2"
guest_accelerator {
type = "nvidia-tesla-t4"
count = 1
gpu_driver_installation_config {
gpu_driver_version = "LATEST"
}
}
reservation_affinity {
consume_reservation_type = "NO_RESERVATION"
}
}
queued_provisioning {
enabled = %t
}
}
`, cluster, networkName, subnetworkName, np, enabled)
}

func TestAccContainerNodePool_threadsPerCore(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/container_node_pool.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ cluster.
* `placement_policy` - (Optional) Specifies a custom placement policy for the
nodes.

* `queued_provisioning` - (Optional, Beta) Specifies node pool-level settings of queued provisioning.
* `queued_provisioning` - (Optional) Specifies node pool-level settings of queued provisioning.
Structure is [documented below](#nested_queued_provisioning).

<a name="nested_autoscaling"></a>The `autoscaling` block supports (either total or per zone limits are required):
Expand Down

0 comments on commit ac9f220

Please sign in to comment.