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

Fixed a bug where we always pulled an image if image name had a transport prefix #88

Merged
merged 6 commits into from Mar 9, 2021

Conversation

towe75
Copy link
Collaborator

@towe75 towe75 commented Feb 13, 2021

Images prefixed with a transport where always pulled.
I noticed this while examining podman logs during unit test runs. It re-pulled busybox for each single test.

This PR improves image url parsing and also makes the code a bit nicer by adding an extra method for image handling.

Images prefixed with a transport where always pulled.
Added image url parser
@towe75
Copy link
Collaborator Author

towe75 commented Feb 25, 2021

@krishicks : please review, this also fixes #90 when using podman 2.x

Copy link
Contributor

@krishicks krishicks left a comment

Choose a reason for hiding this comment

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

This looks good to me, though I would like to see the image-transforming code extracted into a separate, tested function.

driver.go Outdated
Comment on lines 578 to 607
// FIXME: there are more variations of image sources, we should handle it
// e.g. oci-archive:/... etc
// see also https://github.com/hashicorp/nomad-driver-podman/issues/69

// strip http/https and docker transport prefix
for _, prefix := range []string{"http://", "https://", "docker://"} {
if strings.HasPrefix(image, prefix) {
image = strings.Replace(image, prefix, "", 1)
}
}

named, err := dockerref.ParseNormalizedNamed(image)
if err != nil {
return err
}

var tag, digest string

tagged, ok := named.(dockerref.Tagged)
if ok {
tag = tagged.Tag()
}

digested, ok := named.(dockerref.Digested)
if ok {
digest = digested.Digest().String()
}
if len(tag) == 0 && len(digest) == 0 {
tag = "latest"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be nice to extract all of this into its own function, since most of this function exists to manipulate a given image. That could then have its own set of tests to make it clear what the expected output for a given input are.

At that point I'd remove the ensureImage function entirely, as it would be about the same length as it was before.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@krishicks PTAL, i added a separate, tested, function. I think it's ok to also keep ensureImage() because of possible, future, improvements regarding oci-archive etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the new tested function. I would still remove ensureImage, as any future change that warrants bringing it back can do so at that time. Otherwise, it's YAGNI.

My approval still applies, in any event.

Base automatically changed from master to main March 3, 2021 20:39
@towe75 towe75 merged commit e9a502d into main Mar 9, 2021
@towe75 towe75 deleted the b_image_parser branch March 9, 2021 19:05
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.

None yet

2 participants