Skip to content

Commit

Permalink
Fix image filters parsing
Browse files Browse the repository at this point in the history
Fix the image filter parsing in the common libraries
to follow an AND logic for all filters passed in ensuring
compatibility with Docker behavior.
Also fix the filter parsing on the tunnel side so that we grab
all the filters given by the user and not only the last filter
in the list.
Add tests for the fixes.

Signed-off-by: Urvashi Mohnani <[email protected]>
  • Loading branch information
umohnani8 committed Jan 15, 2024
1 parent 99502b9 commit 0ff7f6b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/domain/infra/tunnel/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (ir *ImageEngine) Remove(ctx context.Context, imagesArg []string, opts enti
func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
filters := make(map[string][]string, len(opts.Filter))
for _, filter := range opts.Filter {
f := strings.Split(filter, "=")
filters[f[0]] = f[1:]
f := strings.SplitN(filter, "=", 2)
filters[f[0]] = append(filters[f[0]], f[1])
}
options := new(images.ListOptions).WithAll(opts.All).WithFilters(filters)
psImages, err := images.List(ir.ClientCtx, options)
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,53 @@ RUN > file2

})

It("podman images filter should be AND logic", func() {
dockerfile := `FROM quay.io/libpod/alpine:latest
LABEL abc=""
LABEL xyz=""
`
podmanTest.BuildImage(dockerfile, "test-abc-xyz", "true")

dockerfile2 := `FROM quay.io/libpod/alpine:latest
LABEL xyz="bar"
`
podmanTest.BuildImage(dockerfile2, "test-xyz", "true")

session := podmanTest.Podman([]string{"images", "-f", "label=xyz"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(3))
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
Expect(session.OutputToString()).To(ContainSubstring("test-xyz"))

session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring("test-xyz"))

session = podmanTest.Podman([]string{"images", "-f", "label=abc"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))

session = podmanTest.Podman([]string{"images", "-f", "label=abc", "-f", "label=xyz"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))

session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar", "-f", "label=abc"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(1))

session = podmanTest.Podman([]string{"images", "-f", "label=xyz", "-f", "reference=test-abc-xyz"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
Expect(session.OutputToStringArray()).To(HaveLen(2))
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
})

})

0 comments on commit 0ff7f6b

Please sign in to comment.