Skip to content

Commit b88d951

Browse files
container: bump pod_autoscaling to GA (#13997) (#23002)
[upstream:3995a11779dfe389b379bdf77c62b62581d86750] Signed-off-by: Modular Magician <magic-modules@google.com>
1 parent 7a89d85 commit b88d951

File tree

4 files changed

+151
-1
lines changed

4 files changed

+151
-1
lines changed

.changelog/13997.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: bump pod_autoscaling to GA
3+
```

google/services/container/resource_container_cluster.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,28 @@ func ResourceContainerCluster() *schema.Resource {
14541454
Description: `The Kubernetes version on the nodes. Must either be unset or set to the same value as min_master_version on create. Defaults to the default version set by GKE which is not necessarily the latest version. This only affects nodes in the default node pool. While a fuzzy version can be specified, it's recommended that you specify explicit versions as Terraform will see spurious diffs when fuzzy versions are used. See the google_container_engine_versions data source's version_prefix field to approximate fuzzy versions in a Terraform-compatible way. To update nodes in other node pools, use the version attribute on the node pool.`,
14551455
},
14561456

1457+
"pod_autoscaling": {
1458+
Type: schema.TypeList,
1459+
Optional: true,
1460+
Computed: true,
1461+
MaxItems: 1,
1462+
Description: `PodAutoscaling is used for configuration of parameters for workload autoscaling`,
1463+
Elem: &schema.Resource{
1464+
Schema: map[string]*schema.Schema{
1465+
"hpa_profile": {
1466+
Type: schema.TypeString,
1467+
Required: true,
1468+
ValidateFunc: validation.StringInSlice([]string{"NONE", "PERFORMANCE"}, false),
1469+
Description: `
1470+
HPA Profile is used to configure the Horizontal Pod Autoscaler (HPA) profile for the cluster.
1471+
Available options include:
1472+
- NONE: Customers explicitly opt-out of HPA profiles.
1473+
- PERFORMANCE: PERFORMANCE is used when customers opt-in to the performance HPA profile. In this profile we support a higher number of HPAs per cluster and faster metrics collection for workload autoscaling.
1474+
`,
1475+
},
1476+
},
1477+
},
1478+
},
14571479
"secret_manager_config": {
14581480
Type: schema.TypeList,
14591481
Optional: true,
@@ -2365,6 +2387,7 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
23652387
AddonsConfig: expandClusterAddonsConfig(d.Get("addons_config")),
23662388
EnableKubernetesAlpha: d.Get("enable_kubernetes_alpha").(bool),
23672389
IpAllocationPolicy: ipAllocationBlock,
2390+
PodAutoscaling: expandPodAutoscaling(d.Get("pod_autoscaling")),
23682391
SecretManagerConfig: expandSecretManagerConfig(d.Get("secret_manager_config")),
23692392
Autoscaling: expandClusterAutoscaling(d.Get("cluster_autoscaling"), d),
23702393
BinaryAuthorization: expandBinaryAuthorization(d.Get("binary_authorization")),
@@ -3025,6 +3048,10 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
30253048
return err
30263049
}
30273050

3051+
if err := d.Set("pod_autoscaling", flattenPodAutoscaling(cluster.PodAutoscaling)); err != nil {
3052+
return err
3053+
}
3054+
30283055
if err := d.Set("secret_manager_config", flattenSecretManagerConfig(cluster.SecretManagerConfig)); err != nil {
30293056
return err
30303057
}
@@ -4048,6 +4075,33 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
40484075
log.Printf("[INFO] GKE cluster %s database encryption config has been updated", d.Id())
40494076
}
40504077

4078+
if d.HasChange("pod_autoscaling") {
4079+
c := d.Get("pod_autoscaling")
4080+
req := &container.UpdateClusterRequest{
4081+
Update: &container.ClusterUpdate{
4082+
DesiredPodAutoscaling: expandPodAutoscaling(c),
4083+
},
4084+
}
4085+
4086+
updateF := func() error {
4087+
name := containerClusterFullName(project, location, clusterName)
4088+
clusterUpdateCall := config.NewContainerClient(userAgent).Projects.Locations.Clusters.Update(name, req)
4089+
if config.UserProjectOverride {
4090+
clusterUpdateCall.Header().Add("X-Goog-User-Project", project)
4091+
}
4092+
op, err := clusterUpdateCall.Do()
4093+
if err != nil {
4094+
return err
4095+
}
4096+
// Wait until it's updated
4097+
return ContainerOperationWait(config, op, project, location, "updating Horizontal pod Autoscaling profile", userAgent, d.Timeout(schema.TimeoutUpdate))
4098+
}
4099+
if err := transport_tpg.LockedCall(lockKey, updateF); err != nil {
4100+
return err
4101+
}
4102+
log.Printf("[INFO] GKE cluster %s horizontal pod autoscaling profile has been updated", d.Id())
4103+
}
4104+
40514105
if d.HasChange("secret_manager_config") {
40524106
c := d.Get("secret_manager_config")
40534107
req := &container.UpdateClusterRequest{
@@ -5472,6 +5526,28 @@ func expandIdentityServiceConfig(configured interface{}) *container.IdentityServ
54725526
return v
54735527
}
54745528

5529+
func expandPodAutoscaling(configured interface{}) *container.PodAutoscaling {
5530+
if configured == nil {
5531+
return nil
5532+
}
5533+
5534+
podAutoscaling := &container.PodAutoscaling{}
5535+
5536+
configs := configured.([]interface{})
5537+
5538+
if len(configs) == 0 || configs[0] == nil {
5539+
return nil
5540+
}
5541+
5542+
config := configs[0].(map[string]interface{})
5543+
5544+
if v, ok := config["hpa_profile"]; ok {
5545+
podAutoscaling.HpaProfile = v.(string)
5546+
}
5547+
5548+
return podAutoscaling
5549+
}
5550+
54755551
func expandSecretManagerConfig(configured interface{}) *container.SecretManagerConfig {
54765552
l := configured.([]interface{})
54775553
if len(l) == 0 || l[0] == nil {
@@ -6364,6 +6440,19 @@ func flattenMasterAuthorizedNetworksConfig(c *container.MasterAuthorizedNetworks
63646440
return []map[string]interface{}{result}
63656441
}
63666442

6443+
func flattenPodAutoscaling(c *container.PodAutoscaling) []map[string]interface{} {
6444+
config := make([]map[string]interface{}, 0, 1)
6445+
6446+
if c == nil {
6447+
return config
6448+
}
6449+
6450+
config = append(config, map[string]interface{}{
6451+
"hpa_profile": c.HpaProfile,
6452+
})
6453+
return config
6454+
}
6455+
63676456
func flattenSecretManagerConfig(c *container.SecretManagerConfig) []map[string]interface{} {
63686457
if c == nil {
63696458
return []map[string]interface{}{

google/services/container/resource_container_cluster_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,64 @@ func TestUnitContainerCluster_Rfc3339TimeDiffSuppress(t *testing.T) {
851851
}
852852
}
853853

854+
func TestAccContainerCluster_withPodAutoscaling(t *testing.T) {
855+
t.Parallel()
856+
857+
clusterName := fmt.Sprintf("tf-test-cluster-%s", acctest.RandString(t, 10))
858+
networkName := acctest.BootstrapSharedTestNetwork(t, "gke-cluster")
859+
subnetworkName := acctest.BootstrapSubnet(t, "gke-cluster", networkName)
860+
861+
acctest.VcrTest(t, resource.TestCase{
862+
PreCheck: func() { acctest.AccTestPreCheck(t) },
863+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
864+
CheckDestroy: testAccCheckContainerClusterDestroyProducer(t),
865+
Steps: []resource.TestStep{
866+
{
867+
Config: testAccContainerCluster_podAutoscalingConfig(clusterName, networkName, subnetworkName, "NONE"),
868+
},
869+
{
870+
ResourceName: "google_container_cluster.pod_autoscaling_config",
871+
ImportState: true,
872+
ImportStateVerify: true,
873+
ImportStateVerifyIgnore: []string{"deletion_protection"},
874+
Check: resource.TestCheckResourceAttr("google_container_cluster.pod_autoscaling_config", "pod_autoscaling.hpa_profile", "NONE"),
875+
},
876+
{
877+
Config: testAccContainerCluster_podAutoscalingConfig(clusterName, networkName, subnetworkName, "PERFORMANCE"),
878+
},
879+
{
880+
ResourceName: "google_container_cluster.pod_autoscaling_config",
881+
ImportState: true,
882+
ImportStateVerify: true,
883+
ImportStateVerifyIgnore: []string{"deletion_protection"},
884+
Check: resource.TestCheckResourceAttr("google_container_cluster.pod_autoscaling_config", "pod_autoscaling.hpa_profile", "PERFORMANCE"),
885+
},
886+
},
887+
})
888+
}
889+
890+
func testAccContainerCluster_podAutoscalingConfig(clusterName string, networkName string, subnetworkName string, hpaProfile string) string {
891+
return fmt.Sprintf(`
892+
resource "google_container_cluster" "pod_autoscaling_config" {
893+
name = "%s"
894+
location = "us-central1-a"
895+
initial_node_count = 1
896+
network = "%s"
897+
subnetwork = "%s"
898+
899+
pod_autoscaling {
900+
hpa_profile = "%s"
901+
}
902+
903+
private_cluster_config {
904+
enable_private_nodes = true
905+
}
906+
907+
deletion_protection = false
908+
}
909+
`, clusterName, networkName, subnetworkName, hpaProfile)
910+
}
911+
854912
func testAccContainerCluster_enableMultiNetworking(clusterName string) string {
855913
return fmt.Sprintf(`
856914
resource "google_compute_network" "container_network" {

website/docs/r/container_cluster.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ region are guaranteed to support the same version.
307307
[PodSecurityPolicy](https://cloud.google.com/kubernetes-engine/docs/how-to/pod-security-policies) feature.
308308
Structure is [documented below](#nested_pod_security_policy_config).
309309

310-
* `pod_autoscaling` - (Optional, [Beta](https://terraform.io/docs/providers/google/guides/provider_versions.html)) Configuration for the
310+
* `pod_autoscaling` - (Optional) Configuration for the
311311
Structure is [documented below](#nested_pod_autoscaling).
312312

313313
* `secret_manager_config` - (Optional) Configuration for the

0 commit comments

Comments
 (0)