Skip to content

Commit e612af8

Browse files
authored
Merge pull request #1883 from kube-hetzner/fix/issue-1877-kustomization-retry
fix: add retry logic and timeout for network migration during upgrades
2 parents f320e37 + a8c8e67 commit e612af8

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

init.tf

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ resource "null_resource" "first_control_plane" {
8484
agent_identity = local.ssh_agent_identity
8585
host = local.first_control_plane_ip
8686
port = var.ssh_port
87+
timeout = "10m" # Extended timeout to handle network migrations during upgrades
8788

8889
bastion_host = local.ssh_bastion.bastion_host
8990
bastion_port = local.ssh_bastion.bastion_port
@@ -223,6 +224,7 @@ resource "null_resource" "kustomization" {
223224
agent_identity = local.ssh_agent_identity
224225
host = local.first_control_plane_ip
225226
port = var.ssh_port
227+
timeout = "10m" # Extended timeout to handle network migrations during upgrades
226228

227229
bastion_host = local.ssh_bastion.bastion_host
228230
bastion_port = local.ssh_bastion.bastion_port
@@ -416,9 +418,29 @@ resource "null_resource" "kustomization" {
416418
# Deploy secrets, logging is automatically disabled due to sensitive variables
417419
provisioner "remote-exec" {
418420
inline = [
419-
"set -ex",
420-
"kubectl -n kube-system create secret generic hcloud --from-literal=token=${var.hcloud_token} --from-literal=network=${data.hcloud_network.k3s.name} --dry-run=client -o yaml | kubectl apply -f -",
421-
"kubectl -n kube-system create secret generic hcloud-csi --from-literal=token=${var.hcloud_token} --dry-run=client -o yaml | kubectl apply -f -",
421+
<<-EOT
422+
set -ex
423+
# Retry logic to handle temporary network connectivity issues during upgrades
424+
MAX_ATTEMPTS=30
425+
RETRY_INTERVAL=10
426+
for attempt in $(seq 1 $MAX_ATTEMPTS); do
427+
echo "Attempt $attempt: Checking kubectl connectivity..."
428+
if [ "$(kubectl get --raw='/readyz' 2>/dev/null)" = "ok" ]; then
429+
echo "kubectl connectivity established, deploying secrets..."
430+
kubectl -n kube-system create secret generic hcloud --from-literal=token=${var.hcloud_token} --from-literal=network=${data.hcloud_network.k3s.name} --dry-run=client -o yaml | kubectl apply -f -
431+
kubectl -n kube-system create secret generic hcloud-csi --from-literal=token=${var.hcloud_token} --dry-run=client -o yaml | kubectl apply -f -
432+
echo "Secrets deployed successfully"
433+
break
434+
else
435+
echo "kubectl not ready yet, waiting $RETRY_INTERVAL seconds..."
436+
sleep $RETRY_INTERVAL
437+
fi
438+
if [ $attempt -eq $MAX_ATTEMPTS ]; then
439+
echo "Failed to establish kubectl connectivity after $MAX_ATTEMPTS attempts"
440+
exit 1
441+
fi
442+
done
443+
EOT
422444
]
423445
}
424446

0 commit comments

Comments
 (0)