Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use logical AND on chained label! filters #20280

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/domain/filters/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ func GeneratePruneContainerFilterFuncs(filter string, filterValues []string, r *
}, nil
case "label!":
return func(c *libpod.Container) bool {
return !filters.MatchLabelFilters(filterValues, c.Labels())
return filters.MatchNegatedLabelFilters(filterValues, c.Labels())
}, nil
case "until":
return prepareUntilFilterFunc(filterValues)
Expand Down
4 changes: 2 additions & 2 deletions pkg/domain/filters/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func GenerateVolumeFilters(filter string, filterValues []string, runtime *libpod
}, nil
case "label!":
return func(v *libpod.Volume) bool {
return !filters.MatchLabelFilters(filterValues, v.Labels())
return filters.MatchNegatedLabelFilters(filterValues, v.Labels())
}, nil
case "opt":
return func(v *libpod.Volume) bool {
Expand Down Expand Up @@ -111,7 +111,7 @@ func GeneratePruneVolumeFilters(filter string, filterValues []string, runtime *l
}, nil
case "label!":
return func(v *libpod.Volume) bool {
return !filters.MatchLabelFilters(filterValues, v.Labels())
return filters.MatchNegatedLabelFilters(filterValues, v.Labels())
}, nil
case "until":
return createUntilFilterVolumeFunction(filterValues)
Expand Down
45 changes: 45 additions & 0 deletions test/e2e/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,4 +744,49 @@ var _ = Describe("Podman network", func() {
Expect(listAgain.OutputToStringArray()).Should(ContainElement(net2))
Expect(listAgain.OutputToStringArray()).Should(ContainElement("podman"))
})

It("podman network prune with chained label!", func() {
useCustomNetworkDir(podmanTest, tempdir)
net := "macvlan" + stringid.GenerateRandomID()
net1 := net + "1"
net2 := net + "2"
net3 := net + "3"
nc := podmanTest.Podman([]string{"network", "create", "--label=foo", net1})
nc.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net1)
Expect(nc).Should(ExitCleanly())

nc2 := podmanTest.Podman([]string{"network", "create", "--label=bar", net2})
nc2.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net2)
Expect(nc2).Should(ExitCleanly())

nc3 := podmanTest.Podman([]string{"network", "create", "--label=foobar", net3})
nc3.WaitWithDefaultTimeout()
defer podmanTest.removeNetwork(net3)
Expect(nc3).Should(ExitCleanly())

list := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
list.WaitWithDefaultTimeout()
Expect(list.OutputToStringArray()).Should(HaveLen(4))

Expect(list.OutputToStringArray()).Should(ContainElement(net1))
Expect(list.OutputToStringArray()).Should(ContainElement(net2))
Expect(list.OutputToStringArray()).Should(ContainElement(net3))
Expect(list.OutputToStringArray()).Should(ContainElement("podman"))

prune := podmanTest.Podman([]string{"network", "prune", "-f", "--filter", "label!=foo", "--filter", "label!=foobar"})
prune.WaitWithDefaultTimeout()
Expect(prune).Should(ExitCleanly())

listAgain := podmanTest.Podman([]string{"network", "ls", "--format", "{{.Name}}"})
listAgain.WaitWithDefaultTimeout()
Expect(listAgain).Should(ExitCleanly())
Expect(listAgain.OutputToStringArray()).Should(HaveLen(3))

Expect(listAgain.OutputToStringArray()).Should(ContainElement(net1))
Expect(listAgain.OutputToStringArray()).ShouldNot(ContainElement(net2))
Expect(listAgain.OutputToStringArray()).Should(ContainElement(net3))
Expect(listAgain.OutputToStringArray()).Should(ContainElement("podman"))
})
})
24 changes: 24 additions & 0 deletions test/e2e/prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,28 @@ var _ = Describe("Podman prune", func() {
Expect(err).ToNot(HaveOccurred())
Expect(dirents).To(HaveLen(3))
})

It("podman container prune with chained label!", func() {
foobar := podmanTest.Podman([]string{"create", "--label", "foobar", "--name", "foobar", ALPINE})
foobar.WaitWithDefaultTimeout()
Expect(foobar).Should(ExitCleanly())

foo := podmanTest.Podman([]string{"create", "--label", "foo", "--name", "foo", ALPINE})
foo.WaitWithDefaultTimeout()
Expect(foo).Should(ExitCleanly())

bar := podmanTest.Podman([]string{"create", "--label", "bar", "--name", "bar", ALPINE})
bar.WaitWithDefaultTimeout()
Expect(bar).Should(ExitCleanly())

Expect(podmanTest.NumberOfContainers()).To(Equal(3))

prune := podmanTest.Podman([]string{"container", "prune", "--force", "--filter", "label!=foo", "--filter", "label!=foobar"})
prune.WaitWithDefaultTimeout()
Expect(prune).Should(ExitCleanly())

Expect(podmanTest.NumberOfContainers()).To(Equal(2))
Expect(prune.OutputToStringArray()).To(HaveLen(1))
Expect(prune.OutputToString()).To(Equal(bar.OutputToString()))
})
})
30 changes: 30 additions & 0 deletions test/e2e/volume_prune_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,34 @@ var _ = Describe("Podman volume prune", func() {
Expect(session.OutputToStringArray()).To(HaveLen(1))
Expect(session.OutputToStringArray()[0]).To(Equal(vol1))
})

It("podman volume prune with chained label!", func() {
foobar := podmanTest.Podman([]string{"volume", "create", "--label", "foobar", "foobar"})
foobar.WaitWithDefaultTimeout()
Expect(foobar).Should(ExitCleanly())

foo := podmanTest.Podman([]string{"volume", "create", "--label", "foo", "foo"})
foo.WaitWithDefaultTimeout()
Expect(foo).Should(ExitCleanly())

bar := podmanTest.Podman([]string{"volume", "create", "--label", "bar", "bar"})
bar.WaitWithDefaultTimeout()
Expect(bar).Should(ExitCleanly())

ls := podmanTest.Podman([]string{"volume", "list", "-q"})
ls.WaitWithDefaultTimeout()
Expect(ls).Should(ExitCleanly())
Expect(ls.OutputToStringArray()).To(HaveLen(3))

prune := podmanTest.Podman([]string{"volume", "prune", "--force", "--filter", "label!=foo", "--filter", "label!=foobar"})
prune.WaitWithDefaultTimeout()
Expect(prune).Should(ExitCleanly())

ls = podmanTest.Podman([]string{"volume", "list", "-q"})
ls.WaitWithDefaultTimeout()
Expect(ls).Should(ExitCleanly())
Expect(ls.OutputToStringArray()).To(HaveLen(2))
Expect(prune.OutputToStringArray()).To(HaveLen(1))
Expect(prune.OutputToString()).To(Equal("bar"))
})
})