From 960311ebd4e4616e74d6d123b6849e135e8f2256 Mon Sep 17 00:00:00 2001 From: phaer Date: Mon, 7 Feb 2022 12:56:13 +0100 Subject: [PATCH] use yamlencode for k3s configs... ...and remove the now, hopefully unneeded workaround for agent.conf, all values are in config.yaml now --- agents.tf | 26 +++++++------------------- master.tf | 15 ++++++++++----- servers.tf | 18 ++++++++++++------ templates/agent.conf.tpl | 3 --- templates/agent_config.yaml.tpl | 4 ---- templates/master_config.yaml.tpl | 16 ---------------- templates/server_config.yaml.tpl | 16 ---------------- 7 files changed, 29 insertions(+), 69 deletions(-) delete mode 100644 templates/agent.conf.tpl delete mode 100644 templates/agent_config.yaml.tpl delete mode 100644 templates/master_config.yaml.tpl delete mode 100644 templates/server_config.yaml.tpl diff --git a/agents.tf b/agents.tf index ad65ec8..ffba9a5 100644 --- a/agents.tf +++ b/agents.tf @@ -59,27 +59,15 @@ resource "hcloud_server" "agents" { EOT } - # Generating and uploading the angent.conf file - provisioner "file" { - content = templatefile("${path.module}/templates/agent.conf.tpl", { - server_url = "https://${local.first_control_plane_network_ip}:6443" - node_token = random_password.k3s_token.result - }) - destination = "/etc/rancher/k3s/agent.conf" - - connection { - user = "root" - private_key = local.ssh_private_key - agent_identity = local.ssh_identity - host = self.ipv4_address - } - } - # Generating k3s server config file provisioner "file" { - content = templatefile("${path.module}/templates/agent_config.yaml.tpl", { - node_ip = cidrhost(hcloud_network.k3s.ip_range, 2 + var.servers_num + count.index) - node_name = self.name + content = yamlencode({ + node-name = self.name + server = "https://${local.first_control_plane_network_ip}:6443" + kubelet-arg = "cloud-provider=external" + flannel-iface = "eth1" + node-ip = local.first_control_plane_network_ip + token = random_password.k3s_token.result }) destination = "/etc/rancher/k3s/config.yaml" diff --git a/master.tf b/master.tf index 33fbf57..98d2fc1 100644 --- a/master.tf +++ b/master.tf @@ -59,11 +59,16 @@ resource "hcloud_server" "first_control_plane" { # Generating k3s master config file provisioner "file" { - content = templatefile("${path.module}/templates/master_config.yaml.tpl", { - node_ip = local.first_control_plane_network_ip - token = random_password.k3s_token.result - node_name = self.name - allow_scheduling_on_control_plane = var.allow_scheduling_on_control_plane + content = yamlencode({ + node-name = self.name + cluster-init = true + disable-cloud-controller = true + disable = "servicelb, local-storage" + flannel-iface = "eth1" + kubelet-arg = "cloud-provider=external" + node-ip = local.first_control_plane_network_ip + advertise-address = local.first_control_plane_network_ip + token = random_password.k3s_token.result }) destination = "/etc/rancher/k3s/config.yaml" diff --git a/servers.tf b/servers.tf index 3cbdc68..b933793 100644 --- a/servers.tf +++ b/servers.tf @@ -60,12 +60,18 @@ resource "hcloud_server" "control_planes" { # Generating k3s server config file provisioner "file" { - content = templatefile("${path.module}/templates/server_config.yaml.tpl", { - first_control_plane_url = "https://${local.first_control_plane_network_ip}:6443" - node_ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) - token = random_password.k3s_token.result - node_name = self.name - allow_scheduling_on_control_plane = var.allow_scheduling_on_control_plane + content = yamlencode({ + node-name = self.name + server = "https://${local.first_control_plane_network_ip}:6443" + cluster-init = true + disable-cloud-controller = true + disable = "servicelb, local-storage" + flannel-iface = "eth1" + kubelet-arg = "cloud-provider=external" + node-ip = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) + advertise-address = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) + tls-san = cidrhost(hcloud_network.k3s.ip_range, 3 + count.index) + token = random_password.k3s_token.result }) destination = "/etc/rancher/k3s/config.yaml" diff --git a/templates/agent.conf.tpl b/templates/agent.conf.tpl deleted file mode 100644 index 047b9cf..0000000 --- a/templates/agent.conf.tpl +++ /dev/null @@ -1,3 +0,0 @@ -SERVER_URL="${server_url}" -NODE_TOKEN="${node_token}" -AGENT_OPTS= \ No newline at end of file diff --git a/templates/agent_config.yaml.tpl b/templates/agent_config.yaml.tpl deleted file mode 100644 index 8f13611..0000000 --- a/templates/agent_config.yaml.tpl +++ /dev/null @@ -1,4 +0,0 @@ -node-ip: ${node_ip} -kubelet-arg: "cloud-provider=external" -flannel-iface: eth1 -node-name: ${node_name} \ No newline at end of file diff --git a/templates/master_config.yaml.tpl b/templates/master_config.yaml.tpl deleted file mode 100644 index 5da9450..0000000 --- a/templates/master_config.yaml.tpl +++ /dev/null @@ -1,16 +0,0 @@ -cluster-init: true -disable-cloud-controller: true -disable: -- servicelb -- local-storage -flannel-iface: eth1 -node-ip: ${node_ip} -advertise-address: ${node_ip} -tls-san: ${node_ip} -kubelet-arg: "cloud-provider=external" -token: ${token} -node-name: ${node_name} -%{ if !allow_scheduling_on_control_plane } -node-taint: -- node-role.kubernetes.io/master:NoSchedule -%{ endif } diff --git a/templates/server_config.yaml.tpl b/templates/server_config.yaml.tpl deleted file mode 100644 index 60bd076..0000000 --- a/templates/server_config.yaml.tpl +++ /dev/null @@ -1,16 +0,0 @@ -server: ${first_control_plane_url} -disable-cloud-controller: true -disable: -- servicelb -- local-storage -flannel-iface: eth1 -node-ip: ${node_ip} -advertise-address: ${node_ip} -tls-san: ${node_ip} -kubelet-arg: "cloud-provider=external" -token: ${token} -node-name: ${node_name} -%{ if !allow_scheduling_on_control_plane } -node-taint: -- node-role.kubernetes.io/master:NoSchedule -%{ endif }