Skip to content

docs(cli): add offline mock and cross-resource testing#1979

Merged
realshuting merged 11 commits into
kyverno:mainfrom
SargamPuram:docs/get-http-mockup-and-cross-resource
May 29, 2026
Merged

docs(cli): add offline mock and cross-resource testing#1979
realshuting merged 11 commits into
kyverno:mainfrom
SargamPuram:docs/get-http-mockup-and-cross-resource

Conversation

@SargamPuram
Copy link
Copy Markdown
Contributor

@SargamPuram SargamPuram commented Apr 26, 2026

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 apply and kyverno test). Specifically, it introduces:

  1. Cross-Resource Policy Evaluation (Offline) section: Documented under apply, outlining how the CLI builds an in-memory client automatically when --resource is given without --cluster. It includes examples for GET, LIST (PDB pattern), and GlobalContextEntry.
  2. Offline HTTP Mocks and Global Context section: Documented under test, outlining the new apiCallResponses and globalContextEntries fields mapped in kyverno-test.yaml. Includes clear examples for mocking CEL http.Get(), standard context.apiCalls, and validating raw JSON schemas inline.
  3. Updated the Test File Structures schema block to reflect the new API mock mappings.
image image

Checklist

  • I have read the contributing guidelines.
  • I have inspected the website preview for accuracy.
  • I have signed off my issue.

Document in-memory fake client for offline context evaluation and HTTP mocks

Signed-off-by: SargamPuram <sargampuram3@gmail.com>
@welcome
Copy link
Copy Markdown

welcome Bot commented Apr 26, 2026

Thanks for opening your first Pull Request here! Please check out our Contributing guidelines and confirm that you Signed off.

@github-actions github-actions Bot added the documentation Improvements or additions to documentation label May 19, 2026
SargamPuram and others added 2 commits May 21, 2026 19:00
…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>
@SargamPuram SargamPuram force-pushed the docs/get-http-mockup-and-cross-resource branch from 881e50a to 4c879ef Compare May 21, 2026 18:36
@realshuting realshuting enabled auto-merge (squash) May 26, 2026 07:25
@realshuting realshuting requested a review from Copilot May 26, 2026 07:28
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.apiCall evaluation using an in-memory client when --resource is provided without --cluster.
  • Extend kyverno-test.yaml documentation to include apiCallResponses and globalContextEntries for 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.

Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
@realshuting
Copy link
Copy Markdown
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

@SargamPuram
Copy link
Copy Markdown
Contributor Author

Hi @realshuting , I've addressed all the Copilot comments. Please have a look now!

@SargamPuram SargamPuram requested a review from Copilot May 26, 2026 16:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Signed-off-by: SargamPuram <sargampuram3@gmail.com>
@SargamPuram SargamPuram requested a review from Copilot May 26, 2026 18:26
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 5 comments.

Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
Comment thread src/content/docs/docs/subprojects/kyverno-cli.mdx Outdated
@realshuting realshuting enabled auto-merge (squash) May 28, 2026 13:37
@realshuting realshuting merged commit 6d336ab into kyverno:main May 29, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants