-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix duplicate results in podman images <image> #25783
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
base: main
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Honny1 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
cmd/podman/images/list.go
Outdated
if len(args) > 0 && !listOptions.All { | ||
for _, img := range summaries { | ||
for _, repoTag := range img.RepoTags { | ||
if strings.Contains(repoTag, args[0]) { |
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.
is strings.Contains
the expected comparison to perform here?
e.g., if I build two images like:
$ podman build -t exam .
podman build -t example .
then I get:
$ bin/podman images exam
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/exam latest ca20047de3b8 3 hours ago 165 MB
localhost/example latest ca20047de3b8 3 hours ago 165 MB
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've changed the way it filters. Now regex is used.
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 feel like this is the wrong place to fix it. This will not fix the filter for any API user.
IMO this needs to be fixed where the filter actually runs which I guess would be in libimage.
@Luap99 I don't think so. The Steps to reproduce the issue:
|
Ok but then would it not be better to the the filtering directly in the sortImages() loop? Looping several times like this here seems quite inefficient. Also btw, I think you can just use podman tag, no need to use podman build. |
Also not that |
8d833b6
to
088367b
Compare
@Luap99 I moved the filtering to the |
Fixes: containers#25725 Fixes: https://issues.redhat.com/browse/RUN-2726 Signed-off-by: Jan Rodák <[email protected]>
for _, filter := range listOptions.Filter { | ||
if strings.HasPrefix(filter, "reference=") { | ||
reference = strings.TrimPrefix(filter, "reference=") | ||
if strings.HasPrefix(reference, "sha256:") { |
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.
why are digests filtered out here?
break | ||
} | ||
reference, _, _ = tokenRepoTag(reference) | ||
if strings.Contains(reference, "<none>") { |
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.
should this be an ==
not contains? But again it is not clear to me why this is done at all.
This whole section should have proper comments what is being filtered here.
var err error | ||
var referenceRegex *regexp.Regexp | ||
if reference != "" { | ||
referenceRegex, err = regexp.Compile(reference + "$") |
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.
isn't this effectively a HasSuffix() match, why do we need a regex for this?
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.
Also, a suffix match is still not at all great: example.com/foo
matches notexample.com/foo
.
As a first guess, I agree with @Luap99 that this (whatever “this” is[1]) should be done in libimage. I don’t know how, maybe a new “return only matching names” option to ListImageOptions
, maybe something completely different.
The principle, as I understand it, is that libimage knows exactly what matched and how. That information is ~lost here, and we are reduced to guessing; and if we ever change libimage, this will get out of sync.
[1] “whatever this is”: I do expect that this might look harder to do inside libimage, because all the various corner cases will be visible. E.g. what should happen on reference!=…
filters?? But, to me, that’s an even stronger reason to do it in libimage.
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.
Okay, Now I understand why. I will do it in libimage
. And I will keep PR as a draft for tests and vendoring of c/common
.
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.
libimage
PR: containers/common#2413
containerFile := "FROM quay.io/libpod/alpine:latest" | ||
imageName := "exampletestimage" | ||
podmanTest.BuildImage(containerFile, imageName, "false") |
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.
this can use podman tag instead which seems simpler
if strings.HasPrefix(filter, "reference=") { | ||
reference = strings.TrimPrefix(filter, "reference=") |
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.
doesn't the regular filter code allow more than one reference? SO I think this needs to handle all not just the first match.
Also you should use CutPrefix()
This PR fixes an issue where an image has multiple names (tags) and when you run
podman image <name>
for one of the names, all the names are displayed. According to the documentation, the command should only list the images that match the name.Fixes: #25725
Fixes: https://issues.redhat.com/browse/RUN-2726
Does this PR introduce a user-facing change?