Skip to content

Commit 318f38f

Browse files
feat: allow default node pools metadata key-value pairs to be disabled (terraform-google-modules#2005)
Co-authored-by: Andrew Peabody <[email protected]>
1 parent 674f772 commit 318f38f

File tree

23 files changed

+87
-30
lines changed

23 files changed

+87
-30
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ Then perform the following commands on the root folder:
165165
| enable\_cilium\_clusterwide\_network\_policy | Enable Cilium Cluster Wide Network Policies on the cluster | `bool` | `false` | no |
166166
| enable\_confidential\_nodes | An optional flag to enable confidential node config. | `bool` | `false` | no |
167167
| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no |
168+
| enable\_default\_node\_pools\_metadata | Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool` | `bool` | `true` | no |
168169
| enable\_identity\_service | Enable the Identity Service component, which allows customers to use external identity providers with the K8S API. | `bool` | `false` | no |
169170
| enable\_intranode\_visibility | Whether Intra-node visibility is enabled for this cluster. This makes same node pod to pod traffic visible for VPC network | `bool` | `false` | no |
170171
| enable\_kubernetes\_alpha | 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. | `bool` | `false` | no |

autogen/main/cluster.tf.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ resource "google_container_node_pool" "windows_pools" {
891891
local.node_pools_resource_labels[each.value["name"]],
892892
)
893893
metadata = merge(
894-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
895-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
894+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
895+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
896896
local.node_pools_metadata["all"],
897897
local.node_pools_metadata[each.value["name"]],
898898
{

autogen/main/variables.tf.tmpl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,14 @@ variable "disable_default_snat" {
619619
default = false
620620
}
621621

622+
{% if autopilot_cluster != true %}
623+
variable "enable_default_node_pools_metadata" {
624+
type = bool
625+
description = "Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool`"
626+
default = true
627+
}
628+
629+
{% endif %}
622630
variable "notification_config_topic" {
623631
type = string
624632
description = "The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}."

cluster.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,8 +604,8 @@ resource "google_container_node_pool" "pools" {
604604
local.node_pools_resource_labels[each.value["name"]],
605605
)
606606
metadata = merge(
607-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
608-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
607+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
608+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
609609
local.node_pools_metadata["all"],
610610
local.node_pools_metadata[each.value["name"]],
611611
{
@@ -877,8 +877,8 @@ resource "google_container_node_pool" "windows_pools" {
877877
local.node_pools_resource_labels[each.value["name"]],
878878
)
879879
metadata = merge(
880-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
881-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
880+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
881+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
882882
local.node_pools_metadata["all"],
883883
local.node_pools_metadata[each.value["name"]],
884884
{

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ Then perform the following commands on the root folder:
201201
| enable\_cilium\_clusterwide\_network\_policy | Enable Cilium Cluster Wide Network Policies on the cluster | `bool` | `false` | no |
202202
| enable\_confidential\_nodes | An optional flag to enable confidential node config. | `bool` | `false` | no |
203203
| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no |
204+
| enable\_default\_node\_pools\_metadata | Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool` | `bool` | `true` | no |
204205
| enable\_fqdn\_network\_policy | Enable FQDN Network Policies on the cluster | `bool` | `null` | no |
205206
| enable\_gcfs | Enable image streaming on cluster level. | `bool` | `false` | no |
206207
| enable\_identity\_service | Enable the Identity Service component, which allows customers to use external identity providers with the K8S API. | `bool` | `false` | no |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -767,8 +767,8 @@ resource "google_container_node_pool" "pools" {
767767
local.node_pools_resource_labels[each.value["name"]],
768768
)
769769
metadata = merge(
770-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
771-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
770+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
771+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
772772
local.node_pools_metadata["all"],
773773
local.node_pools_metadata[each.value["name"]],
774774
{
@@ -1054,8 +1054,8 @@ resource "google_container_node_pool" "windows_pools" {
10541054
local.node_pools_resource_labels[each.value["name"]],
10551055
)
10561056
metadata = merge(
1057-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
1058-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
1057+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
1058+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
10591059
local.node_pools_metadata["all"],
10601060
local.node_pools_metadata[each.value["name"]],
10611061
{

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ variable "disable_default_snat" {
593593
default = false
594594
}
595595

596+
variable "enable_default_node_pools_metadata" {
597+
type = bool
598+
description = "Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool`"
599+
default = true
600+
}
601+
596602
variable "notification_config_topic" {
597603
type = string
598604
description = "The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}."

modules/beta-private-cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Then perform the following commands on the root folder:
179179
| enable\_cilium\_clusterwide\_network\_policy | Enable Cilium Cluster Wide Network Policies on the cluster | `bool` | `false` | no |
180180
| enable\_confidential\_nodes | An optional flag to enable confidential node config. | `bool` | `false` | no |
181181
| enable\_cost\_allocation | Enables Cost Allocation Feature and the cluster name and namespace of your GKE workloads appear in the labels field of the billing export to BigQuery | `bool` | `false` | no |
182+
| enable\_default\_node\_pools\_metadata | Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool` | `bool` | `true` | no |
182183
| enable\_fqdn\_network\_policy | Enable FQDN Network Policies on the cluster | `bool` | `null` | no |
183184
| enable\_gcfs | Enable image streaming on cluster level. | `bool` | `false` | no |
184185
| enable\_identity\_service | Enable the Identity Service component, which allows customers to use external identity providers with the K8S API. | `bool` | `false` | no |

modules/beta-private-cluster/cluster.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,8 +687,8 @@ resource "google_container_node_pool" "pools" {
687687
local.node_pools_resource_labels[each.value["name"]],
688688
)
689689
metadata = merge(
690-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
691-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
690+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
691+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
692692
local.node_pools_metadata["all"],
693693
local.node_pools_metadata[each.value["name"]],
694694
{
@@ -973,8 +973,8 @@ resource "google_container_node_pool" "windows_pools" {
973973
local.node_pools_resource_labels[each.value["name"]],
974974
)
975975
metadata = merge(
976-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", true) ? { "cluster_name" = var.name } : {},
977-
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", true) ? { "node_pool" = each.value["name"] } : {},
976+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "cluster_name", var.enable_default_node_pools_metadata) ? { "cluster_name" = var.name } : {},
977+
lookup(lookup(local.node_pools_metadata, "default_values", {}), "node_pool", var.enable_default_node_pools_metadata) ? { "node_pool" = each.value["name"] } : {},
978978
local.node_pools_metadata["all"],
979979
local.node_pools_metadata[each.value["name"]],
980980
{

modules/beta-private-cluster/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,12 @@ variable "disable_default_snat" {
593593
default = false
594594
}
595595

596+
variable "enable_default_node_pools_metadata" {
597+
type = bool
598+
description = "Whether to enable the default node pools metadata key-value pairs such as `cluster_name` and `node_pool`"
599+
default = true
600+
}
601+
596602
variable "notification_config_topic" {
597603
type = string
598604
description = "The desired Pub/Sub topic to which notifications will be sent by GKE. Format is projects/{project}/topics/{topic}."

0 commit comments

Comments
 (0)