Skip to content

Commit

Permalink
Moving autoscaling from beta to GA
Browse files Browse the repository at this point in the history
  • Loading branch information
marko7460 committed Oct 12, 2020
1 parent 6cb85fb commit 3cc16d3
Show file tree
Hide file tree
Showing 21 changed files with 148 additions and 25 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Then perform the following commands on the root folder:
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | string | `""` | no |
| cluster\_autoscaling | Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling) | object | `<map>` | no |
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
| configure\_ip\_masq | Enables the installation of ip masquerading, which is usually no longer required when using aliasied IP addresses. IP masquerading uses a kubectl call, so when you have a private cluster, you will need access to the API server. | string | `"false"` | no |
Expand Down
6 changes: 2 additions & 4 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ resource "google_container_cluster" "primary" {
logging_service = var.logging_service
monitoring_service = var.monitoring_service

{% if beta_cluster %}
cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
{% if beta_cluster %}
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
{% endif %}
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
Expand All @@ -78,7 +79,6 @@ resource "google_container_cluster" "primary" {
}
}
}
{% endif %}

default_max_pods_per_node = var.default_max_pods_per_node

Expand Down Expand Up @@ -389,10 +389,8 @@ resource "google_container_node_pool" "pools" {
{% endif %}
project = var.project_id
location = local.location
{% if beta_cluster %}
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(each.value, "node_locations", "") != "" ? split(",", each.value["node_locations"]) : null
{% endif %}

cluster = google_container_cluster.primary.name

Expand Down
3 changes: 0 additions & 3 deletions autogen/main/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ locals {
node_pools = zipmap(local.node_pool_names, tolist(toset(var.node_pools)))

release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []
{% if beta_cluster %}

autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
resource_type = "cpu"
Expand All @@ -63,8 +62,6 @@ locals {
maximum = var.cluster_autoscaling.max_memory_gb
}] : []

{% endif %}


custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
Expand Down
6 changes: 5 additions & 1 deletion autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -207,27 +207,31 @@ variable "enable_kubernetes_alpha" {
description = "Whether to enable Kubernetes Alpha features for this cluster. Note that when this option is enabled, the cluster cannot be upgraded and will be automatically deleted after 30 days."
default = false
}
{% endif %}

variable "cluster_autoscaling" {
type = object({
enabled = bool
{% if beta_cluster %}
autoscaling_profile = string
{% endif %}
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
{% if beta_cluster %}
autoscaling_profile = "BALANCED"
{% endif %}
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
{% endif %}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
Expand Down
13 changes: 13 additions & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
logging_service = var.logging_service
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
resource_type = lookup(resource_limits.value, "resource_type")
minimum = lookup(resource_limits.value, "minimum")
maximum = lookup(resource_limits.value, "maximum")
}
}
}

default_max_pods_per_node = var.default_max_pods_per_node

Expand Down Expand Up @@ -181,6 +192,8 @@ resource "google_container_node_pool" "pools" {
name = each.key
project = var.project_id
location = local.location
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(each.value, "node_locations", "") != "" ? split(",", each.value["node_locations"]) : null

cluster = google_container_cluster.primary.name

Expand Down
26 changes: 14 additions & 12 deletions examples/node_pool/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,22 @@ variable "compute_engine_service_account" {

variable "cluster_autoscaling" {
type = object({
enabled = bool
autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
enabled = bool
//Enable when autoscaling_profile becomes GA
//autoscaling_profile = string
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
enabled = false
//Enable when autoscaling_profile becomes GA
//autoscaling_profile = "BALANCED"
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}
10 changes: 10 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ locals {

release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []

autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
resource_type = "cpu"
minimum = var.cluster_autoscaling.min_cpu_cores
maximum = var.cluster_autoscaling.max_cpu_cores
}, {
resource_type = "memory"
minimum = var.cluster_autoscaling.min_memory_gb
maximum = var.cluster_autoscaling.max_memory_gb
}] : []


custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
Expand Down
1 change: 0 additions & 1 deletion modules/beta-private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ locals {
}] : []



custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
Expand Down
1 change: 0 additions & 1 deletion modules/beta-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ locals {
}] : []



custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
Expand Down
1 change: 0 additions & 1 deletion modules/beta-public-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ locals {
}] : []



custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
Expand Down
1 change: 0 additions & 1 deletion modules/beta-public-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ locals {
}] : []



custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster-update-variant/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ Then perform the following commands on the root folder:
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | string | `""` | no |
| cluster\_autoscaling | Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling) | object | `<map>` | no |
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
| configure\_ip\_masq | Enables the installation of ip masquerading, which is usually no longer required when using aliasied IP addresses. IP masquerading uses a kubectl call, so when you have a private cluster, you will need access to the API server. | string | `"false"` | no |
Expand Down
13 changes: 13 additions & 0 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
logging_service = var.logging_service
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
resource_type = lookup(resource_limits.value, "resource_type")
minimum = lookup(resource_limits.value, "minimum")
maximum = lookup(resource_limits.value, "maximum")
}
}
}

default_max_pods_per_node = var.default_max_pods_per_node

Expand Down Expand Up @@ -266,6 +277,8 @@ resource "google_container_node_pool" "pools" {
name = { for k, v in random_id.name : k => v.hex }[each.key]
project = var.project_id
location = local.location
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(each.value, "node_locations", "") != "" ? split(",", each.value["node_locations"]) : null

cluster = google_container_cluster.primary.name

Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ locals {

release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []

autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
resource_type = "cpu"
minimum = var.cluster_autoscaling.min_cpu_cores
maximum = var.cluster_autoscaling.max_cpu_cores
}, {
resource_type = "memory"
minimum = var.cluster_autoscaling.min_memory_gb
maximum = var.cluster_autoscaling.max_memory_gb
}] : []


custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
Expand Down
18 changes: 18 additions & 0 deletions modules/private-cluster-update-variant/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
default = true
}

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"
Expand Down
1 change: 1 addition & 0 deletions modules/private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Then perform the following commands on the root folder:
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
| basic\_auth\_username | The username to be used with Basic Authentication. An empty value will disable Basic Authentication, which is the recommended configuration. | string | `""` | no |
| cluster\_autoscaling | Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling) | object | `<map>` | no |
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
| configure\_ip\_masq | Enables the installation of ip masquerading, which is usually no longer required when using aliasied IP addresses. IP masquerading uses a kubectl call, so when you have a private cluster, you will need access to the API server. | string | `"false"` | no |
Expand Down
13 changes: 13 additions & 0 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
logging_service = var.logging_service
monitoring_service = var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "resource_limits" {
for_each = local.autoscalling_resource_limits
content {
resource_type = lookup(resource_limits.value, "resource_type")
minimum = lookup(resource_limits.value, "minimum")
maximum = lookup(resource_limits.value, "maximum")
}
}
}

default_max_pods_per_node = var.default_max_pods_per_node

Expand Down Expand Up @@ -194,6 +205,8 @@ resource "google_container_node_pool" "pools" {
name = each.key
project = var.project_id
location = local.location
// use node_locations if provided, defaults to cluster level node_locations if not specified
node_locations = lookup(each.value, "node_locations", "") != "" ? split(",", each.value["node_locations"]) : null

cluster = google_container_cluster.primary.name

Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ locals {

release_channel = var.release_channel != null ? [{ channel : var.release_channel }] : []

autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
resource_type = "cpu"
minimum = var.cluster_autoscaling.min_cpu_cores
maximum = var.cluster_autoscaling.max_cpu_cores
}, {
resource_type = "memory"
minimum = var.cluster_autoscaling.min_memory_gb
maximum = var.cluster_autoscaling.max_memory_gb
}] : []


custom_kube_dns_config = length(keys(var.stub_domains)) > 0
upstream_nameservers_config = length(var.upstream_nameservers) > 0
Expand Down
18 changes: 18 additions & 0 deletions modules/private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
default = true
}

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"
Expand Down
2 changes: 1 addition & 1 deletion test/integration/node_pool/controls/gcloud.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"oauthScopes" => %w(https://www.googleapis.com/auth/logging.write https://www.googleapis.com/auth/monitoring),
"serviceAccount" => "default"
},
"autoscalingProfile" => "OPTIMIZE_UTILIZATION",
"autoscalingProfile" => "BALANCED",
"enableNodeAutoprovisioning" => true,
"resourceLimits" => [
{
Expand Down
18 changes: 18 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
default = true
}

variable "cluster_autoscaling" {
type = object({
enabled = bool
min_cpu_cores = number
max_cpu_cores = number
min_memory_gb = number
max_memory_gb = number
})
default = {
enabled = false
max_cpu_cores = 0
min_cpu_cores = 0
max_memory_gb = 0
min_memory_gb = 0
}
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
}

variable "node_pools_taints" {
type = map(list(object({ key = string, value = string, effect = string })))
description = "Map of lists containing node taints by node-pool name"
Expand Down

0 comments on commit 3cc16d3

Please sign in to comment.