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.
This commit is contained in:
phaer 2022-02-21 16:18:11 +01:00
parent 63008004f7
commit 4ee2156a95
2 changed files with 37 additions and 9 deletions

37
main.tf
View File

@ -156,5 +156,40 @@ resource "hcloud_placement_group" "k3s" {
data "hcloud_load_balancer" "traefik" { data "hcloud_load_balancer" "traefik" {
name = "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 <<EOF
until [ -n "\$(kubectl get -n kube-system service/traefik --output=jsonpath='{.status.loadBalancer.ingress[0].ip}')" ]; do
echo "Waiting for load-balancer to get an IP..."
done
EOF
EOT
]
}
provisioner "local-exec" {
when = destroy
command = "hcloud load-balancer delete traefik"
}
} }

View File

@ -157,14 +157,7 @@ resource "null_resource" "first_control_plane" {
"kubectl apply -k /tmp/post_install", "kubectl apply -k /tmp/post_install",
"echo 'Waiting for the system-upgrade-controller deployment to become available...'", "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 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 <<EOF
until [ -n "\$(kubectl get -n kube-system service/traefik --output=jsonpath='{.status.loadBalancer.ingress[0].ip}')" ]; do
echo "Waiting for load-balancer to get an IP..."
done
EOF
EOT
] ]
} }