Skip to content

Commit

Permalink
Merge pull request #1451 from modular-magician/codegen-pr-2765
Browse files Browse the repository at this point in the history
Move vertical_pod_autoscaling to GA in container cluster
  • Loading branch information
slevenick authored Dec 2, 2019
2 parents b46f10d + 5172834 commit 9c996e6
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 65 deletions.
119 changes: 60 additions & 59 deletions google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,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,
},
},
},
},

"release_channel": {
Type: schema.TypeList,
ForceNew: true,
Expand All @@ -815,20 +829,6 @@ func resourceContainerCluster() *schema.Resource {
},
},

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

"workload_identity_config": {
Type: schema.TypeList,
MaxItems: 1,
Expand Down Expand Up @@ -1093,14 +1093,14 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er
cluster.PrivateClusterConfig = expandPrivateClusterConfig(v)
}

if v, ok := d.GetOk("database_encryption"); ok {
cluster.DatabaseEncryption = expandDatabaseEncryption(v)
}

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

if v, ok := d.GetOk("database_encryption"); ok {
cluster.DatabaseEncryption = expandDatabaseEncryption(v)
}

if v, ok := d.GetOk("workload_identity_config"); ok {
cluster.WorkloadIdentityConfig = expandWorkloadIdentityConfig(v)
}
Expand Down Expand Up @@ -1792,6 +1792,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("pod_security_policy_config") {
c := d.Get("pod_security_policy_config")
req := &containerBeta.UpdateClusterRequest{
Expand All @@ -1817,26 +1837,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er
d.SetPartial("pod_security_policy_config")
}

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("workload_identity_config") {
// Because GKE uses a non-RESTful update function, when removing the
// feature you need to specify a fairly full request body or it fails:
Expand Down Expand Up @@ -2361,6 +2361,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 expandReleaseChannel(configured interface{}) *containerBeta.ReleaseChannel {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand All @@ -2384,17 +2395,6 @@ func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEnc
}
}

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 expandWorkloadIdentityConfig(configured interface{}) *containerBeta.WorkloadIdentityConfig {
l := configured.([]interface{})
if len(l) == 0 || l[0] == nil {
Expand Down Expand Up @@ -2558,6 +2558,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 flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interface{} {
result := []map[string]interface{}{}
if c != nil {
Expand All @@ -2573,16 +2584,6 @@ func flattenReleaseChannel(c *containerBeta.ReleaseChannel) []map[string]interfa
return result
}

func flattenVerticalPodAutoscaling(c *containerBeta.VerticalPodAutoscaling) []map[string]interface{} {
if c == nil {
return nil
}
return []map[string]interface{}{
{
"enabled": c.Enabled,
},
}
}
func flattenWorkloadIdentityConfig(c *containerBeta.WorkloadIdentityConfig) []map[string]interface{} {
if c == nil {
return nil
Expand Down
12 changes: 6 additions & 6 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1712,12 +1712,12 @@ resource "google_container_cluster" "primary" {
created-by = "terraform"
}
enable_intranode_visibility = true
enable_binary_authorization = true
vertical_pod_autoscaling {
enabled = true
}
enable_intranode_visibility = true
enable_binary_authorization = true
}
`, name)
}
Expand Down Expand Up @@ -1747,12 +1747,12 @@ resource "google_container_cluster" "primary" {
new-label = "update"
}
enable_intranode_visibility = true
enable_binary_authorization = true
vertical_pod_autoscaling {
enabled = true
}
enable_intranode_visibility = true
enable_binary_authorization = true
}
`, name)
}
Expand Down

0 comments on commit 9c996e6

Please sign in to comment.