Skip to content

Commit 0ff7f6b

Browse files
committed
Fix image filters parsing
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]>
1 parent 99502b9 commit 0ff7f6b

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

pkg/domain/infra/tunnel/images.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func (ir *ImageEngine) Remove(ctx context.Context, imagesArg []string, opts enti
3737
func (ir *ImageEngine) List(ctx context.Context, opts entities.ImageListOptions) ([]*entities.ImageSummary, error) {
3838
filters := make(map[string][]string, len(opts.Filter))
3939
for _, filter := range opts.Filter {
40-
f := strings.Split(filter, "=")
41-
filters[f[0]] = f[1:]
40+
f := strings.SplitN(filter, "=", 2)
41+
filters[f[0]] = append(filters[f[0]], f[1])
4242
}
4343
options := new(images.ListOptions).WithAll(opts.All).WithFilters(filters)
4444
psImages, err := images.List(ir.ClientCtx, options)

test/e2e/images_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,53 @@ RUN > file2
496496

497497
})
498498

499+
It("podman images filter should be AND logic", func() {
500+
dockerfile := `FROM quay.io/libpod/alpine:latest
501+
LABEL abc=""
502+
LABEL xyz=""
503+
`
504+
podmanTest.BuildImage(dockerfile, "test-abc-xyz", "true")
505+
506+
dockerfile2 := `FROM quay.io/libpod/alpine:latest
507+
LABEL xyz="bar"
508+
`
509+
podmanTest.BuildImage(dockerfile2, "test-xyz", "true")
510+
511+
session := podmanTest.Podman([]string{"images", "-f", "label=xyz"})
512+
session.WaitWithDefaultTimeout()
513+
Expect(session).Should(ExitCleanly())
514+
Expect(session.OutputToStringArray()).To(HaveLen(3))
515+
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
516+
Expect(session.OutputToString()).To(ContainSubstring("test-xyz"))
517+
518+
session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar"})
519+
session.WaitWithDefaultTimeout()
520+
Expect(session).Should(ExitCleanly())
521+
Expect(session.OutputToStringArray()).To(HaveLen(2))
522+
Expect(session.OutputToString()).To(ContainSubstring("test-xyz"))
523+
524+
session = podmanTest.Podman([]string{"images", "-f", "label=abc"})
525+
session.WaitWithDefaultTimeout()
526+
Expect(session).Should(ExitCleanly())
527+
Expect(session.OutputToStringArray()).To(HaveLen(2))
528+
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
529+
530+
session = podmanTest.Podman([]string{"images", "-f", "label=abc", "-f", "label=xyz"})
531+
session.WaitWithDefaultTimeout()
532+
Expect(session).Should(ExitCleanly())
533+
Expect(session.OutputToStringArray()).To(HaveLen(2))
534+
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
535+
536+
session = podmanTest.Podman([]string{"images", "-f", "label=xyz=bar", "-f", "label=abc"})
537+
session.WaitWithDefaultTimeout()
538+
Expect(session).Should(ExitCleanly())
539+
Expect(session.OutputToStringArray()).To(HaveLen(1))
540+
541+
session = podmanTest.Podman([]string{"images", "-f", "label=xyz", "-f", "reference=test-abc-xyz"})
542+
session.WaitWithDefaultTimeout()
543+
Expect(session).Should(ExitCleanly())
544+
Expect(session.OutputToStringArray()).To(HaveLen(2))
545+
Expect(session.OutputToString()).To(ContainSubstring("test-abc-xyz"))
546+
})
547+
499548
})

0 commit comments

Comments
 (0)