Skip to content

Commit

Permalink
libimage: fix reference filters
Browse files Browse the repository at this point in the history
Make sure that reference filters properly work on digests as well.
To keep things simple, try to lookup an image for the user-specified
value and compare IDs.  This will implicitly fix #containers/podman/issues/18445
and probably more (unknown) issues.

Fixes: #containers/podman/issues/18445
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Jun 14, 2023
1 parent e1ea4d9 commit 3e25180
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
12 changes: 10 additions & 2 deletions libimage/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
filter = filterManifest(ctx, manifest)

case "reference":
filter = filterReferences(value)
filter = filterReferences(r, value)

case "until":
until, err := r.until(value)
Expand Down Expand Up @@ -268,8 +268,15 @@ func filterManifest(ctx context.Context, value bool) filterFunc {
}

// filterReferences creates a reference filter for matching the specified value.
func filterReferences(value string) filterFunc {
func filterReferences(r *Runtime, value string) filterFunc {
lookedUp, _, _ := r.LookupImage(value, nil)
return func(img *Image) (bool, error) {
if lookedUp != nil {
if lookedUp.ID() == img.ID() {
return true, nil
}
}

refs, err := img.NamesReferences()
if err != nil {
return false, err
Expand Down Expand Up @@ -306,6 +313,7 @@ func filterReferences(value string) filterFunc {
}
}
}

return false, nil
}
}
Expand Down
1 change: 1 addition & 0 deletions libimage/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func TestFilterReference(t *testing.T) {
{"quay.io/libpod/*", 2},
{"busybox", 1},
{"alpine", 1},
{"alpine@"+alpine.Digest().String(), 1},
} {
listOptions := &ListImagesOptions{
Filters: []string{"reference=" + test.filter},
Expand Down

0 comments on commit 3e25180

Please sign in to comment.