From 4e7676521a4a85e3ff3f230a1d865c1287452d6b Mon Sep 17 00:00:00 2001 From: robert-sanfeliu Date: Mon, 2 Dec 2024 12:14:08 +0100 Subject: [PATCH] K3 install script wait wireguard (#42) * Update install-kube-k3s-agent-u22-wg.sh Updated k3s agent install script to wait for WIREGUARD_VPN_IP * Update install-kube-k3s-server-u22-wg.sh Added wait in master script --- k3s/install-kube-k3s-agent-u22-wg.sh | 11 ++++++++++- k3s/install-kube-k3s-server-u22-wg.sh | 12 +++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/k3s/install-kube-k3s-agent-u22-wg.sh b/k3s/install-kube-k3s-agent-u22-wg.sh index 542c447..15b1060 100644 --- a/k3s/install-kube-k3s-agent-u22-wg.sh +++ b/k3s/install-kube-k3s-agent-u22-wg.sh @@ -29,7 +29,16 @@ log_print(){ } log_print INFO "Installing k3s agent" -WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` + +while true; do + WIREGUARD_VPN_IP=$(ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1) + if [[ -n "$WIREGUARD_VPN_IP" ]]; then + log_print INFO "WIREGUARD_VPN_IP is set to $WIREGUARD_VPN_IP" + break + fi + log_print INFO "Waiting for WIREGUARD_VPN_IP to be set..." + sleep 1 +done curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${K3S_VERSION} K3S_URL="https://${WIREGUARD_SERVER}:6443" K3S_TOKEN=${NODE_TOKEN} INSTALL_K3S_EXEC="--node-ip $WIREGUARD_VPN_IP" sh - diff --git a/k3s/install-kube-k3s-server-u22-wg.sh b/k3s/install-kube-k3s-server-u22-wg.sh index bccd474..bc1dcc7 100644 --- a/k3s/install-kube-k3s-server-u22-wg.sh +++ b/k3s/install-kube-k3s-server-u22-wg.sh @@ -32,7 +32,17 @@ log_print(){ } log_print INFO "Installing k3s server for APPLICATION_ID: ${TOKEN}" -WIREGUARD_VPN_IP=`ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1` + +while true; do + WIREGUARD_VPN_IP=$(ip a | grep wg | grep inet | awk '{print $2}' | cut -d'/' -f1) + if [[ -n "$WIREGUARD_VPN_IP" ]]; then + echo "WIREGUARD_VPN_IP is set to $WIREGUARD_VPN_IP" + break + fi + echo "Waiting for WIREGUARD_VPN_IP to be set..." + sleep 1 +done + curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION=${K3S_VERSION} INSTALL_K3S_EXEC="--cluster-cidr ${POD_CIDR} --token ${TOKEN} --flannel-backend=none --disable-network-policy --bind-address ${WIREGUARD_VPN_IP} --node-ip ${WIREGUARD_VPN_IP} --write-kubeconfig-mode 644" sh - export KUBECONFIG=/etc/rancher/k3s/k3s.yaml