From ae731a774666e94024dfd44b377661c050924cb3 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Sat, 5 Mar 2022 04:02:09 +0100 Subject: [PATCH] added a flag for the node names --- agents.tf | 2 +- control_planes.tf | 5 ++--- templates/traefik_config.yaml.tpl | 2 +- terraform.tfvars.example | 3 +++ variables.tf | 6 ++++++ 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/agents.tf b/agents.tf index d9870c7..54e6941 100644 --- a/agents.tf +++ b/agents.tf @@ -8,7 +8,7 @@ module "agents" { for_each = local.agent_nodepools - name = "${each.value.nodepool_name}-${random_pet.cluster.id}-${random_pet.agents[each.key].id}" + name = var.use_cluster_name_in_node_name ? "k3s-${random_pet.cluster.id}-${each.value.nodepool_name}-${random_pet.agents[each.key].id}" : "${each.value.nodepool_name}-${random_pet.agents[each.key].id}" ssh_keys = [hcloud_ssh_key.k3s.id] public_key = var.public_key private_key = var.private_key diff --git a/control_planes.tf b/control_planes.tf index 0472a45..8c5b633 100644 --- a/control_planes.tf +++ b/control_planes.tf @@ -6,9 +6,8 @@ resource "random_pet" "control_planes" { module "control_planes" { source = "./modules/host" - count = var.control_plane_count - name = "control-plane-${random_pet.cluster.id}-${random_pet.control_planes[count.index].id}" - + count = var.control_plane_count + name = var.use_cluster_name_in_node_name ? "k3s-${random_pet.cluster.id}-control-plane-${random_pet.control_planes[count.index].id}" : "control-plane-${random_pet.control_planes[count.index].id}" ssh_keys = [hcloud_ssh_key.k3s.id] public_key = var.public_key private_key = var.private_key diff --git a/templates/traefik_config.yaml.tpl b/templates/traefik_config.yaml.tpl index 35f6037..d0ada91 100644 --- a/templates/traefik_config.yaml.tpl +++ b/templates/traefik_config.yaml.tpl @@ -9,7 +9,7 @@ spec: enabled: true type: LoadBalancer annotations: - "load-balancer.hetzner.cloud/name": name + "load-balancer.hetzner.cloud/name": ${name} # make hetzners load-balancer connect to our nodes via our private k3s "load-balancer.hetzner.cloud/use-private-ip": "true" # keep hetzner-ccm from exposing our private ingress ip, which in general isn't routeable from the public internet diff --git a/terraform.tfvars.example b/terraform.tfvars.example index 3c4878b..c7e3e0b 100644 --- a/terraform.tfvars.example +++ b/terraform.tfvars.example @@ -77,6 +77,9 @@ load_balancer_type = "lb11" # Allows you to specify either stable, latest, or testing (defaults to stable), see https://rancher.com/docs/k3s/latest/en/upgrades/basic/ # initial_k3s_channel = "latest" +# Whether to use the cluster name in the node name, i.e. add the prefix k3s-(cluster_name)- to the nodes? The default is "false". +# use_cluster_name_in_node_name = true + # Adding extra firewall rules, like opening a port # In this example with allow port TCP 5432 for a Postgres service we will open via a nodeport # More info on the format here https://registry.terraform.io/providers/hetznercloud/hcloud/latest/docs/resources/firewall diff --git a/variables.tf b/variables.tf index d3439ae..837bcdb 100644 --- a/variables.tf +++ b/variables.tf @@ -120,3 +120,9 @@ variable "extra_firewall_rules" { default = [] description = "Additional firewall rules to apply to the cluster" } + +variable "use_cluster_name_in_node_name" { + type = bool + default = false + description = "Whether to use the cluster name in the node name" +}