Skip to content

Commit

Permalink
Merge pull request #10074 from flouthoc/ancestor-truncate-bug
Browse files Browse the repository at this point in the history
Fix podman ps --filter ancestor to match exact ImageName/ImageID
  • Loading branch information
openshift-merge-robot authored Apr 27, 2021
2 parents bdcfdad + b0ea40f commit 54344d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/domain/filters/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,19 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
return func(c *libpod.Container) bool {
for _, filterValue := range filterValues {
containerConfig := c.Config()
if strings.Contains(containerConfig.RootfsImageID, filterValue) || strings.Contains(containerConfig.RootfsImageName, filterValue) {
var imageTag string
var imageNameWithoutTag string
// Compare with ImageID, ImageName
// Will match ImageName if running image has tag latest for other tags exact complete filter must be given
imageNameSlice := strings.SplitN(containerConfig.RootfsImageName, ":", 2)
if len(imageNameSlice) == 2 {
imageNameWithoutTag = imageNameSlice[0]
imageTag = imageNameSlice[1]
}

if (containerConfig.RootfsImageID == filterValue) ||
(containerConfig.RootfsImageName == filterValue) ||
(imageNameWithoutTag == filterValue && imageTag == "latest") {
return true
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ var _ = Describe("Podman ps", func() {
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal(cid))

// Query by trunctated image name should not match ( should return empty output )
result = podmanTest.Podman([]string{"ps", "-q", "--no-trunc", "-a", "--filter", "ancestor=quay.io/libpod/alpi"})
result.WaitWithDefaultTimeout()
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(Equal(""))
})

It("podman ps id filter flag", func() {
Expand Down

0 comments on commit 54344d3

Please sign in to comment.