Skip to content

Commit 9e080c1

Browse files
committed
Use AND to combine different volume filter keys
Fixes: #26786 Signed-off-by: Šimon Brauner <sbrauner@redhat.com>
1 parent 00012e3 commit 9e080c1

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

docs/source/markdown/options/filter.volume-ls.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
#### **--filter**, **-f**=*filter*
66

77
Filter what volumes are shown in the output.
8-
Multiple filters can be given with multiple uses of the --filter flag.
9-
Filters with the same key work inclusive, with the only exception being `label`
10-
which is exclusive. Filters with different keys always work exclusive.
8+
9+
The *filters* argument format is of `key=value`. If there is more than one *filter*, then pass multiple OPTIONS: **--filter** *foo=bar* **--filter** *bif=baz*.
10+
11+
Filters with different `keys` are combined with `AND`.
12+
Filters with the same `key` are combined with `OR`,
13+
with the only exceptions being `label` and `label!`,
14+
which are combined with `AND`.
1115

1216
Volumes can be filtered by the following attributes:
1317

@@ -23,3 +27,7 @@ Volumes can be filtered by the following attributes:
2327
| scope | Filters volume by scope |
2428
| after/since | Filter by volumes created after the given VOLUME (name or tag) |
2529
| until | Filter by volumes created before given timestamp |
30+
31+
The `label` *filter* accepts two formats. One is the `label`=*key* or `label`=*key*=*value*, which removes volumes with the specified labels. The other format is the `label!`=*key* or `label!`=*key*=*value*, which removes volumes without the specified labels.
32+
33+
The `until` *filter* can be Unix timestamps, date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the machine's time.

docs/source/markdown/podman-volume-prune.1.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ Provide filter values.
2727

2828
The *filters* argument format is of `key=value`. If there is more than one *filter*, then pass multiple OPTIONS: **--filter** *foo=bar* **--filter** *bif=baz*.
2929

30+
Filters with different `keys` are combined with `AND`.
31+
Filters with the same `key` are combined with `OR`,
32+
with the only exceptions being `label` and `label!`,
33+
which are combined with `AND`.
34+
3035
Supported filters:
3136

3237
| Filter | Description |

libpod/runtime_volume.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (r *Runtime) HasVolume(name string) (bool, error) {
7171
// Volumes retrieves all volumes
7272
// Filters can be provided which will determine which volumes are included in the
7373
// output. If multiple filters are used, a volume will be returned if
74-
// any of the filters are matched
74+
// all of the filters are matched
7575
func (r *Runtime) Volumes(filters ...VolumeFilter) ([]*Volume, error) {
7676
if !r.valid {
7777
return nil, define.ErrRuntimeStopped
@@ -88,9 +88,9 @@ func (r *Runtime) Volumes(filters ...VolumeFilter) ([]*Volume, error) {
8888

8989
volsFiltered := make([]*Volume, 0, len(vols))
9090
for _, vol := range vols {
91-
include := false
91+
include := true
9292
for _, filter := range filters {
93-
include = include || filter(vol)
93+
include = include && filter(vol)
9494
}
9595

9696
if include {

test/e2e/volume_ls_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,13 @@ var _ = Describe("Podman volume ls", func() {
213213
Expect(session).Should(ExitCleanly())
214214
Expect(session.OutputToStringArray()).To(HaveLen(1))
215215
Expect(session.OutputToStringArray()[0]).To(Equal(vol3Name))
216+
217+
// Filters with different keys
218+
session = podmanTest.Podman([]string{"volume", "ls", "-q", "--filter", "label=b=c", "--filter", "name=vol1"})
219+
session.WaitWithDefaultTimeout()
220+
Expect(session).Should(ExitCleanly())
221+
Expect(session.OutputToStringArray()).To(HaveLen(1))
222+
Expect(session.OutputToStringArray()[0]).To(Equal(vol1Name))
216223
})
217224

218225
It("podman ls volume with --filter since/after", func() {

0 commit comments

Comments
 (0)