Skip to content

Commit 2b49203

Browse files
committed
Moving autoscaling from beta to GA
1 parent 79e5e14 commit 2b49203

File tree

20 files changed

+134
-13
lines changed

20 files changed

+134
-13
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Then perform the following commands on the root folder:
103103
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
104104
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
105105
| 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 |
106+
| 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 |
106107
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
107108
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
108109
| 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 |

autogen/main/cluster.tf.tmpl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ resource "google_container_cluster" "primary" {
6565
logging_service = var.logging_service
6666
monitoring_service = var.monitoring_service
6767

68-
{% if beta_cluster %}
6968
cluster_autoscaling {
7069
enabled = var.cluster_autoscaling.enabled
70+
{% if beta_cluster %}
7171
autoscaling_profile = var.cluster_autoscaling.autoscaling_profile != null ? var.cluster_autoscaling.autoscaling_profile : "BALANCED"
72+
{% endif %}
7273
dynamic "resource_limits" {
7374
for_each = local.autoscalling_resource_limits
7475
content {
@@ -78,7 +79,6 @@ resource "google_container_cluster" "primary" {
7879
}
7980
}
8081
}
81-
{% endif %}
8282

8383
default_max_pods_per_node = var.default_max_pods_per_node
8484

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

397395
cluster = google_container_cluster.primary.name
398396

autogen/main/main.tf.tmpl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ locals {
5151
node_pools = zipmap(local.node_pool_names, tolist(toset(var.node_pools)))
5252

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

5655
autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
5756
resource_type = "cpu"
@@ -63,8 +62,6 @@ locals {
6362
maximum = var.cluster_autoscaling.max_memory_gb
6463
}] : []
6564

66-
{% endif %}
67-
6865

6966
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
7067
upstream_nameservers_config = length(var.upstream_nameservers) > 0

autogen/main/variables.tf.tmpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,27 +207,31 @@ variable "enable_kubernetes_alpha" {
207207
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."
208208
default = false
209209
}
210+
{% endif %}
210211

211212
variable "cluster_autoscaling" {
212213
type = object({
213214
enabled = bool
215+
{% if beta_cluster %}
214216
autoscaling_profile = string
217+
{% endif %}
215218
min_cpu_cores = number
216219
max_cpu_cores = number
217220
min_memory_gb = number
218221
max_memory_gb = number
219222
})
220223
default = {
221224
enabled = false
225+
{% if beta_cluster %}
222226
autoscaling_profile = "BALANCED"
227+
{% endif %}
223228
max_cpu_cores = 0
224229
min_cpu_cores = 0
225230
max_memory_gb = 0
226231
min_memory_gb = 0
227232
}
228233
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
229234
}
230-
{% endif %}
231235

232236
variable "node_pools_taints" {
233237
type = map(list(object({ key = string, value = string, effect = string })))

cluster.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
5656
logging_service = var.logging_service
5757
monitoring_service = var.monitoring_service
5858

59+
cluster_autoscaling {
60+
enabled = var.cluster_autoscaling.enabled
61+
dynamic "resource_limits" {
62+
for_each = local.autoscalling_resource_limits
63+
content {
64+
resource_type = lookup(resource_limits.value, "resource_type")
65+
minimum = lookup(resource_limits.value, "minimum")
66+
maximum = lookup(resource_limits.value, "maximum")
67+
}
68+
}
69+
}
5970

6071
default_max_pods_per_node = var.default_max_pods_per_node
6172

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

185198
cluster = google_container_cluster.primary.name
186199

examples/node_pool/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ provider "google-beta" {
2424
}
2525

2626
module "gke" {
27-
source = "../.."
27+
source = "../../modules/beta-public-cluster/"
2828
project_id = var.project_id
2929
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
3030
region = var.region

main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ locals {
4848

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

51+
autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
52+
resource_type = "cpu"
53+
minimum = var.cluster_autoscaling.min_cpu_cores
54+
maximum = var.cluster_autoscaling.max_cpu_cores
55+
}, {
56+
resource_type = "memory"
57+
minimum = var.cluster_autoscaling.min_memory_gb
58+
maximum = var.cluster_autoscaling.max_memory_gb
59+
}] : []
60+
5161

5262
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
5363
upstream_nameservers_config = length(var.upstream_nameservers) > 0

modules/beta-private-cluster-update-variant/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ locals {
5959
}] : []
6060

6161

62-
6362
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
6463
upstream_nameservers_config = length(var.upstream_nameservers) > 0
6564
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id

modules/beta-private-cluster/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ locals {
5959
}] : []
6060

6161

62-
6362
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
6463
upstream_nameservers_config = length(var.upstream_nameservers) > 0
6564
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id

modules/beta-public-cluster-update-variant/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ locals {
5959
}] : []
6060

6161

62-
6362
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
6463
upstream_nameservers_config = length(var.upstream_nameservers) > 0
6564
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id

modules/beta-public-cluster/main.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ locals {
5959
}] : []
6060

6161

62-
6362
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
6463
upstream_nameservers_config = length(var.upstream_nameservers) > 0
6564
network_project_id = var.network_project_id != "" ? var.network_project_id : var.project_id

modules/private-cluster-update-variant/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ Then perform the following commands on the root folder:
131131
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
132132
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
133133
| 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 |
134+
| 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 |
134135
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
135136
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
136137
| 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 |

modules/private-cluster-update-variant/cluster.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
5656
logging_service = var.logging_service
5757
monitoring_service = var.monitoring_service
5858

59+
cluster_autoscaling {
60+
enabled = var.cluster_autoscaling.enabled
61+
dynamic "resource_limits" {
62+
for_each = local.autoscalling_resource_limits
63+
content {
64+
resource_type = lookup(resource_limits.value, "resource_type")
65+
minimum = lookup(resource_limits.value, "minimum")
66+
maximum = lookup(resource_limits.value, "maximum")
67+
}
68+
}
69+
}
5970

6071
default_max_pods_per_node = var.default_max_pods_per_node
6172

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

270283
cluster = google_container_cluster.primary.name
271284

modules/private-cluster-update-variant/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ locals {
4848

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

51+
autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
52+
resource_type = "cpu"
53+
minimum = var.cluster_autoscaling.min_cpu_cores
54+
maximum = var.cluster_autoscaling.max_cpu_cores
55+
}, {
56+
resource_type = "memory"
57+
minimum = var.cluster_autoscaling.min_memory_gb
58+
maximum = var.cluster_autoscaling.max_memory_gb
59+
}] : []
60+
5161

5262
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
5363
upstream_nameservers_config = length(var.upstream_nameservers) > 0

modules/private-cluster-update-variant/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
188188
default = true
189189
}
190190

191+
variable "cluster_autoscaling" {
192+
type = object({
193+
enabled = bool
194+
min_cpu_cores = number
195+
max_cpu_cores = number
196+
min_memory_gb = number
197+
max_memory_gb = number
198+
})
199+
default = {
200+
enabled = false
201+
max_cpu_cores = 0
202+
min_cpu_cores = 0
203+
max_memory_gb = 0
204+
min_memory_gb = 0
205+
}
206+
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
207+
}
208+
191209
variable "node_pools_taints" {
192210
type = map(list(object({ key = string, value = string, effect = string })))
193211
description = "Map of lists containing node taints by node-pool name"

modules/private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Then perform the following commands on the root folder:
109109
| add\_cluster\_firewall\_rules | Create additional firewall rules | bool | `"false"` | no |
110110
| basic\_auth\_password | The password to be used with Basic Authentication. | string | `""` | no |
111111
| 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 |
112+
| 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 |
112113
| cluster\_ipv4\_cidr | The IP address range of the kubernetes pods in this cluster. Default is an automatically assigned CIDR. | string | `"null"` | no |
113114
| cluster\_resource\_labels | The GCE resource labels (a map of key/value pairs) to be applied to the cluster | map(string) | `<map>` | no |
114115
| 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 |

modules/private-cluster/cluster.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ resource "google_container_cluster" "primary" {
5656
logging_service = var.logging_service
5757
monitoring_service = var.monitoring_service
5858

59+
cluster_autoscaling {
60+
enabled = var.cluster_autoscaling.enabled
61+
dynamic "resource_limits" {
62+
for_each = local.autoscalling_resource_limits
63+
content {
64+
resource_type = lookup(resource_limits.value, "resource_type")
65+
minimum = lookup(resource_limits.value, "minimum")
66+
maximum = lookup(resource_limits.value, "maximum")
67+
}
68+
}
69+
}
5970

6071
default_max_pods_per_node = var.default_max_pods_per_node
6172

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

198211
cluster = google_container_cluster.primary.name
199212

modules/private-cluster/main.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ locals {
4848

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

51+
autoscalling_resource_limits = var.cluster_autoscaling.enabled ? [{
52+
resource_type = "cpu"
53+
minimum = var.cluster_autoscaling.min_cpu_cores
54+
maximum = var.cluster_autoscaling.max_cpu_cores
55+
}, {
56+
resource_type = "memory"
57+
minimum = var.cluster_autoscaling.min_memory_gb
58+
maximum = var.cluster_autoscaling.max_memory_gb
59+
}] : []
60+
5161

5262
custom_kube_dns_config = length(keys(var.stub_domains)) > 0
5363
upstream_nameservers_config = length(var.upstream_nameservers) > 0

modules/private-cluster/variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
188188
default = true
189189
}
190190

191+
variable "cluster_autoscaling" {
192+
type = object({
193+
enabled = bool
194+
min_cpu_cores = number
195+
max_cpu_cores = number
196+
min_memory_gb = number
197+
max_memory_gb = number
198+
})
199+
default = {
200+
enabled = false
201+
max_cpu_cores = 0
202+
min_cpu_cores = 0
203+
max_memory_gb = 0
204+
min_memory_gb = 0
205+
}
206+
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
207+
}
208+
191209
variable "node_pools_taints" {
192210
type = map(list(object({ key = string, value = string, effect = string })))
193211
description = "Map of lists containing node taints by node-pool name"

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,24 @@ variable "enable_resource_consumption_export" {
188188
default = true
189189
}
190190

191+
variable "cluster_autoscaling" {
192+
type = object({
193+
enabled = bool
194+
min_cpu_cores = number
195+
max_cpu_cores = number
196+
min_memory_gb = number
197+
max_memory_gb = number
198+
})
199+
default = {
200+
enabled = false
201+
max_cpu_cores = 0
202+
min_cpu_cores = 0
203+
max_memory_gb = 0
204+
min_memory_gb = 0
205+
}
206+
description = "Cluster autoscaling configuration. See [more details](https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1beta1/projects.locations.clusters#clusterautoscaling)"
207+
}
208+
191209
variable "node_pools_taints" {
192210
type = map(list(object({ key = string, value = string, effect = string })))
193211
description = "Map of lists containing node taints by node-pool name"

0 commit comments

Comments
 (0)