Skip to content

Commit 702865c

Browse files
authored
Merge pull request #4559 from sharabiani/fix-np-name-filter
Fix filter for gke-nodepool instance_templates
2 parents cb0df01 + 07c1e14 commit 702865c

File tree

1 file changed

+15
-3
lines changed
  • modules/compute/gke-node-pool

1 file changed

+15
-3
lines changed

modules/compute/gke-node-pool/main.tf

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,10 +386,22 @@ locals {
386386
supported_machine_types_for_install_dependencies = ["a3-highgpu-8g", "a3-megagpu-8g"]
387387
}
388388

389+
# Replicates GKE's naming logic for its instance templates. The full
390+
# pattern is "gke-{cluster_name}-{nodepool_name}-{hash}".
391+
#
392+
# This code builds the "{cluster_name}-{nodepool_name}" prefix, which is
393+
# capped at 32 characters plus a dash '-' in between, by truncating names if needed:
394+
# - If both names > 16 chars, both are cut to 16.
395+
# - If one name > 16, it's shortened so the combined name length is 32.
389396
data "google_compute_region_instance_template" "instance_template" {
390-
for_each = { for idx, np in google_container_node_pool.node_pool : idx => np }
391-
project = var.project_id
392-
filter = "name : ${substr("gke-${local.cluster_name}-${each.value.name}", 0, 37)}*"
397+
for_each = { for idx, np in google_container_node_pool.node_pool : idx => np }
398+
project = var.project_id
399+
filter = "name: gke-${
400+
(length(local.cluster_name) <= 16 && length(each.value.name) <= 16) ? "${local.cluster_name}-${each.value.name}" :
401+
(length(local.cluster_name) > 16 && length(each.value.name) > 16) ? "${substr(local.cluster_name, 0, 16)}-${substr(each.value.name, 0, 16)}" :
402+
(length(local.cluster_name) > 16) ? "${substr(local.cluster_name, 0, 32 - length(each.value.name))}-${each.value.name}" :
403+
"${local.cluster_name}-${substr(each.value.name, 0, 32 - length(local.cluster_name))}"
404+
}*"
393405
most_recent = true
394406
}
395407

0 commit comments

Comments
 (0)