Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to specify network tags for the default node pool #1123

Merged
merged 3 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

I deviated slightly from @morgante's suggestion in the related issue (adding the network tags from the first pool in the cluster config like for the service account): node_pools_tags is a map-of-lists unlike node_pools, which is a list-of-maps. The "first" pool here wouldn't be well defined -- I think the approach I went with is more natural in any case.

I'd like to avoid introducing a new "default-pool" concept because we already have precedent for using the first node pool as the default pool (example). In this case, what we should do is retrieve the name of the first node pool (from var.node_pools) and use the network tags associated with that node pool (in var.node_pools_tags).

Copy link
Contributor Author

@tomasgareau tomasgareau Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see -- makes sense! I've changed the "default-pool" lookup to var.node_pools[0].name in 0391098 -- from what I can see

  • node_pools[0] should always exist
  • node_pools entries are assumed to have the attribute name

so I have no error checking for the cases where either of these aren't true. Let me know if either is not the case.

Did we want to keep the "${local.cluster_network_tag}-default-pool" tag?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, yeah you shouldn't need error checking.

Did we want to keep the "${local.cluster_network_tag}-default-pool" tag?

Yes, I think it's helpful.

)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/beta-public-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/beta-public-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down
7 changes: 7 additions & 0 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ resource "google_container_cluster" "primary" {

service_account = lookup(var.node_pools[0], "service_account", local.service_account)

tags = concat(
lookup(local.node_pools_tags, "default_values", [true, true])[0] ? [local.cluster_network_tag] : [],
lookup(local.node_pools_tags, "default_values", [true, true])[1] ? ["${local.cluster_network_tag}-default-pool"] : [],
lookup(local.node_pools_tags, "all", []),
lookup(local.node_pools_tags, "default-pool", []),
)

dynamic "workload_metadata_config" {
for_each = local.cluster_node_metadata_config

Expand Down