From fefc99182ba82bfae87e9d218926456f600c82f4 Mon Sep 17 00:00:00 2001 From: Yang Chiu Date: Mon, 25 Mar 2024 16:43:19 +0800 Subject: [PATCH] ci: add retry for getting rancher api key Signed-off-by: Yang Chiu --- pipelines/utilities/longhorn_rancher_chart.sh | 11 +++++++---- test_framework/scripts/longhorn-setup.sh | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pipelines/utilities/longhorn_rancher_chart.sh b/pipelines/utilities/longhorn_rancher_chart.sh index 2b3ccada51..46bd1d32a3 100755 --- a/pipelines/utilities/longhorn_rancher_chart.sh +++ b/pipelines/utilities/longhorn_rancher_chart.sh @@ -26,10 +26,13 @@ install_rancher() { get_rancher_api_key() { - TOKEN=$(curl -X POST -s -k "https://${RANCHER_HOSTNAME}/v3-public/localproviders/local?action=login" -H 'Content-Type: application/json' -d "{\"username\":\"admin\", \"password\":\"${RANCHER_BOOTSTRAP_PASSWORD}\", \"responseType\": \"json\"}" | jq -r '.token' | tr -d '"') - ARR=(${TOKEN//:/ }) - RANCHER_ACCESS_KEY=${ARR[0]} - RANCHER_SECRET_KEY=${ARR[1]} + while [[ -z "${TOKEN}" ]]; do + TOKEN=$(curl -X POST -s -k "https://${RANCHER_HOSTNAME}/v3-public/localproviders/local?action=login" -H 'Content-Type: application/json' -d "{\"username\":\"admin\", \"password\":\"${RANCHER_BOOTSTRAP_PASSWORD}\", \"responseType\": \"json\"}" | jq -r '.token' | tr -d '"') + ARR=(${TOKEN//:/ }) + RANCHER_ACCESS_KEY=${ARR[0]} + RANCHER_SECRET_KEY=${ARR[1]} + sleep 3s + done } diff --git a/test_framework/scripts/longhorn-setup.sh b/test_framework/scripts/longhorn-setup.sh index 99f2dcd29c..6b4e14ba52 100755 --- a/test_framework/scripts/longhorn-setup.sh +++ b/test_framework/scripts/longhorn-setup.sh @@ -98,10 +98,13 @@ install_rancher() { get_rancher_api_key() { - TOKEN=$(curl -X POST -s -k "https://${RANCHER_HOSTNAME}/v3-public/localproviders/local?action=login" -H 'Content-Type: application/json' -d "{\"username\":\"admin\", \"password\":\"${RANCHER_BOOTSTRAP_PASSWORD}\", \"responseType\": \"json\"}" | jq -r '.token' | tr -d '"') - ARR=(${TOKEN//:/ }) - RANCHER_ACCESS_KEY=${ARR[0]} - RANCHER_SECRET_KEY=${ARR[1]} + while [[ -z "${TOKEN}" ]]; do + TOKEN=$(curl -X POST -s -k "https://${RANCHER_HOSTNAME}/v3-public/localproviders/local?action=login" -H 'Content-Type: application/json' -d "{\"username\":\"admin\", \"password\":\"${RANCHER_BOOTSTRAP_PASSWORD}\", \"responseType\": \"json\"}" | jq -r '.token' | tr -d '"') + ARR=(${TOKEN//:/ }) + RANCHER_ACCESS_KEY=${ARR[0]} + RANCHER_SECRET_KEY=${ARR[1]} + sleep 3s + done }