Skip to content

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

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

Conversation

Honny1
Copy link
Member

@Honny1 Honny1 commented Apr 3, 2025

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?

Fixed: `podman image <name>` now lists only images matching the given name, not all tags.

@openshift-ci openshift-ci bot added release-note do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Apr 3, 2025
Copy link
Contributor

openshift-ci bot commented Apr 3, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Honny1
Once this PR has been reviewed and has the lgtm label, please assign tomsweeneyredhat for approval. For more information see the Code Review Process.

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@Honny1 Honny1 marked this pull request as ready for review April 4, 2025 08:20
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 4, 2025
if len(args) > 0 && !listOptions.All {
for _, img := range summaries {
for _, repoTag := range img.RepoTags {
if strings.Contains(repoTag, args[0]) {
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@Luap99 Luap99 left a 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.

@Honny1
Copy link
Member Author

Honny1 commented Apr 4, 2025

@Luap99 I don't think so. The registry.ImageEngine().List() function returns the correct summaries, but the sortImages() function returns imageReporter for each tag from RepoTags. This causes localhost/example:latest and registry.fedoraproject.org/fedora:41 to be listed for the podman images example command.


Steps to reproduce the issue:

  1. echo "FROM fedora:41" > Containerfile
  2. podman build -t example .
  3. podman images example

@Luap99
Copy link
Member

Luap99 commented Apr 4, 2025

@Luap99 I don't think so. The registry.ImageEngine().List() function returns the correct summaries, but the sortImages() function returns imageReporter for each tag from RepoTags. This causes localhost/example:latest and registry.fedoraproject.org/fedora:41 to be listed for the podman images example command.

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.

@Luap99
Copy link
Member

Luap99 commented Apr 4, 2025

Also not that podman images <name> is mapped to --filter reference=<name> I would expect both to display the same thing but it seems with your current code you only take care of the len(args) > 0 case not the filter one.

@Honny1 Honny1 force-pushed the list-images branch 3 times, most recently from 8d833b6 to 088367b Compare April 4, 2025 13:09
@Honny1
Copy link
Member Author

Honny1 commented Apr 4, 2025

@Luap99 I moved the filtering to the sortImages() function and used the reference filter.

for _, filter := range listOptions.Filter {
if strings.HasPrefix(filter, "reference=") {
reference = strings.TrimPrefix(filter, "reference=")
if strings.HasPrefix(reference, "sha256:") {
Copy link
Member

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>") {
Copy link
Member

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 + "$")
Copy link
Member

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?

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Member Author

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

Comment on lines +551 to +553
containerFile := "FROM quay.io/libpod/alpine:latest"
imageName := "exampletestimage"
podmanTest.BuildImage(containerFile, imageName, "false")
Copy link
Member

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

Comment on lines +134 to +135
if strings.HasPrefix(filter, "reference=") {
reference = strings.TrimPrefix(filter, "reference=")
Copy link
Member

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()

@Honny1 Honny1 marked this pull request as draft April 5, 2025 12:19
@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

podman images <image> can show duplicate results
4 participants