Skip to content

Support for GKE clusters with no default node poolsΒ #2407

@ciroclover

Description

@ciroclover

TL;DR

Currently, the private-cluster module forces the creation of a default node pool even when node_pools = [] is specified. This prevents us to manage the node pools externally with dedicated node-pool modules.

Problem statement

Currently, the private-cluster module forces the creation of a default node pool even when node_pools = [] is specified. This prevents us to manage the node pools externally with dedicated node-pool modules.

The issue happens because:

  1. The node_pools variables defaults to [{name = "default-node-pool"}] [ref]
  2. The node_pool block in the cluster resource is not conditional [ref]
  3. When node_pools = [] is set, the module still tries to access var.node_pool[0] causing index errors [ref]

Detailed design:

  1. Update variables.tf:
variable "node_pools" {
  default = []      # changed from {name = "default-node-pool"}
 ...
  1. Create a conditional to the node_pool block:
dynamic "node_pool" {
  for_each = length(var.node_pools) > 0 ? [1] : []
  content {
    name                  = "default-pool"
    initial_node_count    = var.initial_node_count
  # ... rest of the config
  }
}
  1. Handle an edge case in the main.tf [ref] :
...
  cluster_name_parts_from_nodepool           = length(values(google_container_node_pool.pools)) > 0 ? split("/", element(values(google_container_node_pool.pools)[*].id, 0)) : []
  cluster_name_computed                      = length(local.cluster_name_parts_from_nodepool) > 0 ? element(local.cluster_name_parts_from_nodepool, length(local.cluster_name_parts_from_nodepool) - 3)

...

I have tested the code above, and I was able to create a cluster with no default node pool.

Would the maintainers be open to a pull request implementing this feature? I'm happy to submit a clean PR with the changes, and update the current documentation.

Additional information

No response

Edit

The solution above is not backward compatible.

The correct way to implement is to not change the variable default, and use the conditional:

for_each = length(var.node_pools) == 0 ? [] : [1]

In the pool-node block.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions