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 the docker image parser to account for private repos #24926

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Juanadelacuesta
Copy link
Member

@Juanadelacuesta Juanadelacuesta commented Jan 23, 2025

Description

This PR addresses this issue.

There was a little bug in the parseDockerImage where we were using / the determine the tag and if none was found, it would add latest, completely ignoring the cases where there is a sha present.

This PR refactors the logic to avoid adding the latest tag if a sha is provided.

The extra change corresponds to moving the tests to the utils_test.go for clarity.

Testing & Reproduction steps

Links

Contributor Checklist

  • Changelog Entry If this PR changes user-facing behavior, please generate and add a
    changelog entry using the make cl command.
  • Testing Please add tests to cover any new functionality or to demonstrate bug fixes and
    ensure regressions will be caught.
  • Documentation If the change impacts user-facing functionality such as the CLI, API, UI,
    and job configuration, please update the Nomad website documentation to reflect this. Refer to
    the website README for docs guidelines. Please also consider whether the
    change requires notes within the upgrade guide.

Reviewer Checklist

  • Backport Labels Please add the correct backport labels as described by the internal
    backporting document.
  • Commit Type Ensure the correct merge method is selected which should be "squash and merge"
    in the majority of situations. The main exceptions are long-lived feature branches or merges where
    history should be preserved.
  • Enterprise PRs If this is an enterprise only PR, please add any required changelog entry
    within the public repository.

@Juanadelacuesta Juanadelacuesta changed the title fix: fix the docker image parser to account for private repos Fix the docker image parser to account for private repos Jan 23, 2025
@Juanadelacuesta Juanadelacuesta added the backport/1.9.x backport to 1.9.x release line label Jan 23, 2025
@Juanadelacuesta Juanadelacuesta marked this pull request as ready for review January 23, 2025 17:27
@Juanadelacuesta Juanadelacuesta requested review from a team as code owners January 23, 2025 17:27
@@ -21,31 +21,41 @@ import (
"github.com/docker/docker/registry"
)

var regexForDockerImages = `^(?:(?P<registry>[^/]+)/)?(?P<repository>[^:@]+)(?::(?P<tag>[^@]+))?(?:@(?P<digest>sha256:[a-fA-F0-9]{64}))?$`
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 have https://pkg.go.dev/github.com/distribution/reference as a dependency. Maybe we should use that official upstream instead of our own regex (as awesome as this regex is 😁 )? We can probably even ditch the test in that case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

tag = "latest"
matches := reference.ReferenceRegexp.FindStringSubmatch(image)
if matches == nil {
return "", ""
Copy link
Member

Choose a reason for hiding this comment

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

The caller doesn't expect an empty string value and is going to do some weird stuff in this case like incrementing the image reference count for empty string. (The original version of this function would return something even if it wasn't all that useful.) We should probably adjust the signature of this function to return an error and have the caller handle that properly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.9.x backport to 1.9.x release line
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants