Skip to content

Conversation

@Abhay349
Copy link
Contributor

@Abhay349 Abhay349 commented Jan 29, 2026

What type of PR is this?

/kind cleanup

What this PR does / why we need it:
This PR adds comprehensive test coverage for the Policy resource interpreter customization.

Specifically, it:
• Adds unit tests for AggregateStatus, InterpretStatus, and InterpretHealth
• Aligns test expectations with the actual aggregation behavior

These tests improve confidence in Kyverno Policy status handling across clusters and prevent future regressions.

Which issue(s) this PR fixes:
Fixes part of #6952

Special notes for your reviewer:
• Tests are written to strictly follow the existing Lua aggregation logic
• All cases are verified using:
go test ./pkg/resourceinterpreter/default/thirdparty

Does this PR introduce a user-facing change?:
None

@karmada-bot karmada-bot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Jan 29, 2026
@karmada-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign poor12 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

@karmada-bot karmada-bot requested a review from yike21 January 29, 2026 10:07
@karmada-bot karmada-bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 29, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello @Abhay349, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the test coverage for the Kyverno Policy resource interpreter. By introducing a comprehensive suite of unit tests for status aggregation, interpretation, and health checks, it aims to improve the reliability and robustness of Kyverno's policy status handling across different clusters. These additions ensure that future changes or updates to the interpreter logic maintain expected behavior and prevent regressions.

Highlights

  • Expanded Test Coverage: Added extensive unit tests for the Policy resource interpreter's AggregateStatus, InterpretStatus, and InterpretHealth functions.
  • AggregateStatus Enhancements: Introduced new test cases to validate AggregateStatus behavior with varying Ready reasons and nil statusItems.
  • InterpretHealth Test File: Created a dedicated test file for InterpretHealth covering scenarios like status.ready values, Ready conditions, and missing status fields.
  • InterpretStatus Refinements: Expanded InterpretStatus tests to include cases for nil status, policies with only the ready field, and policies without conditions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds comprehensive test coverage for the Kyverno Policy resource interpreter. It introduces new test files and cases for AggregateStatus, InterpretHealth, and InterpretStatus operations, ensuring the Lua-based customization logic is well-tested against various scenarios, including edge cases like nil statuses and different condition reasons. The changes are clear, correct, and significantly improve the robustness of the interpreter. Excellent work!

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.53%. Comparing base (b5a60ff) to head (0029da6).
⚠️ Report is 38 commits behind head on master.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7146      +/-   ##
==========================================
- Coverage   46.56%   46.53%   -0.03%     
==========================================
  Files         700      700              
  Lines       48103    48136      +33     
==========================================
+ Hits        22398    22399       +1     
- Misses      24025    24050      +25     
- Partials     1680     1687       +7     
Flag Coverage Δ
unittests 46.53% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@FAUST-BENCHOU
Copy link
Contributor

/assign
may takes some time

@XiShanYongYe-Chang
Copy link
Member

Fixes #6952

Hi @Abhay349, this info can be updated to:

Fixes part of #xxx

As it is currently written, when a PR is merged, the associated issue will also be closed by GitHub. This is appropriate for individual issues, but for umbrella issues, a single PR often resolves only a subset of the problems in most cases.

@FAUST-BENCHOU
Copy link
Contributor

ya we still get one pr to track

@Abhay349
Copy link
Contributor Author

Fixes #6952

Hi @Abhay349, this info can be updated to:

Fixes part of #xxx

As it is currently written, when a PR is merged, the associated issue will also be closed by GitHub. This is appropriate for individual issues, but for umbrella issues, a single PR often resolves only a subset of the problems in most cases.

@XiShanYongYe-Chang Thanks, I will this in mind from next times.

# test case for aggregating status of Policy
# case1. Policy with two status items
# case2. Policy with different Ready reasons
# case3. Policy with nil statusItems
Copy link
Contributor

Choose a reason for hiding this comment

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

conseder add a mixed test that a certain statusItem has no status or its status is empty.

verifyimages: 0
---
name: "Policy with nil status"
description: "InterprettStatus should return empty status when status is nil"
Copy link
Contributor

Choose a reason for hiding this comment

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

spell error

# test case for interpreting status of Policy
# case1. Policy: interpret status test
# case2. Policy with nil status
# case3. Policy with only ready field
Copy link
Contributor

Choose a reason for hiding this comment

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

Besides Policy with only ready field we can also add only conditions and only autogen case

status.autogen = observedObj.status.autogen
status.conditions = observedObj.status.conditions

# case1. Policy with status.ready = true
# case2. Policy with status.ready false
# case3. Policy with Ready=True and Succeeded condition
# case4. Policy with Ready=True but non-succeeded reason
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: The test case here covers "there is a Ready condition but the reason is incorrect"; consider adding a test to cover "there is no Ready condition at all" (status.conditions is not empty, but there is no type=Ready).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. 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.

5 participants