From 7a494420cf654dcea129a325f683368e56d7d22c Mon Sep 17 00:00:00 2001 From: ayushsatyam146 Date: Mon, 16 Sep 2024 14:36:17 +0530 Subject: [PATCH] fix: update the storage-version-migration script to complete execution in finite time --- hack/storage-version-migration.sh | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/hack/storage-version-migration.sh b/hack/storage-version-migration.sh index 09f02e9a91..981e1dbb83 100755 --- a/hack/storage-version-migration.sh +++ b/hack/storage-version-migration.sh @@ -65,19 +65,23 @@ spec: ttlSecondsAfterFinished: 600 EOF -JOB_NAME=$(kubectl -n shipwright-build get job --selector app=storage-version-migration-shipwright -o jsonpath='{.items[0].metadata.name}') -while [ "$(kubectl -n shipwright-build get job "${JOB_NAME}" -o json | jq -r '.status.completionTime // ""')" == "" ]; do - echo "[INFO] Storage version migraton job is still running" - sleep 10 -done +NAMESPACE="shipwright-build" +JOB_NAME=$(kubectl -n "${NAMESPACE}" get job --selector app=storage-version-migration-shipwright -o jsonpath='{.items[0].metadata.name}') -isFailed="$(kubectl -n shipwright-build get job "${JOB_NAME}" -o json | jq -r '.status.conditions[] | select(.type == "Failed") | .status')" +while true; do + jobStatus=$(kubectl get job "${JOB_NAME}" -n "${NAMESPACE}" -o=jsonpath='{.status.conditions[*].type}') -if [ "${isFailed}" == "True" ]; then - echo "[ERROR] Storage version migration failed" - kubectl -n shipwright-build logs "job/${JOB_NAME}" - exit 1 -fi + if [[ "${jobStatus}" == *"Complete"* ]]; then + echo "Job ${JOB_NAME} has completed successfully!" + exit 0 + elif [[ "${jobStatus}" == *"Failed"* ]]; then + echo "[ERROR] Storage version migration failed" + exit 1 + fi + + echo "[INFO] Storage version migration job is still running" + sleep 10 +done echo "[DONE]" \ No newline at end of file