fix: Implement retry logic for image resolution processes#11
Conversation
Added a verification loop to check registry connectivity before starting the resolution process. Included a retry mechanism for the ko resolve command to mitigate failures caused by intermittent network issues or temporary registry unavailability. Prevented the script from proceeding with invalid configurations by ensuring it returned an error code upon repeated resolution failure. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
Summary of ChangesHello @chmouel, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the robustness of the image resolution process by introducing proactive registry connectivity verification and a retry mechanism for the 'ko resolve' command. These changes aim to improve the reliability of deployments by mitigating failures caused by temporary network instability or registry unavailability, and by providing clearer error signaling when critical steps cannot be completed. Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
ⓘ You are approaching your monthly quota for Qodo. Upgrade your plan PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
There was a problem hiding this comment.
Code Review
This pull request introduces retry logic for image resolution, which is a good improvement for handling intermittent network or registry issues. The changes include a pre-flight check for registry connectivity and a retry mechanism for the ko resolve command. My review focuses on improving the maintainability of the new retry logic by using constants for configuration and following shell scripting best practices.
| local reg_ok=false | ||
| for ((i = 1; i <= 5; i++)); do | ||
| if curl -o/dev/null --fail -k -s "https://${REGISTRY}/v2/"; then | ||
| reg_ok=true | ||
| break | ||
| fi | ||
| echo "Registry not ready, retrying in 5s ($i/5)..." | ||
| sleep 5 | ||
| done | ||
| if [[ ${reg_ok} != true ]]; then | ||
| echo "Warning: Registry ${REGISTRY} not responding, proceeding anyway..." | ||
| fi |
There was a problem hiding this comment.
The retry logic is a great addition. To improve maintainability and readability, consider extracting the magic numbers for retries and sleep intervals into named constants. Also, it's a good practice to quote variables within [[ ... ]] tests to prevent potential issues.
local reg_ok=false
local -r registry_check_retries=5
local -r registry_check_interval=5
for ((i = 1; i <= registry_check_retries; i++)); do
if curl -o/dev/null --fail -k -s "https://${REGISTRY}/v2/"; then
reg_ok=true
break
fi
echo "Registry not ready, retrying in ${registry_check_interval}s ($i/${registry_check_retries})..."
sleep "${registry_check_interval}"
done
if [[ "${reg_ok}" != "true" ]]; then
echo "Warning: Registry ${REGISTRY} not responding, proceeding anyway..."
fi
| local ko_success=false | ||
| local ko_max_retries=3 | ||
| for ((attempt = 1; attempt <= ko_max_retries; attempt++)); do | ||
| if env KO_DOCKER_REPO="${REGISTRY}" ko resolve -f"${c}" "${extras[@]}" -B --sbom=none "${KO_EXTRA_FLAGS[@]}" >"${tmppac}"; then | ||
| ko_success=true | ||
| break | ||
| fi | ||
| if [[ ${attempt} -lt ${ko_max_retries} ]]; then | ||
| echo "ko resolve failed (attempt ${attempt}/${ko_max_retries}), retrying in 15s..." | ||
| sleep 15 | ||
| fi | ||
| done | ||
| if [[ ${ko_success} != true ]]; then | ||
| echo "ko resolve failed after ${ko_max_retries} attempts" | ||
| return 1 | ||
| fi |
There was a problem hiding this comment.
Similar to the registry check, extracting the magic number for the retry interval into a named constant would improve maintainability. Also, quoting the variable in the if condition is a good practice.
local ko_success=false
local -r ko_max_retries=3
local -r ko_retry_interval=15
for ((attempt = 1; attempt <= ko_max_retries; attempt++)); do
if env KO_DOCKER_REPO="${REGISTRY}" ko resolve -f"${c}" "${extras[@]}" -B --sbom=none "${KO_EXTRA_FLAGS[@]}" >"${tmppac}"; then
ko_success=true
break
fi
if [[ ${attempt} -lt ${ko_max_retries} ]]; then
echo "ko resolve failed (attempt ${attempt}/${ko_max_retries}), retrying in ${ko_retry_interval}s..."
sleep "${ko_retry_interval}"
fi
done
if [[ "${ko_success}" != "true" ]]; then
echo "ko resolve failed after ${ko_max_retries} attempts"
return 1
fi
Added a verification loop to check registry connectivity before starting the resolution process. Included a retry mechanism for the ko resolve command to mitigate failures caused by intermittent network issues or temporary registry unavailability. Prevented the script from proceeding with invalid configurations by ensuring it returned an error code upon repeated resolution failure.