Skip to content

Commit

Permalink
JIRA-SONIC-9824: Add retry for pulling k8s when building the SONiC image
Browse files Browse the repository at this point in the history
Pulling universal k8s images is not stable. It sometimes fails.
Add retry to fix build image failure.
  • Loading branch information
chiourung committed Sep 10, 2024
1 parent 9f77012 commit 9fa4e2a
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions files/build_templates/sonic_debian_extension.j2
Original file line number Diff line number Diff line change
Expand Up @@ -798,8 +798,33 @@ sudo LANG=C DOCKER_HOST="$DOCKER_HOST" chroot $FILESYSTEM_ROOT /usr/local/bin/ge
{% if include_kubernetes == "y" %}
## Pull in kubernetes docker images
echo "pulling universal k8s images ..."
sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS pull k8s.gcr.io/pause:${K8s_GCR_IO_PAUSE_VERSION}
echo "docker images pull complete"

MAX_ATTEMPTS=5
RETRY_INTERVAL=10
attempt=1

# skip Exit immediately due to error retry
set +e
while [ $attempt -le $MAX_ATTEMPTS ]; do
output=$(sudo https_proxy=$https_proxy LANG=C chroot $FILESYSTEM_ROOT docker $SONIC_NATIVE_DOCKERD_FOR_DOCKERFS pull k8s.gcr.io/pause:${K8s_GCR_IO_PAUSE_VERSION} 2>&1)
exit_status=$?
if [ $exit_status -eq 0 ]; then
echo "docker images pull complete"
break
else
echo "Failed to pull Docker image. Error message:"
echo "$output"
echo "Retrying in $RETRY_INTERVAL seconds..."
sleep $RETRY_INTERVAL
fi

attempt=$(( $attempt + 1 ))
done
set -e
if [ $attempt -gt $MAX_ATTEMPTS ]; then
echo "Failed to pull Docker image after $MAX_ATTEMPTS attempts."
exit 1
fi
{% endif %}

{% if include_kubernetes_master == "y" %}
Expand Down

0 comments on commit 9fa4e2a

Please sign in to comment.