summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Christiansen <xordspar0@gmail.com>2020-09-23 14:58:33 -0500
committerMatthew Heon <mheon@redhat.com>2020-09-25 11:06:32 -0400
commit3be6c483c6d7ca36d16f0b312bc8c897160ab7a0 (patch)
tree41b82c9f3f59791d1f25a8a17210957ee1fa629d
parentc06dfe4ea666535ace8c46abfb7443a738099339 (diff)
downloadpodman-3be6c483c6d7ca36d16f0b312bc8c897160ab7a0.tar.gz
podman-3be6c483c6d7ca36d16f0b312bc8c897160ab7a0.tar.bz2
podman-3be6c483c6d7ca36d16f0b312bc8c897160ab7a0.zip
Allow filtering on pod label values
Before this change, filters of the form `podman pod ps --filter label=app=myapp` were not working. The results would include all pods that contained the app label with any value. Looking at the code, this makes sense. It appears that the second = and everything after it were getting truncated. Even though there was already a passing test that tested `podman pod ps --filter label=io.podman.test.label=value1`, the test failed with the above example with a label `app=myapp`. The new code works in both cases. Signed-off-by: Jordan Christiansen <xordspar0@gmail.com>
-rw-r--r--cmd/podman/pods/ps.go2
-rw-r--r--test/e2e/pod_ps_test.go8
2 files changed, 5 insertions, 5 deletions
diff --git a/cmd/podman/pods/ps.go b/cmd/podman/pods/ps.go
index 97e528c7c..7b755cb22 100644
--- a/cmd/podman/pods/ps.go
+++ b/cmd/podman/pods/ps.go
@@ -73,7 +73,7 @@ func pods(cmd *cobra.Command, _ []string) error {
if cmd.Flag("filter").Changed {
psInput.Filters = make(map[string][]string)
for _, f := range inputFilters {
- split := strings.Split(f, "=")
+ split := strings.SplitN(f, "=", 2)
if len(split) < 2 {
return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
diff --git a/test/e2e/pod_ps_test.go b/test/e2e/pod_ps_test.go
index 602d9d577..cc096af28 100644
--- a/test/e2e/pod_ps_test.go
+++ b/test/e2e/pod_ps_test.go
@@ -212,17 +212,17 @@ var _ = Describe("Podman ps", func() {
Expect(ec).To(Equal(0))
_, ec, podid2 := podmanTest.CreatePodWithLabels("", map[string]string{
- "io.podman.test.label": "value1",
- "io.podman.test.key": "irrelevant-value",
+ "app": "myapp",
+ "io.podman.test.key": "irrelevant-value",
})
Expect(ec).To(Equal(0))
_, ec, podid3 := podmanTest.CreatePodWithLabels("", map[string]string{
- "io.podman.test.label": "value2",
+ "app": "test",
})
Expect(ec).To(Equal(0))
- session := podmanTest.Podman([]string{"pod", "ps", "--no-trunc", "--filter", "label=io.podman.test.key", "--filter", "label=io.podman.test.label=value1"})
+ session := podmanTest.Podman([]string{"pod", "ps", "--no-trunc", "--filter", "label=app", "--filter", "label=app=myapp"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(session.OutputToString()).To(Not(ContainSubstring(podid1)))