From acf0c4ec8dc44b26ffd6d9a30d1394eb979d5a6e Mon Sep 17 00:00:00 2001 From: The Magician Date: Thu, 23 May 2019 13:18:28 -0700 Subject: [PATCH] Community/veritcal pod (#733) Signed-off-by: Modular Magician --- google-beta/resource_container_cluster.go | 34 ++++++++++++++++++- .../resource_container_cluster_test.go | 28 +++++++++++++++ .../docs/r/container_cluster.html.markdown | 7 ++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index b3a1ac8bb58..2a11d6a6363 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -664,6 +664,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, @@ -847,6 +861,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, } @@ -1015,6 +1033,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 } @@ -1551,7 +1573,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er d.SetPartial("vertical_pod_autoscaling") } - } if d.HasChange("resource_labels") { @@ -1978,6 +1999,17 @@ 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 expandPodSecurityPolicyConfig(configured interface{}) *containerBeta.PodSecurityPolicyConfig { l := configured.([]interface{}) if len(l) == 0 || l[0] == nil { diff --git a/google-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index a7ad878b9ac..4277956c094 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -3129,6 +3129,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" { diff --git a/website/docs/r/container_cluster.html.markdown b/website/docs/r/container_cluster.html.markdown index 6e2a0537c7d..49ab5a16ca0 100644 --- a/website/docs/r/container_cluster.html.markdown +++ b/website/docs/r/container_cluster.html.markdown @@ -305,6 +305,9 @@ to the datasource. A `region` can have a different set of supported versions tha * `subnetwork` - (Optional) The name or self_link of the Google Compute Engine subnetwork in which the cluster's instances are launched. +* `vertical_pod_autoscaling` - Vertical Pod Autoscaling automatically adjusts the resources of pods controlled by it. + Structure is documented below. + The `addons_config` block supports: * `horizontal_pod_autoscaling` - (Optional) The status of the Horizontal Pod Autoscaling @@ -591,6 +594,10 @@ The `workload_metadata_config` block supports: * SECURE: Prevent workloads not in hostNetwork from accessing certain VM metadata, specifically kube-env, which contains Kubelet credentials, and the instance identity token. See [Metadata Concealment](https://cloud.google.com/kubernetes-engine/docs/how-to/metadata-proxy) documentation. * EXPOSE: Expose all VM metadata to pods. +The `vertical_pod_autoscaling` block supports: + +* `enabled` (Required) - Enables vertical pod autoscaling + ## Attributes Reference In addition to the arguments listed above, the following computed attributes are