Skip to content

Commit 89d719a

Browse files
committed
capz: use retry wrapper to ensure-azcli.sh
1 parent 9af3232 commit 89d719a

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

capz/run-capz-e2e.sh

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,42 @@ wait_for_nodes() {
533533

534534
}
535535

536+
ensure_azcli_with_retry() {
537+
local max_attempts=5
538+
local attempt=1
539+
local wait_time=2
540+
541+
while [[ $attempt -le $max_attempts ]]; do
542+
log "Attempt $attempt/$max_attempts: Running CAPZ ensure-azcli.sh"
543+
# shellcheck disable=SC1091
544+
if source "${CAPZ_DIR}/hack/ensure-azcli.sh" 2>&1 | tee /tmp/ensure-azcli-${attempt}.log; then
545+
return 0
546+
fi
547+
548+
if [[ $attempt -lt $max_attempts ]]; then
549+
log "Azure CLI installation failed. Waiting ${wait_time}s before retry ${attempt}/${max_attempts}..."
550+
sleep $wait_time
551+
wait_time=$((wait_time * 2))
552+
fi
553+
554+
((attempt++))
555+
done
556+
557+
if command -v az &> /dev/null && az version &> /dev/null; then
558+
return 0
559+
else
560+
log "ERROR: Failed to install Azure CLI after $max_attempts attempts"
561+
log "Logs from attempts:"
562+
for i in $(seq 1 $max_attempts); do
563+
if [[ -f "/tmp/ensure-azcli-${i}.log" ]]; then
564+
log "=== Attempt $i log ==="
565+
tail -20 "/tmp/ensure-azcli-${i}.log" | sed 's/^/ /'
566+
fi
567+
done
568+
return 1
569+
fi
570+
}
571+
536572
set_azure_envs() {
537573
# shellcheck disable=SC1091
538574
source "${CAPZ_DIR}/hack/ensure-tags.sh"
@@ -543,10 +579,12 @@ set_azure_envs() {
543579
fi
544580
# shellcheck disable=SC1091
545581
source "${CAPZ_DIR}/hack/util.sh"
546-
# shellcheck disable=SC1091
547-
source "${CAPZ_DIR}/hack/ensure-azcli.sh"
548582

549-
583+
# use retry wrapper instead of source "${CAPZ_DIR}/hack/ensure-azcli.sh"
584+
if ! ensure_azcli_with_retry; then
585+
log "ERROR: Could not install Azure CLI"
586+
exit 1
587+
fi
550588

551589
# Verify the required Environment Variables are present.
552590
: "${AZURE_SUBSCRIPTION_ID:?Environment variable empty or not defined.}"

0 commit comments

Comments
 (0)