Skip to content

Fix crictl images not filtering by repository:tag#2051

Open
vigneshakaviki wants to merge 1 commit into
kubernetes-sigs:masterfrom
vigneshakaviki:fix/crictl-images-filter
Open

Fix crictl images not filtering by repository:tag#2051
vigneshakaviki wants to merge 1 commit into
kubernetes-sigs:masterfrom
vigneshakaviki:fix/crictl-images-filter

Conversation

@vigneshakaviki

Copy link
Copy Markdown

Summary

  • Add client-side image name filtering in ListImages as a fallback when the CRI runtime does not honor the ListImagesRequest filter
  • Some runtimes return all images regardless of the ImageFilter.Image spec, causing crictl images repo:tag to show unrelated images
  • The fix filters results after the CRI call, matching by RepoTags and RepoDigests

Fixes #2008

Root Cause

crictl images REPOSITORY:TAG passes the filter to the CRI runtime via ListImagesRequest.Filter.Image, but some runtimes (e.g. certain containerd configurations) ignore this filter and return all images. There was no client-side fallback filtering.

Changes

  • Added filterByName() in cmd/crictl/image.go — filters image list by matching RepoTags or RepoDigests against the user-provided name filter
  • Added matchesNameFilter() helper — handles exact repo:tag match, repo-only match (when no tag specified), and repo@digest match
  • Applied after CRI response in ListImages(), before sorting and condition filters

Test plan

  • Added 5 ginkgo test cases for filterByName: exact repo:tag, repo-only, no match, digest match, tag-specific match
  • All 31 existing tests pass
Ran 31 of 31 Specs in 0.002 seconds
SUCCESS! -- 31 Passed | 0 Failed | 0 Pending | 0 Skipped
  • Tested on minikube (containerd runtime):
=== Patched: filter by exact repo:tag ===
IMAGE                   TAG                 IMAGE ID            SIZE
registry.k8s.io/pause   3.10.1              cd073f4c5f6a8       736kB

=== Patched: filter by repo only ===
IMAGE                   TAG                 IMAGE ID            SIZE
registry.k8s.io/pause   3.10.1              cd073f4c5f6a8       736kB

=== Patched: filter by non-existent tag ===
IMAGE               TAG                 IMAGE ID            SIZE

=== Patched: no filter (all images) ===
IMAGE                                      TAG        IMAGE ID       SIZE
gcr.io/k8s-minikube/storage-provisioner    v5         6e38f40d628db  31.5MB
...

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: vigneshakaviki
Once this PR has been reviewed and has the lgtm label, please assign random-liu for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 14, 2026
@k8s-ci-robot

Copy link
Copy Markdown
Contributor

Welcome @vigneshakaviki!

It looks like this is your first PR to kubernetes-sigs/cri-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cri-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 14, 2026
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 22, 2026
Some CRI runtimes do not honor the ListImages image name filter,
returning all images instead of only those matching the requested
repository:tag. Add client-side filtering as a fallback to ensure
correct results regardless of runtime behavior.

The filter supports exact repo:tag matching, repo-only matching
(returns all tags for that repo), and repo@digest matching.

Fixes kubernetes-sigs#2008

Signed-off-by: vigneshakaviki <kumarvignesh295@gmail.com>
@vigneshakaviki
vigneshakaviki force-pushed the fix/crictl-images-filter branch from bd1ff23 to 561ab4b Compare June 6, 2026 01:49
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

crictl images not filtering by repository:tag

2 participants