Skip to content

Commit 3b0bbe8

Browse files
authored
feat: Add additional functionality for autopilot clusters (#1985)
1 parent c19756c commit 3b0bbe8

File tree

19 files changed

+134
-40
lines changed

19 files changed

+134
-40
lines changed

autogen/main/cluster.tf.tmpl

+5-6
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ resource "google_container_cluster" "primary" {
324324
}
325325
}
326326

327+
config_connector_config {
328+
enabled = var.config_connector
329+
}
330+
{% endif %}
331+
327332
dynamic "gke_backup_agent_config" {
328333
for_each = local.gke_backup_agent_config
329334

@@ -347,13 +352,7 @@ resource "google_container_cluster" "primary" {
347352
enabled = stateful_ha_config.value.enabled
348353
}
349354
}
350-
351-
config_connector_config {
352-
enabled = var.config_connector
353-
}
354-
{% endif %}
355355
{% if beta_cluster and autopilot_cluster != true %}
356-
357356
istio_config {
358357
disabled = !var.istio
359358
auth = var.istio_auth

autogen/main/main.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ locals {
107107
}]
108108
cluster_gce_pd_csi_config = var.gce_pd_csi_driver ? [{ enabled = true }] : [{ enabled = false }]
109109
logmon_config_is_set = length(var.logging_enabled_components) > 0 || length(var.monitoring_enabled_components) > 0 || var.monitoring_enable_managed_prometheus
110+
{% endif %}
110111
gke_backup_agent_config = var.gke_backup_agent_config ? [{ enabled = true }] : [{ enabled = false }]
111112
gcs_fuse_csi_driver_config = var.gcs_fuse_csi_driver ? [{ enabled = true }] : []
112113
stateful_ha_config = var.stateful_ha ? [{ enabled = true }] : []
113-
{% endif %}
114114
{% if beta_cluster and autopilot_cluster != true %}
115115
cluster_cloudrun_config_load_balancer_config = (var.cloudrun && var.cloudrun_load_balancer_type != "") ? {
116116
load_balancer_type = var.cloudrun_load_balancer_type

autogen/main/variables.tf.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,7 @@ variable "gce_pd_csi_driver" {
741741
default = true
742742
}
743743

744+
{% endif %}
744745
variable "gke_backup_agent_config" {
745746
type = bool
746747
description = "Whether Backup for GKE agent is enabled for this cluster."
@@ -759,7 +760,6 @@ variable "stateful_ha" {
759760
default = false
760761
}
761762

762-
{% endif %}
763763
variable "timeouts" {
764764
type = map(string)
765765
description = "Timeout for cluster operations."

cluster.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ resource "google_container_cluster" "primary" {
244244
}
245245
}
246246

247+
config_connector_config {
248+
enabled = var.config_connector
249+
}
250+
247251
dynamic "gke_backup_agent_config" {
248252
for_each = local.gke_backup_agent_config
249253

@@ -267,10 +271,6 @@ resource "google_container_cluster" "primary" {
267271
enabled = stateful_ha_config.value.enabled
268272
}
269273
}
270-
271-
config_connector_config {
272-
enabled = var.config_connector
273-
}
274274
}
275275

276276
datapath_provider = var.datapath_provider

examples/simple_autopilot_public/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,7 @@ module "gke" {
4949
network_tags = [local.cluster_type]
5050
deletion_protection = false
5151
enable_l4_ilb_subsetting = true
52+
gcs_fuse_csi_driver = true
53+
stateful_ha = false
54+
gke_backup_agent_config = false
5255
}

modules/beta-autopilot-private-cluster/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Then perform the following commands on the root folder:
104104
| fleet\_project | (Optional) Register the cluster with the fleet in this project. | `string` | `null` | no |
105105
| fleet\_project\_grant\_service\_agent | (Optional) Grant the fleet project service identity the `roles/gkehub.serviceAgent` and `roles/gkehub.crossProjectServiceAgent` roles. | `bool` | `false` | no |
106106
| gateway\_api\_channel | The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`. | `string` | `null` | no |
107+
| gcs\_fuse\_csi\_driver | Whether GCE FUSE CSI driver is enabled for this cluster. | `bool` | `false` | no |
108+
| gke\_backup\_agent\_config | Whether Backup for GKE agent is enabled for this cluster. | `bool` | `false` | no |
107109
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer and artifactregistry.reader roles. | `bool` | `false` | no |
108110
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | `bool` | `true` | no |
109111
| http\_load\_balancing | Enable httpload balancer addon | `bool` | `true` | no |
@@ -141,6 +143,7 @@ Then perform the following commands on the root folder:
141143
| shadow\_firewall\_rules\_log\_config | The log\_config for shadow firewall rules. You can set this variable to `null` to disable logging. | <pre>object({<br> metadata = string<br> })</pre> | <pre>{<br> "metadata": "INCLUDE_ALL_METADATA"<br>}</pre> | no |
142144
| shadow\_firewall\_rules\_priority | The firewall priority of GKE shadow firewall rules. The priority should be less than default firewall, which is 1000. | `number` | `999` | no |
143145
| stack\_type | The stack type to use for this cluster. Either `IPV4` or `IPV4_IPV6`. Defaults to `IPV4`. | `string` | `"IPV4"` | no |
146+
| stateful\_ha | Whether the Stateful HA Addon is enabled for this cluster. | `bool` | `false` | no |
144147
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | `map(list(string))` | `{}` | no |
145148
| subnetwork | The subnetwork to host the cluster in (required) | `string` | n/a | yes |
146149
| timeouts | Timeout for cluster operations. | `map(string)` | `{}` | no |

modules/beta-autopilot-private-cluster/cluster.tf

+24
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ resource "google_container_cluster" "primary" {
135135
disabled = !var.horizontal_pod_autoscaling
136136
}
137137

138+
139+
dynamic "gke_backup_agent_config" {
140+
for_each = local.gke_backup_agent_config
141+
142+
content {
143+
enabled = gke_backup_agent_config.value.enabled
144+
}
145+
}
146+
147+
dynamic "gcs_fuse_csi_driver_config" {
148+
for_each = local.gcs_fuse_csi_driver_config
149+
150+
content {
151+
enabled = gcs_fuse_csi_driver_config.value.enabled
152+
}
153+
}
154+
155+
dynamic "stateful_ha_config" {
156+
for_each = local.stateful_ha_config
157+
158+
content {
159+
enabled = stateful_ha_config.value.enabled
160+
}
161+
}
138162
}
139163

140164
allow_net_admin = var.allow_net_admin

modules/beta-autopilot-private-cluster/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ locals {
6666
cluster_alias_ranges_cidr = var.add_cluster_firewall_rules ? { for range in toset(data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range) : range.range_name => range.ip_cidr_range } : {}
6767
pod_all_ip_ranges = var.add_cluster_firewall_rules ? compact(concat([local.cluster_alias_ranges_cidr[var.ip_range_pods]], [for range in var.additional_ip_range_pods : local.cluster_alias_ranges_cidr[range] if length(range) > 0])) : []
6868

69+
gke_backup_agent_config = var.gke_backup_agent_config ? [{ enabled = true }] : [{ enabled = false }]
70+
gcs_fuse_csi_driver_config = var.gcs_fuse_csi_driver ? [{ enabled = true }] : []
71+
stateful_ha_config = var.stateful_ha ? [{ enabled = true }] : []
6972

7073
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
7174
security_group = var.authenticator_security_group

modules/beta-autopilot-private-cluster/variables.tf

+18
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,24 @@ variable "database_encryption" {
453453
}
454454

455455

456+
variable "gke_backup_agent_config" {
457+
type = bool
458+
description = "Whether Backup for GKE agent is enabled for this cluster."
459+
default = false
460+
}
461+
462+
variable "gcs_fuse_csi_driver" {
463+
type = bool
464+
description = "Whether GCE FUSE CSI driver is enabled for this cluster."
465+
default = false
466+
}
467+
468+
variable "stateful_ha" {
469+
type = bool
470+
description = "Whether the Stateful HA Addon is enabled for this cluster."
471+
default = false
472+
}
473+
456474
variable "timeouts" {
457475
type = map(string)
458476
description = "Timeout for cluster operations."

modules/beta-autopilot-public-cluster/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Then perform the following commands on the root folder:
9595
| fleet\_project | (Optional) Register the cluster with the fleet in this project. | `string` | `null` | no |
9696
| fleet\_project\_grant\_service\_agent | (Optional) Grant the fleet project service identity the `roles/gkehub.serviceAgent` and `roles/gkehub.crossProjectServiceAgent` roles. | `bool` | `false` | no |
9797
| gateway\_api\_channel | The gateway api channel of this cluster. Accepted values are `CHANNEL_STANDARD` and `CHANNEL_DISABLED`. | `string` | `null` | no |
98+
| gcs\_fuse\_csi\_driver | Whether GCE FUSE CSI driver is enabled for this cluster. | `bool` | `false` | no |
99+
| gke\_backup\_agent\_config | Whether Backup for GKE agent is enabled for this cluster. | `bool` | `false` | no |
98100
| grant\_registry\_access | Grants created cluster-specific service account storage.objectViewer and artifactregistry.reader roles. | `bool` | `false` | no |
99101
| horizontal\_pod\_autoscaling | Enable horizontal pod autoscaling addon | `bool` | `true` | no |
100102
| http\_load\_balancing | Enable httpload balancer addon | `bool` | `true` | no |
@@ -130,6 +132,7 @@ Then perform the following commands on the root folder:
130132
| shadow\_firewall\_rules\_log\_config | The log\_config for shadow firewall rules. You can set this variable to `null` to disable logging. | <pre>object({<br> metadata = string<br> })</pre> | <pre>{<br> "metadata": "INCLUDE_ALL_METADATA"<br>}</pre> | no |
131133
| shadow\_firewall\_rules\_priority | The firewall priority of GKE shadow firewall rules. The priority should be less than default firewall, which is 1000. | `number` | `999` | no |
132134
| stack\_type | The stack type to use for this cluster. Either `IPV4` or `IPV4_IPV6`. Defaults to `IPV4`. | `string` | `"IPV4"` | no |
135+
| stateful\_ha | Whether the Stateful HA Addon is enabled for this cluster. | `bool` | `false` | no |
133136
| stub\_domains | Map of stub domains and their resolvers to forward DNS queries for a certain domain to an external DNS server | `map(list(string))` | `{}` | no |
134137
| subnetwork | The subnetwork to host the cluster in (required) | `string` | n/a | yes |
135138
| timeouts | Timeout for cluster operations. | `map(string)` | `{}` | no |

modules/beta-autopilot-public-cluster/cluster.tf

+24
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ resource "google_container_cluster" "primary" {
135135
disabled = !var.horizontal_pod_autoscaling
136136
}
137137

138+
139+
dynamic "gke_backup_agent_config" {
140+
for_each = local.gke_backup_agent_config
141+
142+
content {
143+
enabled = gke_backup_agent_config.value.enabled
144+
}
145+
}
146+
147+
dynamic "gcs_fuse_csi_driver_config" {
148+
for_each = local.gcs_fuse_csi_driver_config
149+
150+
content {
151+
enabled = gcs_fuse_csi_driver_config.value.enabled
152+
}
153+
}
154+
155+
dynamic "stateful_ha_config" {
156+
for_each = local.stateful_ha_config
157+
158+
content {
159+
enabled = stateful_ha_config.value.enabled
160+
}
161+
}
138162
}
139163

140164
allow_net_admin = var.allow_net_admin

modules/beta-autopilot-public-cluster/main.tf

+3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ locals {
6666
cluster_alias_ranges_cidr = var.add_cluster_firewall_rules ? { for range in toset(data.google_compute_subnetwork.gke_subnetwork[0].secondary_ip_range) : range.range_name => range.ip_cidr_range } : {}
6767
pod_all_ip_ranges = var.add_cluster_firewall_rules ? compact(concat([local.cluster_alias_ranges_cidr[var.ip_range_pods]], [for range in var.additional_ip_range_pods : local.cluster_alias_ranges_cidr[range] if length(range) > 0])) : []
6868

69+
gke_backup_agent_config = var.gke_backup_agent_config ? [{ enabled = true }] : [{ enabled = false }]
70+
gcs_fuse_csi_driver_config = var.gcs_fuse_csi_driver ? [{ enabled = true }] : []
71+
stateful_ha_config = var.stateful_ha ? [{ enabled = true }] : []
6972

7073
cluster_authenticator_security_group = var.authenticator_security_group == null ? [] : [{
7174
security_group = var.authenticator_security_group

modules/beta-autopilot-public-cluster/variables.tf

+18
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,24 @@ variable "database_encryption" {
423423
}
424424

425425

426+
variable "gke_backup_agent_config" {
427+
type = bool
428+
description = "Whether Backup for GKE agent is enabled for this cluster."
429+
default = false
430+
}
431+
432+
variable "gcs_fuse_csi_driver" {
433+
type = bool
434+
description = "Whether GCE FUSE CSI driver is enabled for this cluster."
435+
default = false
436+
}
437+
438+
variable "stateful_ha" {
439+
type = bool
440+
description = "Whether the Stateful HA Addon is enabled for this cluster."
441+
default = false
442+
}
443+
426444
variable "timeouts" {
427445
type = map(string)
428446
description = "Timeout for cluster operations."

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ resource "google_container_cluster" "primary" {
267267
}
268268
}
269269

270+
config_connector_config {
271+
enabled = var.config_connector
272+
}
273+
270274
dynamic "gke_backup_agent_config" {
271275
for_each = local.gke_backup_agent_config
272276

@@ -290,11 +294,6 @@ resource "google_container_cluster" "primary" {
290294
enabled = stateful_ha_config.value.enabled
291295
}
292296
}
293-
294-
config_connector_config {
295-
enabled = var.config_connector
296-
}
297-
298297
istio_config {
299298
disabled = !var.istio
300299
auth = var.istio_auth

modules/beta-private-cluster/cluster.tf

+4-5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ resource "google_container_cluster" "primary" {
267267
}
268268
}
269269

270+
config_connector_config {
271+
enabled = var.config_connector
272+
}
273+
270274
dynamic "gke_backup_agent_config" {
271275
for_each = local.gke_backup_agent_config
272276

@@ -290,11 +294,6 @@ resource "google_container_cluster" "primary" {
290294
enabled = stateful_ha_config.value.enabled
291295
}
292296
}
293-
294-
config_connector_config {
295-
enabled = var.config_connector
296-
}
297-
298297
istio_config {
299298
disabled = !var.istio
300299
auth = var.istio_auth

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

+4-5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ resource "google_container_cluster" "primary" {
267267
}
268268
}
269269

270+
config_connector_config {
271+
enabled = var.config_connector
272+
}
273+
270274
dynamic "gke_backup_agent_config" {
271275
for_each = local.gke_backup_agent_config
272276

@@ -290,11 +294,6 @@ resource "google_container_cluster" "primary" {
290294
enabled = stateful_ha_config.value.enabled
291295
}
292296
}
293-
294-
config_connector_config {
295-
enabled = var.config_connector
296-
}
297-
298297
istio_config {
299298
disabled = !var.istio
300299
auth = var.istio_auth

modules/beta-public-cluster/cluster.tf

+4-5
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ resource "google_container_cluster" "primary" {
267267
}
268268
}
269269

270+
config_connector_config {
271+
enabled = var.config_connector
272+
}
273+
270274
dynamic "gke_backup_agent_config" {
271275
for_each = local.gke_backup_agent_config
272276

@@ -290,11 +294,6 @@ resource "google_container_cluster" "primary" {
290294
enabled = stateful_ha_config.value.enabled
291295
}
292296
}
293-
294-
config_connector_config {
295-
enabled = var.config_connector
296-
}
297-
298297
istio_config {
299298
disabled = !var.istio
300299
auth = var.istio_auth

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ resource "google_container_cluster" "primary" {
244244
}
245245
}
246246

247+
config_connector_config {
248+
enabled = var.config_connector
249+
}
250+
247251
dynamic "gke_backup_agent_config" {
248252
for_each = local.gke_backup_agent_config
249253

@@ -267,10 +271,6 @@ resource "google_container_cluster" "primary" {
267271
enabled = stateful_ha_config.value.enabled
268272
}
269273
}
270-
271-
config_connector_config {
272-
enabled = var.config_connector
273-
}
274274
}
275275

276276
datapath_provider = var.datapath_provider

modules/private-cluster/cluster.tf

+4-4
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ resource "google_container_cluster" "primary" {
244244
}
245245
}
246246

247+
config_connector_config {
248+
enabled = var.config_connector
249+
}
250+
247251
dynamic "gke_backup_agent_config" {
248252
for_each = local.gke_backup_agent_config
249253

@@ -267,10 +271,6 @@ resource "google_container_cluster" "primary" {
267271
enabled = stateful_ha_config.value.enabled
268272
}
269273
}
270-
271-
config_connector_config {
272-
enabled = var.config_connector
273-
}
274274
}
275275

276276
datapath_provider = var.datapath_provider

0 commit comments

Comments
 (0)