Skip to content

fix(cli): improve assert fake client lookup logic - #2762

Open
FirePheonix wants to merge 1 commit into
kyverno:mainfrom
FirePheonix:fix-cli-assert-lookup
Open

fix(cli): improve assert fake client lookup logic#2762
FirePheonix wants to merge 1 commit into
kyverno:mainfrom
FirePheonix:fix-cli-assert-lookup

Conversation

@FirePheonix

Copy link
Copy Markdown

Explanation

When running the chainsaw assert CLI command using the --resource flag, the internal fake client previously hardcoded resource lookups to always return the very first element in the loaded file (ressources[0]). If a resource file contained multiple manifests, assertions targeting any resource other than the first one would receive the wrong object.

I replaced the hardcoded index access with proper resource filtering by Name, Namespace, and GroupVersionKind, returning a standard NotFound API error if the requested object is missing.

Related issue

There was the following TODO:
pkg/commands/assert/command.go : // TODO: we should improve the lookup logic here

Proposed Changes

  • Refactored GetFn in pkg/commands/assert/command.go to match objects by name, namespace, and GVK.
  • Refactored ListFn in pkg/commands/assert/command.go to filter items by namespace, GVK, and label selector.
  • Updated unit tests in pkg/commands/assert/command_test.go to cover the resourcePath fake client path.

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Signed-off-by: Shubham Singh <shubhsoch@gmail.com>
@FirePheonix
FirePheonix requested a review from a team as a code owner August 3, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant