Skip to content

Commit 0ebdfda

Browse files
pocesarapeabody
andauthored
feat: add logging_config and monitoring_config to autopilot modules (#2155)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent 52f8bea commit 0ebdfda

File tree

22 files changed

+567
-129
lines changed

22 files changed

+567
-129
lines changed

autogen/main/cluster.tf.tmpl

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,42 +94,51 @@ resource "google_container_cluster" "primary" {
9494
}
9595
}
9696
{% endif %}
97-
{% if autopilot_cluster != true %}
98-
# only one of logging/monitoring_service or logging/monitoring_config can be specified
99-
{% if beta_cluster %}
100-
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
101-
{% else %}
102-
logging_service = local.logmon_config_is_set ? null : var.logging_service
103-
{% endif %}
10497
dynamic "logging_config" {
10598
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
10699

107100
content {
108101
enable_components = var.logging_enabled_components
109102
}
110103
}
111-
{% if beta_cluster %}
112-
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
113-
{% else %}
114-
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
115-
{% endif %}
104+
116105
dynamic "monitoring_config" {
106+
{% if autopilot_cluster != true %}
117107
{% if beta_cluster %}
118108
for_each = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? [1] : []
119109
{% else %}
120110
for_each = local.logmon_config_is_set || local.logmon_config_is_set ? [1] : []
121111
{% endif %}
112+
{% else %}
113+
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
114+
{% endif %}
122115
content{
123116
enable_components = var.monitoring_enabled_components
117+
{% if autopilot_cluster != true %}
124118
managed_prometheus {
125119
enabled = var.monitoring_enable_managed_prometheus
126120
}
127121
advanced_datapath_observability_config {
128122
enable_metrics = var.monitoring_enable_observability_metrics
129123
enable_relay = var.monitoring_enable_observability_relay
130124
}
125+
{% endif %}
131126
}
132127
}
128+
129+
{% if autopilot_cluster != true %}
130+
# only one of logging/monitoring_service or logging/monitoring_config can be specified
131+
{% if beta_cluster %}
132+
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
133+
{% else %}
134+
logging_service = local.logmon_config_is_set ? null : var.logging_service
135+
{% endif %}
136+
{% if beta_cluster %}
137+
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
138+
{% else %}
139+
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
140+
{% endif %}
141+
133142
cluster_autoscaling {
134143
enabled = var.cluster_autoscaling.enabled
135144
dynamic "auto_provisioning_defaults" {

autogen/main/variables.tf.tmpl

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,53 @@ variable "timeouts" {
852852
}
853853
}
854854

855+
variable "monitoring_enabled_components" {
856+
type = list(string)
857+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
858+
default = []
859+
validation {
860+
condition = alltrue([
861+
for c in var.monitoring_enabled_components:
862+
contains([
863+
"SYSTEM_COMPONENTS",
864+
"APISERVER",
865+
"SCHEDULER",
866+
"CONTROLLER_MANAGER",
867+
"STORAGE",
868+
"HPA",
869+
"POD",
870+
"DAEMONSET",
871+
"DEPLOYMENT",
872+
"STATEFULSET",
873+
"WORKLOADS",
874+
"KUBELET",
875+
"CADVISOR",
876+
"DCGM"
877+
], c)
878+
])
879+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
880+
}
881+
}
882+
883+
variable "logging_enabled_components" {
884+
type = list(string)
885+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
886+
default = []
887+
validation {
888+
condition = alltrue([
889+
for c in var.logging_enabled_components:
890+
contains([
891+
"SYSTEM_COMPONENTS",
892+
"APISERVER",
893+
"CONTROLLER_MANAGER",
894+
"SCHEDULER",
895+
"WORKLOADS"
896+
], c)
897+
])
898+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
899+
}
900+
}
901+
855902
{% if autopilot_cluster != true %}
856903
variable "monitoring_enable_managed_prometheus" {
857904
type = bool
@@ -871,18 +918,6 @@ variable "monitoring_enable_observability_relay" {
871918
default = false
872919
}
873920

874-
variable "monitoring_enabled_components" {
875-
type = list(string)
876-
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
877-
default = []
878-
}
879-
880-
variable "logging_enabled_components" {
881-
type = list(string)
882-
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
883-
default = []
884-
}
885-
886921
variable "enable_kubernetes_alpha" {
887922
type = bool
888923
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."

cluster.tf

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,14 @@ resource "google_container_cluster" "primary" {
8080

8181
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
8282

83-
# only one of logging/monitoring_service or logging/monitoring_config can be specified
84-
logging_service = local.logmon_config_is_set ? null : var.logging_service
8583
dynamic "logging_config" {
8684
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
8785

8886
content {
8987
enable_components = var.logging_enabled_components
9088
}
9189
}
92-
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
90+
9391
dynamic "monitoring_config" {
9492
for_each = local.logmon_config_is_set || local.logmon_config_is_set ? [1] : []
9593
content {
@@ -103,6 +101,11 @@ resource "google_container_cluster" "primary" {
103101
}
104102
}
105103
}
104+
105+
# only one of logging/monitoring_service or logging/monitoring_config can be specified
106+
logging_service = local.logmon_config_is_set ? null : var.logging_service
107+
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
108+
106109
cluster_autoscaling {
107110
enabled = var.cluster_autoscaling.enabled
108111
dynamic "auto_provisioning_defaults" {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ Then perform the following commands on the root folder:
121121
| ip\_range\_services | The _name_ of the secondary subnet range to use for services | `string` | n/a | yes |
122122
| issue\_client\_certificate | Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
123123
| kubernetes\_version | The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region. | `string` | `"latest"` | no |
124+
| logging\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, CONTROLLER\_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
124125
| logging\_variant | (Optional) The type of logging agent that is deployed by default for newly created node pools in the cluster. Valid values include DEFAULT and MAX\_THROUGHPUT. | `string` | `null` | no |
125126
| maintenance\_end\_time | Time window specified for recurring maintenance operations in RFC3339 format | `string` | `""` | no |
126127
| maintenance\_exclusions | List of maintenance exclusions. A cluster can have up to three | `list(object({ name = string, start_time = string, end_time = string, exclusion_scope = string }))` | `[]` | no |
@@ -129,6 +130,7 @@ Then perform the following commands on the root folder:
129130
| master\_authorized\_networks | List of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists). | `list(object({ cidr_block = string, display_name = string }))` | `[]` | no |
130131
| master\_global\_access\_enabled | Whether the cluster master is accessible globally (from any region) or only within the same region as the private endpoint. | `bool` | `true` | no |
131132
| master\_ipv4\_cidr\_block | The IP range in CIDR notation to use for the hosted master network. Optional for Autopilot clusters. | `string` | `null` | no |
133+
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
132134
| name | The name of the cluster (required) | `string` | n/a | yes |
133135
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
134136
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ resource "google_container_cluster" "primary" {
7272

7373
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7474

75+
dynamic "logging_config" {
76+
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
77+
78+
content {
79+
enable_components = var.logging_enabled_components
80+
}
81+
}
82+
83+
dynamic "monitoring_config" {
84+
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
85+
content {
86+
enable_components = var.monitoring_enabled_components
87+
}
88+
}
89+
7590
cluster_autoscaling {
7691
dynamic "auto_provisioning_defaults" {
7792
for_each = (var.create_service_account || var.service_account != "") ? [1] : []

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,53 @@ variable "timeouts" {
519519
}
520520
}
521521

522+
variable "monitoring_enabled_components" {
523+
type = list(string)
524+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
525+
default = []
526+
validation {
527+
condition = alltrue([
528+
for c in var.monitoring_enabled_components :
529+
contains([
530+
"SYSTEM_COMPONENTS",
531+
"APISERVER",
532+
"SCHEDULER",
533+
"CONTROLLER_MANAGER",
534+
"STORAGE",
535+
"HPA",
536+
"POD",
537+
"DAEMONSET",
538+
"DEPLOYMENT",
539+
"STATEFULSET",
540+
"WORKLOADS",
541+
"KUBELET",
542+
"CADVISOR",
543+
"DCGM"
544+
], c)
545+
])
546+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
547+
}
548+
}
549+
550+
variable "logging_enabled_components" {
551+
type = list(string)
552+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
553+
default = []
554+
validation {
555+
condition = alltrue([
556+
for c in var.logging_enabled_components :
557+
contains([
558+
"SYSTEM_COMPONENTS",
559+
"APISERVER",
560+
"CONTROLLER_MANAGER",
561+
"SCHEDULER",
562+
"WORKLOADS"
563+
], c)
564+
])
565+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
566+
}
567+
}
568+
522569
variable "enable_l4_ilb_subsetting" {
523570
type = bool
524571
description = "Enable L4 ILB Subsetting on the cluster"

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,14 @@ Then perform the following commands on the root folder:
112112
| ip\_range\_services | The _name_ of the secondary subnet range to use for services | `string` | n/a | yes |
113113
| issue\_client\_certificate | Issues a client certificate to authenticate to the cluster endpoint. To maximize the security of your cluster, leave this option disabled. Client certificates don't automatically rotate and aren't easily revocable. WARNING: changing this after cluster creation is destructive! | `bool` | `false` | no |
114114
| kubernetes\_version | The Kubernetes version of the masters. If set to 'latest' it will pull latest available version in the selected region. | `string` | `"latest"` | no |
115+
| logging\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, CONTROLLER\_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
115116
| logging\_variant | (Optional) The type of logging agent that is deployed by default for newly created node pools in the cluster. Valid values include DEFAULT and MAX\_THROUGHPUT. | `string` | `null` | no |
116117
| maintenance\_end\_time | Time window specified for recurring maintenance operations in RFC3339 format | `string` | `""` | no |
117118
| maintenance\_exclusions | List of maintenance exclusions. A cluster can have up to three | `list(object({ name = string, start_time = string, end_time = string, exclusion_scope = string }))` | `[]` | no |
118119
| maintenance\_recurrence | Frequency of the recurring maintenance window in RFC5545 format. | `string` | `""` | no |
119120
| maintenance\_start\_time | Time window specified for daily or recurring maintenance operations in RFC3339 format | `string` | `"05:00"` | no |
120121
| master\_authorized\_networks | List of master authorized networks. If none are provided, disallow external access (except the cluster node IPs, which GKE automatically whitelists). | `list(object({ cidr_block = string, display_name = string }))` | `[]` | no |
122+
| monitoring\_enabled\_components | List of services to monitor: SYSTEM\_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER\_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration. | `list(string)` | `[]` | no |
121123
| name | The name of the cluster (required) | `string` | n/a | yes |
122124
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
123125
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,21 @@ resource "google_container_cluster" "primary" {
7272

7373
min_master_version = var.release_channel == null || var.release_channel == "UNSPECIFIED" ? local.master_version : var.kubernetes_version == "latest" ? null : var.kubernetes_version
7474

75+
dynamic "logging_config" {
76+
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
77+
78+
content {
79+
enable_components = var.logging_enabled_components
80+
}
81+
}
82+
83+
dynamic "monitoring_config" {
84+
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
85+
content {
86+
enable_components = var.monitoring_enabled_components
87+
}
88+
}
89+
7590
cluster_autoscaling {
7691
dynamic "auto_provisioning_defaults" {
7792
for_each = (var.create_service_account || var.service_account != "") ? [1] : []

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,53 @@ variable "timeouts" {
483483
}
484484
}
485485

486+
variable "monitoring_enabled_components" {
487+
type = list(string)
488+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, KUBELET, CADVISOR and DCGM. In beta provider, WORKLOADS is supported on top of those 12 values. (WORKLOADS is deprecated and removed in GKE 1.24.) KUBELET and CADVISOR are only supported in GKE 1.29.3-gke.1093000 and above. Empty list is default GKE configuration."
489+
default = []
490+
validation {
491+
condition = alltrue([
492+
for c in var.monitoring_enabled_components :
493+
contains([
494+
"SYSTEM_COMPONENTS",
495+
"APISERVER",
496+
"SCHEDULER",
497+
"CONTROLLER_MANAGER",
498+
"STORAGE",
499+
"HPA",
500+
"POD",
501+
"DAEMONSET",
502+
"DEPLOYMENT",
503+
"STATEFULSET",
504+
"WORKLOADS",
505+
"KUBELET",
506+
"CADVISOR",
507+
"DCGM"
508+
], c)
509+
])
510+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
511+
}
512+
}
513+
514+
variable "logging_enabled_components" {
515+
type = list(string)
516+
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
517+
default = []
518+
validation {
519+
condition = alltrue([
520+
for c in var.logging_enabled_components :
521+
contains([
522+
"SYSTEM_COMPONENTS",
523+
"APISERVER",
524+
"CONTROLLER_MANAGER",
525+
"SCHEDULER",
526+
"WORKLOADS"
527+
], c)
528+
])
529+
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
530+
}
531+
}
532+
486533
variable "enable_l4_ilb_subsetting" {
487534
type = bool
488535
description = "Enable L4 ILB Subsetting on the cluster"

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,14 @@ resource "google_container_cluster" "primary" {
8686
type = var.cluster_telemetry_type
8787
}
8888
}
89-
# only one of logging/monitoring_service or logging/monitoring_config can be specified
90-
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
9189
dynamic "logging_config" {
9290
for_each = length(var.logging_enabled_components) > 0 ? [1] : []
9391

9492
content {
9593
enable_components = var.logging_enabled_components
9694
}
9795
}
98-
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
96+
9997
dynamic "monitoring_config" {
10098
for_each = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? [1] : []
10199
content {
@@ -109,6 +107,11 @@ resource "google_container_cluster" "primary" {
109107
}
110108
}
111109
}
110+
111+
# only one of logging/monitoring_service or logging/monitoring_config can be specified
112+
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
113+
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
114+
112115
cluster_autoscaling {
113116
enabled = var.cluster_autoscaling.enabled
114117
dynamic "auto_provisioning_defaults" {

0 commit comments

Comments
 (0)