Skip to content

Commit 51a9bc8

Browse files
Merge pull request #16191 from odra/fix-16180_ancestor-filter-regex
adding regex support to the ancestor ps filter function
2 parents c426fd9 + 6c7ae37 commit 51a9bc8

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

docs/source/markdown/podman-ps.1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Valid filters are listed below:
5252
| label | [Key] or [Key=Value] Label assigned to a container |
5353
| exited | [Int] Container's exit code |
5454
| status | [Status] Container's status: 'created', 'exited', 'paused', 'running', 'unknown' |
55-
| ancestor | [ImageName] Image or descendant used to create container |
55+
| ancestor | [ImageName] Image or descendant used to create container (accepts regex) |
5656
| before | [ID] or [Name] Containers created before this container |
5757
| since | [ID] or [Name] Containers created since this container |
5858
| volume | [VolumeName] or [MountpointDestination] Volume mounted in container |

pkg/domain/filters/containers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ func GenerateContainerFilterFuncs(filter string, filterValues []string, r *libpo
9696
}
9797

9898
if (rootfsImageID == filterValue) ||
99-
(rootfsImageName == filterValue) ||
100-
(imageNameWithoutTag == filterValue && imageTag == "latest") {
99+
util.StringMatchRegexSlice(rootfsImageName, filterValues) ||
100+
(util.StringMatchRegexSlice(imageNameWithoutTag, filterValues) && imageTag == "latest") {
101101
return true
102102
}
103103
}

test/e2e/ps_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,22 @@ var _ = Describe("Podman ps", func() {
313313
Expect(result).Should(Exit(0))
314314
Expect(result.OutputToString()).To(Equal(cid))
315315

316-
// Query by truncated image name should not match ( should return empty output )
316+
// Query by truncated image name should match (regexp match)
317317
result = podmanTest.Podman([]string{"ps", "-q", "--no-trunc", "-a", "--filter", "ancestor=quay.io/libpod/alpi"})
318318
result.WaitWithDefaultTimeout()
319319
Expect(result).Should(Exit(0))
320+
Expect(result.OutputToString()).To(Equal(cid))
321+
322+
// Query using regex by truncated image name should match (regexp match)
323+
result = podmanTest.Podman([]string{"ps", "-q", "--no-trunc", "-a", "--filter", "ancestor=^(quay.io|docker.io)/libpod/alpine:[a-zA-Z]+"})
324+
result.WaitWithDefaultTimeout()
325+
Expect(result).Should(Exit(0))
326+
Expect(result.OutputToString()).To(Equal(cid))
327+
328+
// Query for an non-existing image using regex should not match anything
329+
result = podmanTest.Podman([]string{"ps", "-q", "--no-trunc", "-a", "--filter", "ancestor=^quai.io/libpod/alpi"})
330+
result.WaitWithDefaultTimeout()
331+
Expect(result).Should(Exit(0))
320332
Expect(result.OutputToString()).To(Equal(""))
321333
})
322334

0 commit comments

Comments
 (0)