From 63008004f7ee9d7db47d0885e78c3141987797d9 Mon Sep 17 00:00:00 2001 From: phaer Date: Mon, 21 Feb 2022 12:45:11 +0100 Subject: [PATCH 1/6] wait for load-balancer ip, expose it via terraform --- main.tf | 4 +--- master.tf | 9 ++++++++- output.tf | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/main.tf b/main.tf index 3650304..d0eb508 100644 --- a/main.tf +++ b/main.tf @@ -153,10 +153,8 @@ resource "hcloud_placement_group" "k3s" { } } -/* data "hcloud_load_balancer" "traefik" { name = "traefik" - depends_on = [hcloud_server.agents[0]] + depends_on = [module.first_control_plane] } -*/ diff --git a/master.tf b/master.tf index dd51aeb..9dc91c1 100644 --- a/master.tf +++ b/master.tf @@ -157,7 +157,14 @@ resource "null_resource" "first_control_plane" { "kubectl apply -k /tmp/post_install", "echo 'Waiting for the system-upgrade-controller deployment to become available...'", "kubectl -n system-upgrade wait --for=condition=available --timeout=120s deployment/system-upgrade-controller", - "kubectl -n system-upgrade apply -f /tmp/post_install/plans.yaml" + "kubectl -n system-upgrade apply -f /tmp/post_install/plans.yaml", + <<-EOT + timeout 120 bash < Date: Mon, 21 Feb 2022 16:18:11 +0100 Subject: [PATCH 2/6] wait for load-balancer in null-resource... ...because we can only do that whenever the cluster is operational, which it isn't with just one node. --- main.tf | 37 ++++++++++++++++++++++++++++++++++++- master.tf | 9 +-------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/main.tf b/main.tf index d0eb508..7437d2f 100644 --- a/main.tf +++ b/main.tf @@ -156,5 +156,40 @@ resource "hcloud_placement_group" "k3s" { data "hcloud_load_balancer" "traefik" { name = "traefik" - depends_on = [module.first_control_plane] + depends_on = [null_resource.cluster_provisioning] +} + + +resource "null_resource" "cluster_provisioning" { + + triggers = { + agent_ids = "${join(",", module.agents.*.id)}" + control_plane_ids = "${join(",", concat([module.first_control_plane.id], module.control_planes.*.id))}" + } + + depends_on = [ null_resource.first_control_plane, null_resource.control_planes, null_resource.agents ] + + provisioner "remote-exec" { + connection { + user = "root" + private_key = local.ssh_private_key + agent_identity = local.ssh_identity + host = module.first_control_plane.ipv4_address + } + + inline = [ + <<-EOT + timeout 120 bash < Date: Mon, 21 Feb 2022 17:54:39 +0100 Subject: [PATCH 3/6] terraform fmt --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 7437d2f..8521b7f 100644 --- a/main.tf +++ b/main.tf @@ -167,7 +167,7 @@ resource "null_resource" "cluster_provisioning" { control_plane_ids = "${join(",", concat([module.first_control_plane.id], module.control_planes.*.id))}" } - depends_on = [ null_resource.first_control_plane, null_resource.control_planes, null_resource.agents ] + depends_on = [null_resource.first_control_plane, null_resource.control_planes, null_resource.agents] provisioner "remote-exec" { connection { @@ -189,7 +189,7 @@ resource "null_resource" "cluster_provisioning" { } provisioner "local-exec" { - when = destroy + when = destroy command = "hcloud load-balancer delete traefik" } } From 96539720fde44998ff10244e20df5f52f2abfb1b Mon Sep 17 00:00:00 2001 From: phaer Date: Tue, 22 Feb 2022 00:32:30 +0100 Subject: [PATCH 4/6] remove triggers on cluster_provisioning --- main.tf | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/main.tf b/main.tf index 8521b7f..6d704fd 100644 --- a/main.tf +++ b/main.tf @@ -161,13 +161,11 @@ data "hcloud_load_balancer" "traefik" { resource "null_resource" "cluster_provisioning" { - - triggers = { - agent_ids = "${join(",", module.agents.*.id)}" - control_plane_ids = "${join(",", concat([module.first_control_plane.id], module.control_planes.*.id))}" - } - - depends_on = [null_resource.first_control_plane, null_resource.control_planes, null_resource.agents] + depends_on = [ + null_resource.first_control_plane, + null_resource.control_planes, + null_resource.agents + ] provisioner "remote-exec" { connection { From 9380b70bbe6f90deffa6916e0f6688dab6603ea0 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Tue, 22 Feb 2022 00:58:08 +0100 Subject: [PATCH 5/6] tweak to cluster provisioning null ressource, destroy, and moved lb waiting to master.tf --- main.tf | 33 ++++++--------------------------- master.tf | 10 +++++++++- 2 files changed, 15 insertions(+), 28 deletions(-) diff --git a/main.tf b/main.tf index 8521b7f..e10cab3 100644 --- a/main.tf +++ b/main.tf @@ -162,34 +162,13 @@ data "hcloud_load_balancer" "traefik" { resource "null_resource" "cluster_provisioning" { - triggers = { - agent_ids = "${join(",", module.agents.*.id)}" - control_plane_ids = "${join(",", concat([module.first_control_plane.id], module.control_planes.*.id))}" - } - - depends_on = [null_resource.first_control_plane, null_resource.control_planes, null_resource.agents] - - provisioner "remote-exec" { - connection { - user = "root" - private_key = local.ssh_private_key - agent_identity = local.ssh_identity - host = module.first_control_plane.ipv4_address - } - - inline = [ - <<-EOT - timeout 120 bash < /dev/null)" ]; do + echo "Waiting for load-balancer to get an IP..." + sleep 2 + done + EOF + EOT ] } From efad2fa8702c4b8194067c65998a6a2f20eff145 Mon Sep 17 00:00:00 2001 From: Karim Naufal Date: Tue, 22 Feb 2022 01:38:53 +0100 Subject: [PATCH 6/6] removed the cluster provisioning null ressource as not needed --- main.tf | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/main.tf b/main.tf index e10cab3..bc4ff34 100644 --- a/main.tf +++ b/main.tf @@ -156,19 +156,5 @@ resource "hcloud_placement_group" "k3s" { data "hcloud_load_balancer" "traefik" { name = "traefik" - depends_on = [null_resource.cluster_provisioning] -} - - -resource "null_resource" "cluster_provisioning" { - - provisioner "local-exec" { - when = destroy - command = <<-EOT - hcloud load-balancer delete traefik - hcloud network delete k3s - EOT - } - depends_on = [null_resource.first_control_plane] }