Skip to content

Conversation

@ZaidMarwat
Copy link

@ZaidMarwat ZaidMarwat commented Dec 16, 2025

Fix ancestor filter to resolve image names to IDs. This is necessary since image names are mutable and can thus point to different image IDs as time goes by. The image ID, on the other hand, stays immutable and thus is the best approach in finding a container's ancestor.

Fixes: #27743

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?


Fixed `podman ps --filter ancestor=...` to resolve image names and tags to immutable image IDs at container creation time.

Previously, filtering by an image name or tag (e.g., `ancestor=alpine:latest`) could incorrectly match containers if the tag was later retagged to a different image. Podman now matches containers based on the original image ID they were created from, ensuring correct and Docker-compatible behavior when image tags are mutable.

…since image names are mutable and can thus point to different image IDs as time goes by. The image ID, on the other hand, stays immutable and thus is the best approach in finding a container's ancestor.

Fixes: containers#27743

Signed-off-by: Zaid Marwat <zaidratify123@gmail.com>
@ZaidMarwat
Copy link
Author

Hi, this is my first contribution to Podman, so please bear with me as I’m still learning the project’s testing expectations.

I wanted to note that I ran make validatepr locally, but I am consistently hitting a Darwin (macOS) build failure. I verified that this does not appear to be related to my changes: I checked out a clean branch from main with no modifications and ran validatepr there as well, and it failed with the same Darwin build error. Based on that, I believe the failure is environmental or pre-existing rather than caused by this PR.

I am still working through the testing requirements and would appreciate any guidance on whether additional tests are expected beyond what I’ve added, or if there is a preferred way to validate this change.

Lastly, please let me know if you think this change warrants any documentation updates. I’m happy to add documentation if needed.

Thank you for your time!

Copy link
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the contribution. I have several comments on the PR.

First, please create a test that reproduces this issue. It can be a simple BATS test written in Bash or an E2E test in Golang. Also, please validate the new behavior with Docker. If Padman produce same results.

There is also an issue with the validatepr image. To run this, you need to remove that image and ideally build your own; I think the new image isn't built yet for ARM64. Here are the commands:

$ podman rmi quay.io/libpod/validatepr:latest

$ podman build -t quay.io/libpod/validatepr:latest . -f contrib/validatepr/Containerfile

for _, filterValue := range filterValues {
img, _, err := imgRuntime.LookupImage(filterValue, nil)
if err == nil && img != nil {
// filterValue is a resolvable image name[:tag]
Copy link
Member

Choose a reason for hiding this comment

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

CI is not happy

pkg/domain/filters/containers.go:101:1: File is not properly formatted (gofumpt)
				// filterValue is a resolvable image name[:tag] 
^
1 issues:

Copy link
Author

Choose a reason for hiding this comment

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

Silly mistake, ill get that fixed

// - ancestor=(<image-name>[:tag]|<image-id>| ⟨image@digest⟩) - containers created from an image or a descendant.
imgRuntime := r.LibimageRuntime()
var resolvedIDs []string
var passthrough []string
Copy link
Member

Choose a reason for hiding this comment

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

I think this is not necessary because LookupImage also accepts IDs.

Copy link
Author

Choose a reason for hiding this comment

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

Sounds good! I didn't catch that on the first scan of LookupImage.

}
imgRuntime := r.LibimageRuntime()
var resolvedIDs []string
var passthrough []string
Copy link
Member

Choose a reason for hiding this comment

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

ditto

case "ancestor":
// This needs to refine to match docker
// - ancestor=(<image-name>[:tag]|<image-id>| ⟨image@digest⟩) - containers created from an image or a descendant.
imgRuntime := r.LibimageRuntime()
Copy link
Member

Choose a reason for hiding this comment

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

Both changes in the "ancestor" case seem similar. I would like to see some deduplication to keep it DRY.

case "ancestor":
// This needs to refine to match docker
// - ancestor=(<image-name>[:tag]|<image-id>| ⟨image@digest⟩) - containers created from an image or a descendant.
imgRuntime := r.LibimageRuntime()
Copy link
Member

Choose a reason for hiding this comment

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

All of this feels like it ought to be in the returned function, not here?

Copy link
Author

Choose a reason for hiding this comment

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

Please correct me on any misconceptions I might have but, it looks to me like the code within the return function runs for every container while the code outside is just called once per filter. So I kept this logic outside the returned function to avoid doing expensive work repeatedly (which, taking a look at LibimageRuntime(), seems to be the case). Resolving image names to IDs with LookupImage only needs to happen once, and putting it inside the returned function would cause it to run for every container.

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.

--ancestor refers to container's original image tag, rather than current

3 participants