From 7670fe08894213d008b62d5d603a9588d1103186 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Mac=C3=ADk?= Date: Wed, 23 Oct 2024 10:43:31 +0200 Subject: [PATCH] fix(RHIDP-4394): implement re-attempting mechanism for uploading entities (#101) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pavel MacĂ­k --- .gitignore | 1 + ci-scripts/rhdh-setup/create_resource.sh | 25 +++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 2b7d8f7..67f0bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ benchmark-before benchmark-after load-test.log shellcheck +.artifacts* diff --git a/ci-scripts/rhdh-setup/create_resource.sh b/ci-scripts/rhdh-setup/create_resource.sh index b540cac..90395b6 100755 --- a/ci-scripts/rhdh-setup/create_resource.sh +++ b/ci-scripts/rhdh-setup/create_resource.sh @@ -113,9 +113,28 @@ clone_and_upload() { for filename in "${files[@]}"; do e_count=$(yq eval '.metadata.name | capture(".*-(?P[0-9]+)").value' "$filename" | tail -n 1) upload_url="${GITHUB_REPO%.*}/blob/${tmp_branch}/$(basename "$filename")" - log_info "Uploading entities from $upload_url" - ACCESS_TOKEN=$(get_token "rhdh") - curl -k "$(backstage_url)/api/catalog/locations" --cookie "$COOKIE" --cookie-jar "$COOKIE" -X POST -H 'Accept-Encoding: gzip, deflate, br' -H 'Authorization: Bearer '"$ACCESS_TOKEN" -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}' + max_attempts=5 + attempt=1 + while ((attempt <= max_attempts)); do + log_info "Uploading entities from $upload_url" + ACCESS_TOKEN=$(get_token "rhdh") + response="$(curl -k "$(backstage_url)/api/catalog/locations" --cookie "$COOKIE" --cookie-jar "$COOKIE" \ + -X POST \ + -H 'Accept-Encoding: gzip, deflate, br' \ + -H 'Authorization: Bearer '"$ACCESS_TOKEN" \ + -H 'Content-Type: application/json' --data-raw '{"type":"url","target":"'"${upload_url}"'"}')" + if [ "${PIPESTATUS[0]}" -eq 0 ]; then + log_info "Entities from $upload_url uploaded" + break + else + log_warn "Unable to upload entities from $upload_url: [$response]. Trying again up to $max_attempts times." + ((attempt++)) + fi + done + if [[ $attempt -gt $max_attempts ]]; then + log_error "Unable to upload entities from $upload_url $max_attempts attempts, giving up!" + return 1 + fi timeout=1800 timeout_timestamp=$(date -d "$timeout seconds" "+%s")