From 5cb6fd70575fb4e4df51840d7eaa46aa3eba56b5 Mon Sep 17 00:00:00 2001 From: reyesj2 <94730068+reyesj2@users.noreply.github.com> Date: Sun, 29 Nov 2026 17:51:04 -0600 Subject: [PATCH] fail fast when the registry or an image fails One inspect preflight turns an unreachable registry into about a minute of retries instead of one round per image. The pool stops launching after a finished job fails and logs every skipped image; the caller's rc loop still reports the failures. --- salt/common/tools/sbin/so-image-common | 42 +++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/salt/common/tools/sbin/so-image-common b/salt/common/tools/sbin/so-image-common index 644031124..ade7d235f 100755 --- a/salt/common/tools/sbin/so-image-common +++ b/salt/common/tools/sbin/so-image-common @@ -400,14 +400,30 @@ _pool_abort() { # _pool_abort # Only wait on PIDs started here: soup may run its own background jobs in this # shell (e.g. the grid highstate), and a bare `wait` would block on those. +# Fail fast: once a finished job of this pool failed, no new job is launched, so +# an unreachable registry costs one round of retries instead of one per image. +pool_failed() { # pool_failed ... + local phase=$1 + shift + local img + for img in "$@"; do + if [ -f "$SIGNPATH/$img.$phase.rc" ] && + [ "$(cat "$SIGNPATH/$img.$phase.rc" 2>/dev/null)" != "0" ]; then + return 0 + fi + done + return 1 +} + launch_pool() { local func=$1 local phase=$2 local jobs=$3 local hook=$4 shift 4 - local -a active=() still=() + local -a active=() still=() launched=() local img pid + local stop=0 POOL_PIDS=() local saved_int saved_term saved_int=$(trap -p INT) @@ -415,6 +431,11 @@ launch_pool() { trap '_pool_abort 130' INT trap '_pool_abort 143' TERM for img in "$@"; do + if [ "$stop" -ne 0 ]; then + # No .rc is written, so the caller counts this image as failed too. + echo "Skipped $img: an earlier image failed" >>"$SIGNPATH/$img.$phase.log" 2>&1 + continue + fi if [ -n "$hook" ]; then "$hook" "$img" fi @@ -425,6 +446,7 @@ launch_pool() { pid=$! POOL_PIDS+=("$pid") active+=("$pid") + launched+=("$img") while [ ${#active[@]} -ge "$jobs" ]; do wait -n "${active[@]}" 2>/dev/null || true still=() @@ -434,6 +456,9 @@ launch_pool() { fi done active=("${still[@]}") + if [ "$stop" -eq 0 ] && pool_failed "$phase" "${launched[@]}"; then + stop=1 + fi done done if [ ${#POOL_PIDS[@]} -gt 0 ]; then @@ -510,6 +535,21 @@ update_docker_containers() { else progress_hook=$PROGRESS_CALLBACK fi + + # One preflight before the pool: fail in seconds instead of letting every + # verify job spend its retries in parallel. Upstream registry, not :5000. + if [ ${#TRUSTED_CONTAINERS[@]} -gt 0 ]; then + local preflight_image preflight_ref preflight_out + read -r preflight_image _ < <(resolve_image "${TRUSTED_CONTAINERS[0]}") + preflight_ref=$(image_ref "$preflight_image") + if ! preflight_out=$(retry_cmd 2 10 timeout 60 \ + docker buildx imagetools inspect --raw "$preflight_ref" 2>&1); then + echo "Could not reach $CONTAINER_REGISTRY, please ensure connectivity" >>"$LOG_FILE" 2>&1 + echo "$preflight_out" >>"$LOG_FILE" 2>&1 + exit 1 + fi + fi + launch_pool verify_trusted_image verify "$jobs" "$progress_hook" "${TRUSTED_CONTAINERS[@]}" local verify_failed=0