Skip to content

Commit 4aad5e9

Browse files
feat: add support for custom monitoring metrics writer role (#2239)
Signed-off-by: samuelarogbonlo <[email protected]> Co-authored-by: Andrew Peabody <[email protected]>
1 parent 9a5aa01 commit 4aad5e9

File tree

30 files changed

+120
-10
lines changed

30 files changed

+120
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Then perform the following commands on the root folder:
212212
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
213213
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
214214
| 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 |
215+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
215216
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
216217
| name | The name of the cluster (required) | `string` | n/a | yes |
217218
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

autogen/main/sa.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

autogen/main/variables.tf.tmpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,3 +1032,13 @@ variable "logging_variant" {
10321032
default = null
10331033
}
10341034
{% endif %}
1035+
1036+
variable "monitoring_metric_writer_role" {
1037+
description = "The monitoring metrics writer role to assign to the GKE node service account"
1038+
type = string
1039+
default = "roles/monitoring.metricWriter"
1040+
validation {
1041+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
1042+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
1043+
}
1044+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ Then perform the following commands on the root folder:
129129
| 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 |
130130
| master\_ipv4\_cidr\_block | (Optional) The IP range in CIDR notation to use for the hosted master network. | `string` | `null` | no |
131131
| 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 |
132+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
132133
| name | The name of the cluster (required) | `string` | n/a | yes |
133134
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
134135
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,3 +597,13 @@ variable "logging_variant" {
597597
type = string
598598
default = null
599599
}
600+
601+
variable "monitoring_metric_writer_role" {
602+
description = "The monitoring metrics writer role to assign to the GKE node service account"
603+
type = string
604+
default = "roles/monitoring.metricWriter"
605+
validation {
606+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
607+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
608+
}
609+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ Then perform the following commands on the root folder:
119119
| maintenance\_start\_time | Time window specified for daily or recurring maintenance operations in RFC3339 format | `string` | `"05:00"` | no |
120120
| 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 |
121121
| 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 |
122+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
122123
| name | The name of the cluster (required) | `string` | n/a | yes |
123124
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |
124125
| network\_project\_id | The project ID of the shared VPC's host (for shared vpc support) | `string` | `""` | no |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "google_project_iam_member" "cluster_service_account_node_service_accou
5656
resource "google_project_iam_member" "cluster_service_account_metric_writer" {
5757
count = var.create_service_account ? 1 : 0
5858
project = google_service_account.cluster_service_account[0].project
59-
role = "roles/monitoring.metricWriter"
59+
role = var.monitoring_metric_writer_role
6060
member = google_service_account.cluster_service_account[0].member
6161
}
6262

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,13 @@ variable "logging_variant" {
561561
type = string
562562
default = null
563563
}
564+
565+
variable "monitoring_metric_writer_role" {
566+
description = "The monitoring metrics writer role to assign to the GKE node service account"
567+
type = string
568+
default = "roles/monitoring.metricWriter"
569+
validation {
570+
condition = can(regex("^(roles/[a-zA-Z0-9_.]+|projects/[a-zA-Z0-9-]+/roles/[a-zA-Z0-9_.]+)$", var.monitoring_metric_writer_role))
571+
error_message = "The monitoring_metric_writer_role must be either a predefined role (roles/*) or a custom role (projects/*/roles/*)."
572+
}
573+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Then perform the following commands on the root folder:
255255
| monitoring\_enable\_observability\_metrics | Whether or not the advanced datapath metrics are enabled. | `bool` | `false` | no |
256256
| monitoring\_enable\_observability\_relay | Whether or not the advanced datapath relay is enabled. | `bool` | `false` | no |
257257
| 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 |
258+
| monitoring\_metric\_writer\_role | The monitoring metrics writer role to assign to the GKE node service account | `string` | `"roles/monitoring.metricWriter"` | no |
258259
| monitoring\_service | The monitoring service that the cluster should write metrics to. Automatically send metrics from pods in the cluster to the Google Cloud Monitoring API. VM metrics will be collected by Google Compute Engine regardless of this setting Available options include monitoring.googleapis.com, monitoring.googleapis.com/kubernetes (beta) and none | `string` | `"monitoring.googleapis.com/kubernetes"` | no |
259260
| name | The name of the cluster (required) | `string` | n/a | yes |
260261
| network | The VPC network to host the cluster in (required) | `string` | n/a | yes |

0 commit comments

Comments
 (0)