Skip to content

Commit

Permalink
Merge pull request #18689 from 89luca89/fix/filter_flags
Browse files Browse the repository at this point in the history
fix: move filter flags from StringSliceVar to StringArrayVar
  • Loading branch information
openshift-merge-robot authored May 26, 2023
2 parents e7ef259 + 5b2d963 commit 1210efc
Show file tree
Hide file tree
Showing 23 changed files with 108 additions and 17 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/containers/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func pauseFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

if registry.IsRemote() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func listFlagSet(cmd *cobra.Command) {
flags.BoolVar(&listOpts.External, "external", false, "Show containers in storage not controlled by Podman")

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

formatFlagName := "format"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func restartFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

timeFlagName := "time"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func rmFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)

filterFlagName := "filter"
flags.StringSliceVar(&filters, filterFlagName, []string{}, "Filter output based on conditions given")
flags.StringArrayVar(&filters, filterFlagName, []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

if !registry.IsRemote() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func startFlags(cmd *cobra.Command) {
flags.BoolVar(&startOptions.SigProxy, "sig-proxy", false, "Proxy received signals to the process (default true if attaching, false otherwise)")

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

flags.BoolVar(&startOptions.All, "all", false, "Start all containers regardless of their state or configuration")
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func stopFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(timeFlagName, completion.AutocompleteNone)

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

if registry.IsRemote() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/containers/unpause.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func unpauseFlags(cmd *cobra.Command) {
_ = cmd.RegisterFlagCompletionFunc(cidfileFlagName, completion.AutocompleteDefault)

filterFlagName := "filter"
flags.StringSliceVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&filters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePsFilters)

if registry.IsRemote() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func imageListFlagSet(cmd *cobra.Command) {
flags.BoolVarP(&listOptions.All, "all", "a", false, "Show all images (default hides intermediate images)")

filterFlagName := "filter"
flags.StringSliceVarP(&listOptions.Filter, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringArrayVarP(&listOptions.Filter, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteImageFilters)

formatFlagName := "format"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/images/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func searchFlags(cmd *cobra.Command) {
flags := cmd.Flags()

filterFlagName := "filter"
flags.StringSliceVarP(&searchOptions.Filters, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
flags.StringArrayVarP(&searchOptions.Filters, filterFlagName, "f", []string{}, "Filter output based on conditions provided (default [])")
_ = cmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteImageSearchFilters)

formatFlagName := "format"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/pods/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func init() {
flags.BoolVar(&psInput.CtrStatus, "ctr-status", false, "Display the container status")

filterFlagName := "filter"
flags.StringSliceVarP(&inputFilters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
flags.StringArrayVarP(&inputFilters, filterFlagName, "f", []string{}, "Filter output based on conditions given")
_ = psCmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompletePodPsFilters)

formatFlagName := "format"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/secrets/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
_ = lsCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(&entities.SecretInfoReport{}))

filterFlagName := "filter"
flags.StringSliceVarP(&listFlag.filter, filterFlagName, "f", []string{}, "Filter secret output")
flags.StringArrayVarP(&listFlag.filter, filterFlagName, "f", []string{}, "Filter secret output")
_ = lsCmd.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteSecretFilters)

noHeadingFlagName := "noheading"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/volumes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func init() {
_ = createCommand.RegisterFlagCompletionFunc(driverFlagName, completion.AutocompleteNone)

labelFlagName := "label"
flags.StringSliceVarP(&opts.Label, labelFlagName, "l", []string{}, "Set metadata for a volume (default [])")
flags.StringArrayVarP(&opts.Label, labelFlagName, "l", []string{}, "Set metadata for a volume (default [])")
_ = createCommand.RegisterFlagCompletionFunc(labelFlagName, completion.AutocompleteNone)

optFlagName := "opt"
Expand Down
2 changes: 1 addition & 1 deletion cmd/podman/volumes/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
flags := lsCommand.Flags()

filterFlagName := "filter"
flags.StringSliceVarP(&cliOpts.Filter, filterFlagName, "f", []string{}, "Filter volume output")
flags.StringArrayVarP(&cliOpts.Filter, filterFlagName, "f", []string{}, "Filter volume output")
_ = lsCommand.RegisterFlagCompletionFunc(filterFlagName, common.AutocompleteVolumeFilters)

formatFlagName := "format"
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@ LABEL "com.example.vendor"="Example Vendor"
Expect(output).To(Equal("[]"))
})

It("podman images --filter label=with,comma", func() {
dockerfile := `FROM quay.io/libpod/alpine:latest
`
podmanTest.BuildImageWithLabel(dockerfile, "foobar.com/before:latest", "false", "test=with,comma")
result := podmanTest.Podman([]string{"images", "--filter", "label=test=with,comma"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToStringArray()).To(HaveLen(2))
})

It("podman images --filter readonly", func() {
dockerfile := `FROM quay.io/libpod/alpine:latest
`
Expand Down
12 changes: 11 additions & 1 deletion test/e2e/pause_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ var _ = Describe("Podman pause", func() {
Expect(session1).Should(Exit(0))
cid2 := session1.OutputToString()

session1 = podmanTest.RunTopContainer("")
session1 = podmanTest.RunTopContainerWithArgs("", []string{"--label", "test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
cid3 := session1.OutputToString()
Expand All @@ -451,6 +451,16 @@ var _ = Describe("Podman pause", func() {
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(125))

session1 = podmanTest.Podman([]string{"pause", "-a", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"unpause", "-a", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"pause", "-a", "--filter", fmt.Sprintf("id=%swrongid", shortCid3)})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/pod_ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ var _ = Describe("Podman ps", func() {

It("podman pod ps --filter until", func() {
name := "mypod"
_, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {name}})
_, ec, _ := podmanTest.CreatePod(map[string][]string{"--name": {name}, "--label": {"test=with,comma"}})
Expect(ec).To(Equal(0))

result := podmanTest.Podman([]string{"pod", "ps", "--filter", "until=50"})
Expand All @@ -99,6 +99,11 @@ var _ = Describe("Podman ps", func() {
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring(name))

result = podmanTest.Podman([]string{"pod", "ps", "--filter", "label=test=with,comma"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring(name))
})

It("podman pod ps filter name regexp", func() {
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/ps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,26 @@ var _ = Describe("Podman ps", func() {
Expect(actual).ToNot(ContainSubstring("table"))
})

It("podman ps --filter label=test=with,comma", func() {
ctrAlpha := "first"
container := podmanTest.Podman([]string{"run", "-dt", "--label", "test=with,comma", "--name", ctrAlpha, ALPINE, "top"})
container.WaitWithDefaultTimeout()
Expect(container).Should(Exit(0))

ctrBravo := "second"
containerBravo := podmanTest.Podman([]string{"run", "-dt", "--name", ctrBravo, ALPINE, "top"})
containerBravo.WaitWithDefaultTimeout()
Expect(containerBravo).Should(Exit(0))

result := podmanTest.Podman([]string{"ps", "-a", "--format", "table {{.Names}}", "--filter", "label=test=with,comma"})
result.WaitWithDefaultTimeout()
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(0))
actual := result.OutputToString()
Expect(actual).To(ContainSubstring("first"))
Expect(actual).ToNot(ContainSubstring("table"))
})

It("podman ps namespace flag", func() {
_, ec, _ := podmanTest.RunLsContainer("")
Expect(ec).To(Equal(0))
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ var _ = Describe("Podman restart", func() {
Expect(session1).Should(Exit(0))
cid2 := session1.OutputToString()

session1 = podmanTest.RunTopContainer("")
session1 = podmanTest.RunTopContainerWithArgs("", []string{"--label", "test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
cid3 := session1.OutputToString()
Expand All @@ -331,6 +331,11 @@ var _ = Describe("Podman restart", func() {
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"restart", "-a", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"restart", "-f", fmt.Sprintf("id=%s", cid2)})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/rm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ var _ = Describe("Podman rm", func() {
cid3 := session1.OutputToString()
shortCid3 := cid3[0:5]

session1 = podmanTest.RunTopContainerWithArgs("test4", []string{"--label", "test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
cid4 := session1.OutputToString()

session1 = podmanTest.Podman([]string{"rm", cid1, "-f", "--filter", "status=running"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(125))
Expand All @@ -311,5 +316,10 @@ var _ = Describe("Podman rm", func() {
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid2))

session1 = podmanTest.Podman([]string{"rm", "-f", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid4))
})
})
2 changes: 1 addition & 1 deletion test/e2e/secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ var _ = Describe("Podman secret", func() {
Expect(list.OutputToStringArray()).To(HaveLen(2))
Expect(list.OutputToStringArray()[1]).To(ContainSubstring(secrID2))

list = podmanTest.Podman([]string{"secret", "ls", "--filter", fmt.Sprintf("name=%s,name=%s", secret1, secret2)})
list = podmanTest.Podman([]string{"secret", "ls", "--filter", fmt.Sprintf("name=%s", secret1), "--filter", fmt.Sprintf("name=%s", secret2)})
list.WaitWithDefaultTimeout()
Expect(list).Should(Exit(0))
Expect(list.OutputToStringArray()).To(HaveLen(3))
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/start_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ var _ = Describe("Podman start", func() {
cid3 := session1.OutputToString()
shortCid3 := cid3[0:5]

session1 = podmanTest.Podman([]string{"container", "create", "--label", "test=with,comma", ALPINE})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
cid4 := session1.OutputToString()

session1 = podmanTest.Podman([]string{"start", cid1, "-f", "status=running"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand All @@ -223,6 +228,11 @@ var _ = Describe("Podman start", func() {
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"start", "--all", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid4))

session1 = podmanTest.Podman([]string{"start", "-f", fmt.Sprintf("id=%s", cid2)})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand Down
10 changes: 10 additions & 0 deletions test/e2e/stop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ var _ = Describe("Podman stop", func() {
cid3 := session1.OutputToString()
shortCid3 := cid3[0:5]

session1 = podmanTest.Podman([]string{"container", "create", "--label", "test=with,comma", ALPINE})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
cid4 := session1.OutputToString()

session1 = podmanTest.Podman([]string{"start", "--all"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand All @@ -400,6 +405,11 @@ var _ = Describe("Podman stop", func() {
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid3))

session1 = podmanTest.Podman([]string{"stop", "-a", "--filter", "label=test=with,comma"})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expect(session1.OutputToString()).To(BeEquivalentTo(cid4))

session1 = podmanTest.Podman([]string{"stop", "-f", fmt.Sprintf("id=%s", cid2)})
session1.WaitWithDefaultTimeout()
Expect(session1).Should(Exit(0))
Expand Down
11 changes: 11 additions & 0 deletions test/e2e/volume_ls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ var _ = Describe("Podman volume ls", func() {
Expect(session.OutputToStringArray()).To(HaveLen(2))
})

It("podman ls volume filter with comma label", func() {
session := podmanTest.Podman([]string{"volume", "create", "--label", "test=with,comma", "myvol3"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))

session = podmanTest.Podman([]string{"volume", "ls", "--filter", "label=test=with,comma"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToStringArray()).To(HaveLen(2))
})

It("podman ls volume filter with a key pattern", func() {
session := podmanTest.Podman([]string{"volume", "create", "--label", "helloworld=world", "myvol2"})
session.WaitWithDefaultTimeout()
Expand Down

0 comments on commit 1210efc

Please sign in to comment.