diff --git a/pkg/domain/filters/volumes.go b/pkg/domain/filters/volumes.go index 9cec39fbb1..b771115067 100644 --- a/pkg/domain/filters/volumes.go +++ b/pkg/domain/filters/volumes.go @@ -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] @@ -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 { diff --git a/test/e2e/volume_prune_test.go b/test/e2e/volume_prune_test.go index 600f1b8871..4894378db3 100644 --- a/test/e2e/volume_prune_test.go +++ b/test/e2e/volume_prune_test.go @@ -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() })