From c187e5cded390b175e9826f39214f58b5db9bc67 Mon Sep 17 00:00:00 2001 From: Shira Pick Date: Mon, 2 Jan 2023 11:53:03 +0200 Subject: [PATCH 1/2] fix: k8s script should wait until finding pod --- scripts/k8s.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/k8s.sh b/scripts/k8s.sh index 8e7f18e..0a3c862 100755 --- a/scripts/k8s.sh +++ b/scripts/k8s.sh @@ -32,12 +32,18 @@ fi if [ $CMD = "start" ]; then echo "[+] Appliying use-sprkl into your cluster" USE_SPRKL_ROOT_DIR="$(git rev-parse --show-toplevel)" - helm install use-sprkl $USE_SPRKL_ROOT_DIR/helm/use-sprkl - shop_pod_name=$(kubectl get pod -l app/name=shop -o jsonpath="{.items[0].metadata.name}") + helm upgrade --install use-sprkl $USE_SPRKL_ROOT_DIR/helm/use-sprkl + shop_pod_name="" + while true; do + shop_pod_name=$(kubectl get pod -l app/name=shop -o jsonpath="{.items[0].metadata.name}") + if [[ ! -z $shop_pod_name ]]; then + break + fi + done echo " >> Waiting for shop service to be ready" kubectl wait --for=condition=Ready pod/"$shop_pod_name" - echo " >> Open your browser at http://localhost:5000" - kubectl port-forward "$shop_pod_name" 5000:5000 + echo " >> Open your browser at http://localhost" + sudo kubectl port-forward svc/shop 80:5000 elif [ $CMD = "stop" ]; then echo "[+] Removing use-sprkl from your cluster" helm uninstall use-sprkl From d712b1b6de13d86859896630218995031baff2f7 Mon Sep 17 00:00:00 2001 From: Shira Pick Date: Mon, 2 Jan 2023 11:58:33 +0200 Subject: [PATCH 2/2] fix: limit retries in k8s script to start --- scripts/k8s.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/k8s.sh b/scripts/k8s.sh index 0a3c862..f8e15e8 100755 --- a/scripts/k8s.sh +++ b/scripts/k8s.sh @@ -34,8 +34,14 @@ if [ $CMD = "start" ]; then USE_SPRKL_ROOT_DIR="$(git rev-parse --show-toplevel)" helm upgrade --install use-sprkl $USE_SPRKL_ROOT_DIR/helm/use-sprkl shop_pod_name="" + retries=0 while true; do + retries=$((retries+1)) shop_pod_name=$(kubectl get pod -l app/name=shop -o jsonpath="{.items[0].metadata.name}") + if [[ $retries -gt 10 ]]; then + echo "Error: failed to find shop pod name after 10 retries." + exit 1 + fi if [[ ! -z $shop_pod_name ]]; then break fi