Skip to content

Commit

Permalink
fix != filter in volume prune
Browse files Browse the repository at this point in the history
Signed-off-by: vyasgun <[email protected]>
  • Loading branch information
vyasgun committed Feb 15, 2023
1 parent f099c1f commit 33a9187
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/domain/filters/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func GenerateVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, error) {
vf = append(vf, func(v *libpod.Volume) bool {
return pruneFilters.MatchLabelFilters([]string{filter}, v.Labels())
})
case "label!":
filter := val
vf = append(vf, func(v *libpod.Volume) bool {
return !pruneFilters.MatchLabelFilters([]string{filter}, v.Labels())
})
case "opt":
filterArray := strings.SplitN(val, "=", 2)
filterKey := filterArray[0]
Expand Down Expand Up @@ -103,6 +108,11 @@ func GeneratePruneVolumeFilters(filters url.Values) ([]libpod.VolumeFilter, erro
vf = append(vf, func(v *libpod.Volume) bool {
return pruneFilters.MatchLabelFilters([]string{filterVal}, v.Labels())
})
case "label!":
filter := val
vf = append(vf, func(v *libpod.Volume) bool {
return !pruneFilters.MatchLabelFilters([]string{filter}, v.Labels())
})
case "until":
f, err := createUntilFilterVolumeFunction(filterVal)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions test/e2e/volume_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ var _ = Describe("Podman volume prune", func() {
Expect(session).Should(Exit(0))
Expect(session.OutputToStringArray()).To(HaveLen(3))

session = podmanTest.Podman([]string{"volume", "create", "--label", "testlabel", "myvol7"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"volume", "prune", "--force", "--filter", "label!=testlabel"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

podmanTest.Cleanup()
})

Expand Down

0 comments on commit 33a9187

Please sign in to comment.