Skip to content

Commit

Permalink
Merge pull request containers#8345 from afbjorklund/volume-filter
Browse files Browse the repository at this point in the history
Add support for volume ls --filter label=key=value
  • Loading branch information
openshift-merge-robot authored Nov 15, 2020
2 parents 9fa09a8 + 0dad249 commit 3920756
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/podman/volumes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func list(cmd *cobra.Command, args []string) error {
lsOpts.Filter = make(map[string][]string)
}
for _, f := range cliOpts.Filter {
filterSplit := strings.Split(f, "=")
filterSplit := strings.SplitN(f, "=", 2)
if len(filterSplit) < 2 {
return errors.Errorf("filter input must be in the form of filter=value: %s is invalid", f)
}
lsOpts.Filter[filterSplit[0]] = append(lsOpts.Filter[filterSplit[0]], filterSplit[1:]...)
lsOpts.Filter[filterSplit[0]] = append(lsOpts.Filter[filterSplit[0]], filterSplit[1])
}
responses, err := registry.ContainerEngine().VolumeList(context.Background(), lsOpts)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-volume-ls.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ $ podman volume ls --format json
$ podman volume ls --format "{{.Driver}} {{.Scope}}"
$ podman volume ls --filter name=foo,label=blue
$ podman volume ls --filter label=key=value
```

## SEE ALSO
Expand Down
22 changes: 22 additions & 0 deletions test/e2e/volume_ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ var _ = Describe("Podman volume ls", func() {
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(2))
Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName))

session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=foo"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(0))

session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(2))
Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName))

session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=baz"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(0))
})

It("podman volume ls with --filter dangling", func() {
Expand Down Expand Up @@ -132,5 +148,11 @@ var _ = Describe("Podman volume ls", func() {
Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName))
Expect(session.OutputToStringArray()[2]).To(ContainSubstring(anotherVol))

session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=foo=bar", "--filter", "label=foo2=bar2"})
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
Expect(len(session.OutputToStringArray())).To(Equal(3))
Expect(session.OutputToStringArray()[1]).To(ContainSubstring(volName))
Expect(session.OutputToStringArray()[2]).To(ContainSubstring(anotherVol))
})
})

0 comments on commit 3920756

Please sign in to comment.