docs(cli): add offline mock and cross-resource testing#1979
Merged
realshuting merged 11 commits intoMay 29, 2026
Merged
Conversation
Document in-memory fake client for offline context evaluation and HTTP mocks Signed-off-by: SargamPuram <sargampuram3@gmail.com>
|
Thanks for opening your first Pull Request here! Please check out our Contributing guidelines and confirm that you Signed off. |
…mocking
Documents the new kubernetesResource-backed GlobalContextEntry mocking
capabilities added in kyverno#16123:
- Extends the Test File Structure schema to show all three mutually
exclusive data sources: data, resources, and resourceFiles
- Updates the test declaration description (item 9) to mention all
three options and explain the []interface{} cache shape equivalence
- Updates the schema overview block in the offline mocking section with
all three options (data shown active, resources/resourceFiles commented)
- Adds a Mutual Exclusivity callout note explaining when to use each
- Adds two new subsections with complete end-to-end examples:
* Inline resources: full kyverno-test.yaml embedding Deployment
manifests directly, tested against both v1 ClusterPolicy (JMESPath
globalReference) and CEL ValidatingPolicy (globalContext.Get)
* External resource files: same scenario using resourceFiles pointing
to a gce-deployments.yaml multi-document YAML file, with a tip note
on when to prefer files over inline resources
All examples are sourced from the canonical CLI test fixtures:
test/cli/test/mock-gce-inline-resource/
test/cli/test/mock-gce-resource-files/
Signed-off-by: SargamPuram <sargampuram3@gmail.com>
881e50a to
4c879ef
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Kyverno CLI documentation to describe newly added offline evaluation capabilities and test-time mocking features for kyverno apply and kyverno test, focusing on cross-resource context resolution and HTTP/global context mocking.
Changes:
- Document offline cross-resource
context.apiCallevaluation using an in-memory client when--resourceis provided without--cluster. - Extend
kyverno-test.yamldocumentation to includeapiCallResponsesandglobalContextEntriesfor offline mocking. - Add end-to-end examples for mocking CEL
http.Get()/http.Post(),context.apiCall, and GlobalContextEntry-backed context usage.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
@SargamPuram - can you please address Copolit comments? |
Signed-off-by: SargamPuram <sargampuram3@gmail.com>
auto-merge was automatically disabled
May 26, 2026 15:42
Head branch was pushed to by a user without write access
Contributor
Author
|
Hi @realshuting , I've addressed all the Copilot comments. Please have a look now! |
Signed-off-by: SargamPuram <sargampuram3@gmail.com>
Signed-off-by: SargamPuram <sargampuram3@gmail.com>
realshuting
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Document in-memory fake client for offline context evaluation and HTTP mocks
Related issue
This documentation PR corresponds to and documents the following CLI feature PRs :
Proposed Changes
This PR documents the new local offline validation and mock-testing capabilities added to the Kyverno CLI (
kyverno applyandkyverno test). Specifically, it introduces:apply, outlining how the CLI builds an in-memory client automatically when--resourceis given without--cluster. It includes examples for GET, LIST (PDB pattern), andGlobalContextEntry.test, outlining the newapiCallResponsesandglobalContextEntriesfields mapped inkyverno-test.yaml. Includes clear examples for mocking CELhttp.Get(), standardcontext.apiCalls, and validating raw JSON schemas inline.Test File Structuresschema block to reflect the new API mock mappings.Checklist