From e86b86848eea5d019b2c358af0e88dac3fee9ffb Mon Sep 17 00:00:00 2001 From: Chris Stephens Date: Mon, 20 May 2019 23:07:02 +0000 Subject: [PATCH] Community/veritcal pod Signed-off-by: Modular Magician --- google-beta/resource_container_cluster.go | 59 ++++++++++++++++++ .../resource_container_cluster_test.go | 61 +++++++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index 9490c44ed9..dd1e60519a 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -649,6 +649,20 @@ func resourceContainerCluster() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, }, + "vertical_pod_autoscaling": { + Type: schema.TypeList, + MaxItems: 1, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "enabled": { + Type: schema.TypeBool, + Optional: true, + }, + }, + }, + }, + "tpu_ipv4_cidr_block": { Computed: true, Type: schema.TypeString, @@ -828,6 +842,10 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er cluster.DatabaseEncryption = expandDatabaseEncryption(v) } + if v, ok := d.GetOk("vertical_pod_autoscaling"); ok { + cluster.VerticalPodAutoscaling = expandVerticalPodAutoscaling(v) + } + req := &containerBeta.CreateClusterRequest{ Cluster: cluster, } @@ -992,6 +1010,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 + } + if err := d.Set("pod_security_policy_config", flattenPodSecurityPolicyConfig(cluster.PodSecurityPolicyConfig)); err != nil { return err } @@ -1510,6 +1532,26 @@ 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("resource_labels") { resourceLabels := d.Get("resource_labels").(map[string]interface{}) req := &containerBeta.SetLabelsRequest{ @@ -1923,6 +1965,12 @@ func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEnc } } +func expandVerticalPodAutoscaling(configured interface{}) *containerBeta.VerticalPodAutoscaling { + return &containerBeta.VerticalPodAutoscaling{ + Enabled: config["enabled"].(bool), + } +} + func expandPodSecurityPolicyConfig(configured interface{}) *containerBeta.PodSecurityPolicyConfig { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { @@ -2045,6 +2093,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 c == nil || c.IpAllocationPolicy == nil { return nil diff --git a/google-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index 9417c50b48..31a80efa3d 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -1476,6 +1476,39 @@ func TestAccContainerCluster_sharedVpc(t *testing.T) { }) } +func TestAccContainerCluster_withVerticalPodAutoscaling(t *testing.T) { + t.Parallel() + + clusterName := fmt.Sprintf("cluster-test-%s", acctest.RandString(10)) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckContainerClusterDestroy, + Steps: []resource.TestStep{ + { + Config: testAccContainerCluster_withVerticalPodAutoscalingEnabled(clusterName), + }, + { + ResourceName: "google_container_cluster.with_vertical_pod_autoscaling", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + { + Config: testAccContainerCluster_withVerticalPodAutoscalingDisabled(clusterName), + }, + { + ResourceName: "google_container_cluster.with_vertical_pod_autoscaling", + ImportStateIdPrefix: "us-central1-a/", + ImportState: true, + ImportStateVerify: true, + }, + }, + }) + +} + func TestAccContainerCluster_withResourceLabels(t *testing.T) { t.Parallel() @@ -3068,6 +3101,34 @@ resource "google_container_cluster" "with_resource_labels" { `, clusterName) } +func testAccContainerCluster_withVerticalPodAutoscalingEnabled(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_vertical_pod_autoscaling" { + name = "%s" + zone = "us-central1-a" + initial_node_count = 1 + + vertical_pod_autoscaling { + enabled = true + } +} +`, clusterName) +} + +func testAccContainerCluster_withVerticalPodAutoscalingDisabled(clusterName string) string { + return fmt.Sprintf(` +resource "google_container_cluster" "with_vertical_pod_autoscaling" { + name = "%s" + zone = "us-central1-a" + initial_node_count = 1 + + vertical_pod_autoscaling { + enabled = false + } +} +`, clusterName) +} + func testAccContainerCluster_withResourceLabels(clusterName string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_resource_labels" {