-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
libpod/image: Use ParseNormalizedNamed in RepoDigests #2106
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"testing" | ||
|
||
"github.com/containers/storage" | ||
"github.com/opencontainers/go-digest" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -192,6 +193,51 @@ func TestImage_MatchRepoTag(t *testing.T) { | |
cleanup(workdir, ir) | ||
} | ||
|
||
// TestImage_RepoDigests tests RepoDigest generation. | ||
func TestImage_RepoDigests(t *testing.T) { | ||
dgst, err := digest.Parse("sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
for _, test := range []struct { | ||
name string | ||
names []string | ||
expected []string | ||
}{ | ||
{ | ||
name: "empty", | ||
names: []string{}, | ||
expected: nil, | ||
}, | ||
{ | ||
name: "tagged", | ||
names: []string{"docker.io/library/busybox:latest"}, | ||
expected: []string{"docker.io/library/busybox@sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How often does Busybox update (such that this would no longer pull the same image)? Can we throw a comment on here that this needs updating when busybox bumps its image version? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This digest is hard-coded in the test itself; it is completely decoupled from any real-world BusyBox image. So no need to bump anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, sorry, I meant the line above - There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Still just a string I'm hard-coding for these unit tests with no relation to real-world images. The new unit tests should just be exercising vendored string-manipulation code; they aren't hitting the network or anything. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alright, should be fine then, thanks |
||
}, | ||
{ | ||
name: "digest", | ||
names: []string{"docker.io/library/busybox@sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc"}, | ||
expected: []string{"docker.io/library/busybox@sha256:7173b809ca12ec5dee4506cd86be934c4596dd234ee82c0662eac04a8c2c71dc"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test fails with the doubled |
||
}, | ||
} { | ||
t.Run(test.name, func(t *testing.T) { | ||
image := &Image{ | ||
image: &storage.Image{ | ||
Names: test.names, | ||
Digest: dgst, | ||
}, | ||
} | ||
actual, err := image.RepoDigests() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
assert.Equal(t, test.expected, actual) | ||
}) | ||
} | ||
} | ||
|
||
// Test_splitString tests the splitString function in image that | ||
// takes input and splits on / and returns the last array item | ||
func Test_splitString(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,13 +41,18 @@ func (i *LibpodAPI) ListImages(call iopodman.VarlinkCall) error { | |
for _, image := range images { | ||
labels, _ := image.Labels(getContext()) | ||
containers, _ := image.Containers() | ||
repoDigests, err := image.RepoDigests() | ||
if err != nil { | ||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yeah, I left the existing error-ignores alone, since I don't understand their motivation. I'm happy to make these all consistent though (one way or the other) if someone can explain the motivation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we don't want to fatally fail when trying to get some information on an image, but it's not commented at all so I'm not sure. @baude this intentional? |
||
} | ||
|
||
size, _ := image.Size(getContext()) | ||
|
||
i := iopodman.ImageInList{ | ||
Id: image.ID(), | ||
ParentId: image.Parent, | ||
RepoTags: image.Names(), | ||
RepoDigests: image.RepoDigests(), | ||
RepoDigests: repoDigests, | ||
Created: image.Created().String(), | ||
Size: int64(*size), | ||
VirtualSize: image.VirtualSize, | ||
|
@@ -73,6 +78,10 @@ func (i *LibpodAPI) GetImage(call iopodman.VarlinkCall, name string) error { | |
if err != nil { | ||
return err | ||
} | ||
repoDigests, err := newImage.RepoDigests() | ||
if err != nil { | ||
return err | ||
} | ||
size, err := newImage.Size(getContext()) | ||
if err != nil { | ||
return err | ||
|
@@ -82,7 +91,7 @@ func (i *LibpodAPI) GetImage(call iopodman.VarlinkCall, name string) error { | |
Id: newImage.ID(), | ||
ParentId: newImage.Parent, | ||
RepoTags: newImage.Names(), | ||
RepoDigests: newImage.RepoDigests(), | ||
RepoDigests: repoDigests, | ||
Created: newImage.Created().String(), | ||
Size: int64(*size), | ||
VirtualSize: newImage.VirtualSize, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW c/image/storage silently ignores errors (=
.Names
entries not in the c/image/docker/reference format).Names
are not documented to be in any particular format, so hard failures here may not be appropriate — OTOH maybe we should tighten the definition ofNames
instead. I don’t know.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have an opinion on what
ParseNormaliedNamed
wants to consider an error, but if it returns an error, I think we should be passing it back up the chain. I certainly don't want different opinions on what names are considered valid living at different places in the stack.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m saying that the existing opinion/practice is that non-
ParseNormalizedNamed
names are 1) allowed and 2) silently ignored, so if you ”don’t want different opinions” (which I agree with) the right thing to do is to silently ignore such names as well.I do support tightening the definition, but if that should happen, it needs be a separate PR set across c/storage (documenting the field as such)+c/image+libpod (using it) and maybe others.