diff --git a/ci-operator/step-registry/kueue-operator/dev-bundle/kueue-operator-dev-bundle-commands.sh b/ci-operator/step-registry/kueue-operator/dev-bundle/kueue-operator-dev-bundle-commands.sh index 6fcce5ae7abd..0a52166e21ca 100644 --- a/ci-operator/step-registry/kueue-operator/dev-bundle/kueue-operator-dev-bundle-commands.sh +++ b/ci-operator/step-registry/kueue-operator/dev-bundle/kueue-operator-dev-bundle-commands.sh @@ -9,11 +9,48 @@ echo "Latest Git commits:" git log --oneline -5 echo "Git status:" git status +# Resolve the newest 40-char SHA tag of a Quay repo via the Quay tag API. +# Reads push timestamps (start_ts) in bulk instead of running `skopeo inspect` +# per tag, which does not scale with the number of accumulated CI build tags. +# Prints ":" for the newest tag, or nothing if none is found. +resolve_latest_image() { + local repo=$1 + local api_repo="${repo#quay.io/}" + local page=1 resp attempt latest="" + # Quay returns tags newest-first, so page 1 normally already holds the newest + # SHA-form tag; keep paging only while Quay reports additional pages. + while :; do + resp="" + for attempt in 1 2 3; do + if resp=$(wget -q -O - --tries=1 --timeout=30 \ + "https://quay.io/api/v1/repository/${api_repo}/tag/?onlyActiveTags=true&limit=100&page=${page}"); then + break + fi + echo "WARN: Quay tag API call failed for ${api_repo} (page ${page}, attempt ${attempt}); retrying..." >&2 + resp="" + sleep $((attempt * 3)) + done + [ -n "$resp" ] || { echo "ERROR: Quay tag API unreachable for ${api_repo} after retries" >&2; return 1; } + latest=$(echo "$resp" | jq -r ' + [.tags[]? | select(.name | test("^[a-f0-9]{40}$"))] + | sort_by(.start_ts) | reverse | .[0].name // empty') + [ -n "$latest" ] && break + [ "$(echo "$resp" | jq -r '.has_additional')" = "true" ] || break + page=$((page + 1)) + if [ "$page" -gt 100 ]; then + echo "ERROR: no SHA-form tag found for ${api_repo} within ${page} pages" >&2 + return 1 + fi + done + if [ -z "$latest" ]; then + echo "ERROR: no SHA-form tag found for ${api_repo}" >&2 + return 1 + fi + echo "${repo}:${latest}" +} + REPO="quay.io/redhat-user-workloads/kueue-operator-tenant/kueue-bundle-dev-main" -BUNDLE_IMAGE=$(skopeo list-tags docker://$REPO | jq -r '.Tags[]' | grep -E '^[a-f0-9]{40}$' | while read -r tag; do - created=$(skopeo inspect docker://$REPO:$tag 2>/dev/null | jq -r '.Created') - if [ "$created" != "null" ] && [ -n "$created" ]; then echo "$created $tag"; fi -done | sort | tail -n1 | awk -v repo="$REPO" '{print repo ":" $2}') +BUNDLE_IMAGE=$(resolve_latest_image "$REPO") if [[ -z "$BUNDLE_IMAGE" ]]; then echo "ERROR: Failed to resolve BUNDLE_IMAGE from $REPO" diff --git a/ci-operator/step-registry/kueue-operator/disconnected/compute/kueue-operator-disconnected-compute-commands.sh b/ci-operator/step-registry/kueue-operator/disconnected/compute/kueue-operator-disconnected-compute-commands.sh index 92a4a570d65e..79bf1a4b4171 100644 --- a/ci-operator/step-registry/kueue-operator/disconnected/compute/kueue-operator-disconnected-compute-commands.sh +++ b/ci-operator/step-registry/kueue-operator/disconnected/compute/kueue-operator-disconnected-compute-commands.sh @@ -4,12 +4,49 @@ set -e set -u set -o pipefail +# Resolve the newest 40-char SHA tag of a Quay repo via the Quay tag API. +# Reads push timestamps (start_ts) in bulk instead of running `skopeo inspect` +# per tag, which does not scale with the number of accumulated CI build tags. +# Prints ":" for the newest tag, or nothing if none is found. +resolve_latest_image() { + local repo=$1 + local api_repo="${repo#quay.io/}" + local page=1 resp attempt latest="" + # Quay returns tags newest-first, so page 1 normally already holds the newest + # SHA-form tag; keep paging only while Quay reports additional pages. + while :; do + resp="" + for attempt in 1 2 3; do + if resp=$(wget -q -O - --tries=1 --timeout=30 \ + "https://quay.io/api/v1/repository/${api_repo}/tag/?onlyActiveTags=true&limit=100&page=${page}"); then + break + fi + echo "WARN: Quay tag API call failed for ${api_repo} (page ${page}, attempt ${attempt}); retrying..." >&2 + resp="" + sleep $((attempt * 3)) + done + [ -n "$resp" ] || { echo "ERROR: Quay tag API unreachable for ${api_repo} after retries" >&2; return 1; } + latest=$(echo "$resp" | jq -r ' + [.tags[]? | select(.name | test("^[a-f0-9]{40}$"))] + | sort_by(.start_ts) | reverse | .[0].name // empty') + [ -n "$latest" ] && break + [ "$(echo "$resp" | jq -r '.has_additional')" = "true" ] || break + page=$((page + 1)) + if [ "$page" -gt 100 ]; then + echo "ERROR: no SHA-form tag found for ${api_repo} within ${page} pages" >&2 + return 1 + fi + done + if [ -z "$latest" ]; then + echo "ERROR: no SHA-form tag found for ${api_repo}" >&2 + return 1 + fi + echo "${repo}:${latest}" +} + echo "[$(date -u --rfc-3339=seconds)] Resolving latest bundle image..." BUNDLE_REPO="quay.io/redhat-user-workloads/kueue-operator-tenant/${BUNDLE_COMPONENT}" -BUNDLE_IMAGE=$(skopeo list-tags docker://$BUNDLE_REPO | jq -r '.Tags[]' | grep -E '^[a-f0-9]{40}$' | while read -r tag; do - created=$(skopeo inspect docker://$BUNDLE_REPO:$tag 2>/dev/null | jq -r '.Created') - if [ "$created" != "null" ] && [ -n "$created" ]; then echo "$created $tag"; fi -done | sort | tail -n1 | awk -v repo="$BUNDLE_REPO" '{print repo ":" $2}') +BUNDLE_IMAGE=$(resolve_latest_image "$BUNDLE_REPO") if [[ -z "$BUNDLE_IMAGE" ]]; then echo "ERROR: Failed to resolve BUNDLE_IMAGE from $BUNDLE_REPO" diff --git a/ci-operator/step-registry/kueue-operator/image-env-setup/kueue-operator-image-env-setup-commands.sh b/ci-operator/step-registry/kueue-operator/image-env-setup/kueue-operator-image-env-setup-commands.sh index 3a0f1692b7c4..9fa0b281005f 100644 --- a/ci-operator/step-registry/kueue-operator/image-env-setup/kueue-operator-image-env-setup-commands.sh +++ b/ci-operator/step-registry/kueue-operator/image-env-setup/kueue-operator-image-env-setup-commands.sh @@ -28,14 +28,50 @@ echo "Latest Git commits:" git log --oneline -5 echo "Git status:" git status +# Resolve the newest 40-char SHA tag of a Quay repo via the Quay tag API. +# Reads push timestamps (start_ts) in bulk instead of running `skopeo inspect` +# per tag, which does not scale with the number of accumulated CI build tags. +# Prints ":" for the newest tag, or nothing if none is found. resolve_latest_image() { local repo=$1 - skopeo list-tags "docker://$repo" | jq -r '.Tags[]' | grep -E '^[a-f0-9]{40}$' | while read -r tag; do - created=$(skopeo inspect "docker://$repo:$tag" 2>/dev/null | jq -r '.Created') - if [ "$created" != "null" ] && [ -n "$created" ]; then echo "$created $tag"; fi - done | sort | tail -n1 | awk -v repo="$repo" '{print repo ":" $2}' + local api_repo="${repo#quay.io/}" + local page=1 resp attempt latest="" + # Quay returns tags newest-first, so page 1 normally already holds the newest + # SHA-form tag; keep paging only while Quay reports additional pages. + while :; do + resp="" + for attempt in 1 2 3; do + if resp=$(wget -q -O - --tries=1 --timeout=30 \ + "https://quay.io/api/v1/repository/${api_repo}/tag/?onlyActiveTags=true&limit=100&page=${page}"); then + break + fi + echo "WARN: Quay tag API call failed for ${api_repo} (page ${page}, attempt ${attempt}); retrying..." >&2 + resp="" + sleep $((attempt * 3)) + done + [ -n "$resp" ] || { echo "ERROR: Quay tag API unreachable for ${api_repo} after retries" >&2; return 1; } + latest=$(echo "$resp" | jq -r ' + [.tags[]? | select(.name | test("^[a-f0-9]{40}$"))] + | sort_by(.start_ts) | reverse | .[0].name // empty') + [ -n "$latest" ] && break + [ "$(echo "$resp" | jq -r '.has_additional')" = "true" ] || break + page=$((page + 1)) + if [ "$page" -gt 100 ]; then + echo "ERROR: no SHA-form tag found for ${api_repo} within ${page} pages" >&2 + return 1 + fi + done + if [ -z "$latest" ]; then + echo "ERROR: no SHA-form tag found for ${api_repo}" >&2 + return 1 + fi + echo "${repo}:${latest}" } +# Resolve the image for a Quay repo, preferring the current PR's on-pr build. +# Does a single `skopeo inspect` for the "on-pr-" tag; if present it is +# used directly, otherwise falls back to resolve_latest_image for the newest +# branch build. Prints ":", or nothing if neither can be resolved. resolve_image() { local repo=$1 local pr_tag="on-pr-${REVISION}"