From a00b867db54d557894da71c6f9c0fac3bae1f8f2 Mon Sep 17 00:00:00 2001 From: Fu Zi Xiang Date: Mon, 25 Dec 2023 19:19:42 +0800 Subject: [PATCH] fix: wait for pods to be ready before deletion --- .github/workflows/deploy.test.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/deploy.test.yml b/.github/workflows/deploy.test.yml index 206cd773..a22ab3ae 100644 --- a/.github/workflows/deploy.test.yml +++ b/.github/workflows/deploy.test.yml @@ -62,6 +62,29 @@ jobs: envsubst < kubernetes/templates/admin-frontend-deployment.yaml | tee deployed/admin-frontend-deployment.yaml | kubectl apply -f - envsubst < kubernetes/templates/admin-frontend-service.yaml | tee deployed/admin-frontend-service.yaml | kubectl apply -f - + # wait until + kubectl get pods --field-selector=status.phase!=Running | grep -v "STATUS" | wc -l + + # wait for all pods to be ready + tried=0 + while true; do + if [ $tried -eq 5 ]; then + echo "Waited too long for all pods to be ready" + exit 1 + fi + + non_running_pods=$(kubectl get pods --field-selector=status.phase!=Running | grep -v STATUS | wc -l) + if [ $non_running_pods -eq 0 ]; then + echo "All pods are ready." + exit 0 + else + echo "Waiting for all pods to be ready ..." + kubectl get pods + tried=$((tried + 1)) + sleep 5 + fi + done + - name: delete built images run: | TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "appflowyinc", "password": "${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}"}' https://hub.docker.com/v2/users/login/ | jq -r .token)