Skip to content

Commit

Permalink
Promoting GKE Autoscaling Profiles to GA (#9558) (#16653)
Browse files Browse the repository at this point in the history
[upstream:87e3546280174e47e7816596162f2a9148d25062]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Dec 1, 2023
1 parent 2d02e20 commit 08df2c8
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/9558.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
container: promoted GKE Autoscaling Profiles to GA in the `cluster_autoscaling` block in `google_container_cluster`
```
10 changes: 10 additions & 0 deletions google/services/container/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,14 @@ func ResourceContainerCluster() *schema.Resource {
},
},
},
"autoscaling_profile": {
Type: schema.TypeString,
Default: "BALANCED",
Optional: true,
DiffSuppressFunc: suppressDiffForAutopilot,
ValidateFunc: validation.StringInSlice([]string{"BALANCED", "OPTIMIZE_UTILIZATION"}, false),
Description: `Configuration options for the Autoscaling profile feature, which lets you choose whether the cluster autoscaler should optimize for resource utilization or resource availability when deciding to remove nodes from a cluster. Can be BALANCED or OPTIMIZE_UTILIZATION. Defaults to BALANCED.`,
},
},
},
},
Expand Down Expand Up @@ -4180,6 +4188,7 @@ func expandClusterAutoscaling(configured interface{}, d *schema.ResourceData) *c
return &container.ClusterAutoscaling{
EnableNodeAutoprovisioning: config["enabled"].(bool),
ResourceLimits: resourceLimits,
AutoscalingProfile: config["autoscaling_profile"].(string),
AutoprovisioningNodePoolDefaults: expandAutoProvisioningDefaults(config["auto_provisioning_defaults"], d),
}
}
Expand Down Expand Up @@ -5287,6 +5296,7 @@ func flattenClusterAutoscaling(a *container.ClusterAutoscaling) []map[string]int
} else {
r["enabled"] = false
}
r["autoscaling_profile"] = a.AutoscalingProfile

return []map[string]interface{}{r}
}
Expand Down
75 changes: 75 additions & 0 deletions google/services/container/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2864,6 +2864,62 @@ func TestAccContainerCluster_withSoleTenantGroup(t *testing.T) {
})
}

func TestAccContainerCluster_withAutoscalingProfile(t *testing.T) {
t.Parallel()
clusterName := fmt.Sprintf("cluster-test-%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: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAutoscalingProfile(clusterName, "BALANCED", networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.autoscaling_with_profile",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
{
Config: testAccContainerCluster_withAutoscalingProfile(clusterName, "OPTIMIZE_UTILIZATION", networkName, subnetworkName),
},
{
ResourceName: "google_container_cluster.autoscaling_with_profile",
ImportStateIdPrefix: "us-central1-a/",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_protection"},
},
},
})
}

func TestAccContainerCluster_withInvalidAutoscalingProfile(t *testing.T) {
// This is essentially a unit test, no interactions
acctest.SkipIfVcr(t)
t.Parallel()
clusterName := fmt.Sprintf("cluster-test-%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: testAccCheckContainerClusterDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccContainerCluster_withAutoscalingProfile(clusterName, "AS_CHEAP_AS_POSSIBLE", networkName, subnetworkName),
ExpectError: regexp.MustCompile(`expected cluster_autoscaling\.0\.autoscaling_profile to be one of \[BALANCED OPTIMIZE_UTILIZATION\], got AS_CHEAP_AS_POSSIBLE`),
},
},
})
}

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

Expand Down Expand Up @@ -5561,6 +5617,25 @@ resource "google_container_cluster" "with_node_pool" {
`, cluster, nodePool, networkName, subnetworkName)
}

func testAccContainerCluster_withAutoscalingProfile(cluster, autoscalingProfile, networkName, subnetworkName string) string {
config := fmt.Sprintf(`
resource "google_container_cluster" "autoscaling_with_profile" {
name = "%s"
location = "us-central1-a"
initial_node_count = 1
cluster_autoscaling {
enabled = false
autoscaling_profile = "%s"
}
deletion_protection = false
network = "%s"
subnetwork = "%s"
}
`, cluster, autoscalingProfile, networkName, subnetworkName)
return config
}

func testAccContainerCluster_autoprovisioning(cluster, networkName, subnetworkName string, autoprovisioning, withNetworkTag bool) string {
config := fmt.Sprintf(`
data "google_container_engine_versions" "central1a" {
Expand Down

0 comments on commit 08df2c8

Please sign in to comment.