Skip to content

Commit

Permalink
Community/veritcal pod (hashicorp#733)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and chrisst committed May 23, 2019
1 parent 058f0bb commit acf0c4e
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
34 changes: 33 additions & 1 deletion google-beta/resource_container_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -1551,7 +1573,6 @@ func resourceContainerClusterUpdate(d *schema.ResourceData, meta interface{}) er

d.SetPartial("vertical_pod_autoscaling")
}

}

if d.HasChange("resource_labels") {
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 28 additions & 0 deletions google-beta/resource_container_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
7 changes: 7 additions & 0 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit acf0c4e

Please sign in to comment.