Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: refactor replace_image_pullspec to use other helper functions #361

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yashvardhannanavati
Copy link
Contributor

a recent commit introduced helper functions to retrieve repo, tag and digest of an image. this commit refactors replace_image_pullspec to use the helper function instead of implementing the logic inside the function.

a recent commit introduced helper functions to retrieve repo, tag
and digest of an image. this commit refactors replace_image_pullspec
to use the helper function instead of implementing the logic inside
the function.

Signed-off-by: Yashvardhan Nanavati <[email protected]>
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Please upload report for BASE (main@4156771). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             main      #361   +/-   ##
========================================
  Coverage        ?   100.00%           
========================================
  Files           ?        18           
  Lines           ?       502           
  Branches        ?         0           
========================================
  Hits            ?       502           
  Misses          ?         0           
  Partials        ?         0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@yashvardhannanavati
Copy link
Contributor Author

@arewm Could you please help review this?

Comment on lines +826 to 829
if ! [[ "$image" =~ $image_regex ]]; then
echo "replace_image_pullspec: invalid pullspec format: ${image}" >&2
exit 2
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this or can we just rely on the validation of parse_image_url? Do we need to improve the validation of that function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried relying on the validation in parse_image_url but one of the tests that verifies the sha is of the required length fails.

Enhancing the validation to that function causes nearly 20 other tests to fail mainly because dummy sha's are used in the unit tests.

I can fix the validation and tests in parse_image_url and update the PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Given the fact that we have encountered multiple bugs due to test cases not accurately reflecting the real world, while this is a non-ideal case, I think the change might be beneficial in the long run.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @arewm, if the test cases don't reflect the real world, they should be updated.

Comment on lines +833 to +843
tag=$(echo "$parsed_image" | jq -r '.tag // empty')
digest=$(echo "$parsed_image" | jq -r '.digest // empty')

local replaced_pullspec="$mirror"
if [ -n "$tag" ]; then
replaced_pullspec+=":${tag}"
fi

if [ -n "$digest" ]; then
replaced_pullspec+="@${digest}"
fi
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already effectively do this in the helper functions when returning the tag and digest. With that, we check to see if the tag and digest exist before we append it to the image.

What if we add one more helper function to just return the tag and digest (checking for their existence) and then append that to the mirror?

If you don't want to do that, then we can also just reuse the same jq query to append the tag and digest (if they exist) to the mirror.

parse_image_url "$image_url" | jq -jr '.registry_repository + if .tag != "" then ":" + .tag else "" end + if .digest != "" then "@" + .digest else "" end'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants