Skip to content

Commit

Permalink
feat: add logging_config and monitoring_config to autopilot modules (#…
Browse files Browse the repository at this point in the history
…2155)

Co-authored-by: Andrew Peabody <[email protected]>
  • Loading branch information
pocesar and apeabody authored Nov 1, 2024
1 parent 52f8bea commit 0ebdfda
Show file tree
Hide file tree
Showing 22 changed files with 567 additions and 129 deletions.
33 changes: 21 additions & 12 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -94,42 +94,51 @@ resource "google_container_cluster" "primary" {
}
}
{% endif %}
{% if autopilot_cluster != true %}
# only one of logging/monitoring_service or logging/monitoring_config can be specified
{% if beta_cluster %}
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
{% else %}
logging_service = local.logmon_config_is_set ? null : var.logging_service
{% endif %}
dynamic "logging_config" {
for_each = length(var.logging_enabled_components) > 0 ? [1] : []

content {
enable_components = var.logging_enabled_components
}
}
{% if beta_cluster %}
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
{% else %}
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
{% endif %}

dynamic "monitoring_config" {
{% if autopilot_cluster != true %}
{% if beta_cluster %}
for_each = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? [1] : []
{% else %}
for_each = local.logmon_config_is_set || local.logmon_config_is_set ? [1] : []
{% endif %}
{% else %}
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
{% endif %}
content{
enable_components = var.monitoring_enabled_components
{% if autopilot_cluster != true %}
managed_prometheus {
enabled = var.monitoring_enable_managed_prometheus
}
advanced_datapath_observability_config {
enable_metrics = var.monitoring_enable_observability_metrics
enable_relay = var.monitoring_enable_observability_relay
}
{% endif %}
}
}

{% if autopilot_cluster != true %}
# only one of logging/monitoring_service or logging/monitoring_config can be specified
{% if beta_cluster %}
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
{% else %}
logging_service = local.logmon_config_is_set ? null : var.logging_service
{% endif %}
{% if beta_cluster %}
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service
{% else %}
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service
{% endif %}

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
Expand Down
59 changes: 47 additions & 12 deletions autogen/main/variables.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,53 @@ variable "timeouts" {
}
}

variable "monitoring_enabled_components" {
type = list(string)
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."
default = []
validation {
condition = alltrue([
for c in var.monitoring_enabled_components:
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"SCHEDULER",
"CONTROLLER_MANAGER",
"STORAGE",
"HPA",
"POD",
"DAEMONSET",
"DEPLOYMENT",
"STATEFULSET",
"WORKLOADS",
"KUBELET",
"CADVISOR",
"DCGM"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
}
}

variable "logging_enabled_components" {
type = list(string)
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
default = []
validation {
condition = alltrue([
for c in var.logging_enabled_components:
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"CONTROLLER_MANAGER",
"SCHEDULER",
"WORKLOADS"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
}
}

{% if autopilot_cluster != true %}
variable "monitoring_enable_managed_prometheus" {
type = bool
Expand All @@ -871,18 +918,6 @@ variable "monitoring_enable_observability_relay" {
default = false
}

variable "monitoring_enabled_components" {
type = list(string)
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."
default = []
}

variable "logging_enabled_components" {
type = list(string)
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
default = []
}

variable "enable_kubernetes_alpha" {
type = bool
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."
Expand Down
9 changes: 6 additions & 3 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,14 @@ resource "google_container_cluster" "primary" {

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

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

content {
enable_components = var.logging_enabled_components
}
}
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service

dynamic "monitoring_config" {
for_each = local.logmon_config_is_set || local.logmon_config_is_set ? [1] : []
content {
Expand All @@ -103,6 +101,11 @@ resource "google_container_cluster" "primary" {
}
}
}

# only one of logging/monitoring_service or logging/monitoring_config can be specified
logging_service = local.logmon_config_is_set ? null : var.logging_service
monitoring_service = local.logmon_config_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
Expand Down
2 changes: 2 additions & 0 deletions modules/beta-autopilot-private-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ Then perform the following commands on the root folder:
| ip\_range\_services | The _name_ of the secondary subnet range to use for services | `string` | n/a | yes |
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_end\_time | Time window specified for recurring maintenance operations in RFC3339 format | `string` | `""` | no |
| 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 |
Expand All @@ -129,6 +130,7 @@ Then perform the following commands on the root folder:
| 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 |
| 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 |
| master\_ipv4\_cidr\_block | The IP range in CIDR notation to use for the hosted master network. Optional for Autopilot clusters. | `string` | `null` | no |
| 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 |
| name | The name of the cluster (required) | `string` | n/a | yes |
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
Expand Down
15 changes: 15 additions & 0 deletions modules/beta-autopilot-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ resource "google_container_cluster" "primary" {

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

dynamic "logging_config" {
for_each = length(var.logging_enabled_components) > 0 ? [1] : []

content {
enable_components = var.logging_enabled_components
}
}

dynamic "monitoring_config" {
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
content {
enable_components = var.monitoring_enabled_components
}
}

cluster_autoscaling {
dynamic "auto_provisioning_defaults" {
for_each = (var.create_service_account || var.service_account != "") ? [1] : []
Expand Down
47 changes: 47 additions & 0 deletions modules/beta-autopilot-private-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,53 @@ variable "timeouts" {
}
}

variable "monitoring_enabled_components" {
type = list(string)
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."
default = []
validation {
condition = alltrue([
for c in var.monitoring_enabled_components :
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"SCHEDULER",
"CONTROLLER_MANAGER",
"STORAGE",
"HPA",
"POD",
"DAEMONSET",
"DEPLOYMENT",
"STATEFULSET",
"WORKLOADS",
"KUBELET",
"CADVISOR",
"DCGM"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
}
}

variable "logging_enabled_components" {
type = list(string)
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
default = []
validation {
condition = alltrue([
for c in var.logging_enabled_components :
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"CONTROLLER_MANAGER",
"SCHEDULER",
"WORKLOADS"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
}
}

variable "enable_l4_ilb_subsetting" {
type = bool
description = "Enable L4 ILB Subsetting on the cluster"
Expand Down
2 changes: 2 additions & 0 deletions modules/beta-autopilot-public-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ Then perform the following commands on the root folder:
| ip\_range\_services | The _name_ of the secondary subnet range to use for services | `string` | n/a | yes |
| 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 |
| 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 |
| 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 |
| 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 |
| maintenance\_end\_time | Time window specified for recurring maintenance operations in RFC3339 format | `string` | `""` | no |
| 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 |
| maintenance\_recurrence | Frequency of the recurring maintenance window in RFC5545 format. | `string` | `""` | no |
| maintenance\_start\_time | Time window specified for daily or recurring maintenance operations in RFC3339 format | `string` | `"05:00"` | no |
| 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 |
| 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 |
| name | The name of the cluster (required) | `string` | n/a | yes |
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |
Expand Down
15 changes: 15 additions & 0 deletions modules/beta-autopilot-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ resource "google_container_cluster" "primary" {

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

dynamic "logging_config" {
for_each = length(var.logging_enabled_components) > 0 ? [1] : []

content {
enable_components = var.logging_enabled_components
}
}

dynamic "monitoring_config" {
for_each = length(var.monitoring_enabled_components) > 0 ? [1] : []
content {
enable_components = var.monitoring_enabled_components
}
}

cluster_autoscaling {
dynamic "auto_provisioning_defaults" {
for_each = (var.create_service_account || var.service_account != "") ? [1] : []
Expand Down
47 changes: 47 additions & 0 deletions modules/beta-autopilot-public-cluster/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,53 @@ variable "timeouts" {
}
}

variable "monitoring_enabled_components" {
type = list(string)
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."
default = []
validation {
condition = alltrue([
for c in var.monitoring_enabled_components :
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"SCHEDULER",
"CONTROLLER_MANAGER",
"STORAGE",
"HPA",
"POD",
"DAEMONSET",
"DEPLOYMENT",
"STATEFULSET",
"WORKLOADS",
"KUBELET",
"CADVISOR",
"DCGM"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, SCHEDULER, CONTROLLER_MANAGER, STORAGE, HPA, POD, DAEMONSET, DEPLOYMENT, STATEFULSET, WORKLOADS, KUBELET, CADVISOR and DCGM."
}
}

variable "logging_enabled_components" {
type = list(string)
description = "List of services to monitor: SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS. Empty list is default GKE configuration."
default = []
validation {
condition = alltrue([
for c in var.logging_enabled_components :
contains([
"SYSTEM_COMPONENTS",
"APISERVER",
"CONTROLLER_MANAGER",
"SCHEDULER",
"WORKLOADS"
], c)
])
error_message = "Valid values are SYSTEM_COMPONENTS, APISERVER, CONTROLLER_MANAGER, SCHEDULER, and WORKLOADS."
}
}

variable "enable_l4_ilb_subsetting" {
type = bool
description = "Enable L4 ILB Subsetting on the cluster"
Expand Down
9 changes: 6 additions & 3 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,14 @@ resource "google_container_cluster" "primary" {
type = var.cluster_telemetry_type
}
}
# only one of logging/monitoring_service or logging/monitoring_config can be specified
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
dynamic "logging_config" {
for_each = length(var.logging_enabled_components) > 0 ? [1] : []

content {
enable_components = var.logging_enabled_components
}
}
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service

dynamic "monitoring_config" {
for_each = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? [1] : []
content {
Expand All @@ -109,6 +107,11 @@ resource "google_container_cluster" "primary" {
}
}
}

# only one of logging/monitoring_service or logging/monitoring_config can be specified
logging_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.logging_service
monitoring_service = local.cluster_telemetry_type_is_set || local.logmon_config_is_set ? null : var.monitoring_service

cluster_autoscaling {
enabled = var.cluster_autoscaling.enabled
dynamic "auto_provisioning_defaults" {
Expand Down
Loading

0 comments on commit 0ebdfda

Please sign in to comment.