Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move vertical_pod_autoscaling to GA in container cluster #5033

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions google/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,20 @@ func resourceContainerCluster() *schema.Resource {
Computed: true,
},

"vertical_pod_autoscaling": {
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
},
},
},
},

"enable_intranode_visibility": {
Type: schema.TypeBool,
Optional: true,
Expand Down Expand Up @@ -875,6 +889,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
cluster.PrivateClusterConfig = expandPrivateClusterConfig(v)
}

if v, ok := d.GetOk("vertical_pod_autoscaling"); ok {
cluster.VerticalPodAutoscaling = expandVerticalPodAutoscaling(v)
}

req := &containerBeta.CreateClusterRequest{
Cluster: cluster,
}
Expand Down Expand Up @@ -1039,6 +1057,10 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro
return err
}

if err := d.Set("vertical_pod_autoscaling", flattenVerticalPodAutoscaling(cluster.VerticalPodAutoscaling)); err != nil {
return err
}

d.Set("resource_labels", cluster.ResourceLabels)

return nil
Expand Down Expand Up @@ -1451,6 +1473,26 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
d.SetPartial("master_auth")
}

if d.HasChange("vertical_pod_autoscaling") {
if ac, ok := d.GetOk("vertical_pod_autoscaling"); ok {
req := &containerBeta.UpdateClusterRequest{
Update: &containerBeta.ClusterUpdate{
DesiredVerticalPodAutoscaling: expandVerticalPodAutoscaling(ac),
},
}

updateF := updateFunc(req, "updating GKE cluster vertical pod autoscaling")
// Call update serially.
if err := lockedCall(lockKey, updateF); err != nil {
return err
}

log.Printf("[INFO] GKE cluster %s vertical pod autoscaling has been updated", d.Id())

d.SetPartial("vertical_pod_autoscaling")
}
}

if d.HasChange("resource_labels") {
resourceLabels := d.Get("resource_labels").(map[string]interface{})
req := &containerBeta.SetLabelsRequest{
Expand Down Expand Up @@ -1889,6 +1931,17 @@ func expandPrivateClusterConfig(configured interface{}) *containerBeta.PrivateCl
}
}

func expandVerticalPodAutoscaling(configured interface{}) *containerBeta.VerticalPodAutoscaling {
l := configured.([]interface{})
if len(l) == 0 {
return nil
}
config := l[0].(map[string]interface{})
return &containerBeta.VerticalPodAutoscaling{
Enabled: config["enabled"].(bool),
}
}

func expandPodSecurityPolicyConfig(configured interface{}) *containerBeta.PodSecurityPolicyConfig {
// Removing lists is hard - the element count (#) will have a diff from nil -> computed
// If we set this to empty on Read, it will be stable.
Expand Down Expand Up @@ -1992,6 +2045,17 @@ func flattenPrivateClusterConfig(c *containerBeta.PrivateClusterConfig) []map[st
}
}

func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []map[string]interface{} {
if c == nil {
return nil
}
return []map[string]interface{}{
{
"enabled": c.Enabled,
},
}
}

func flattenIPAllocationPolicy(c *containerBeta.Cluster, d *schema.ResourceData, config *Config) []map[string]interface{} {
// If IP aliasing isn't enabled, none of the values in this block can be set.
if c == nil || c.IpAllocationPolicy == nil || !c.IpAllocationPolicy.UseIpAliases {
Expand Down
8 changes: 8 additions & 0 deletions google/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,10 @@ resource "google_container_cluster" "primary" {
created-by = "terraform"
}

vertical_pod_autoscaling {
enabled = true
}

}
`, name)
}
Expand Down Expand Up @@ -1302,6 +1306,10 @@ resource "google_container_cluster" "primary" {
new-label = "update"
}

vertical_pod_autoscaling {
enabled = true
}

}
`, name)
}
Expand Down