Test(webhook): add verify empty placement does not panic in propagation policies#7640
Test(webhook): add verify empty placement does not panic in propagation policies#7640Priyanshu8023 wants to merge 1 commit into
Conversation
Summary of ChangesHello, 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 introduces regression tests for the mutating webhooks associated with propagation policies. The goal is to ensure that the system remains stable when the optional spec.placement field is omitted, preventing potential panics during the admission process. These changes document and protect the expected behavior for both namespaced and cluster-scoped policies. Highlights
Using Gemini Code AssistThe 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
Customization To customize the 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. 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. Footnotes
|
|
Welcome @Priyanshu8023! It looks like this is your first PR to karmada-io/karmada 🎉 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
Code Review
This pull request introduces new unit tests to verify the behavior of mutating admission webhooks when handling empty placement specifications. Specifically, it adds TestMutatingAdmission_Handle_EmptyPlacement to both pkg/webhook/clusterpropagationpolicy/mutating_test.go and pkg/webhook/propagationpolicy/mutating_test.go to ensure that both cluster-scoped and namespaced propagation policies with an empty Spec.Placement are correctly allowed and processed by the mutating handlers. I have no feedback to provide as there are no review comments and the changes are well-implemented.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
Adds regression coverage for the PropagationPolicy and ClusterPropagationPolicy mutating webhooks to ensure they don’t panic when spec.placement is omitted (decoded as an empty Placement value), documenting the expected behavior without changing production webhook logic.
Changes:
- Add a new mutating-webhook unit test for namespaced
PropagationPolicywhenspec.placementis missing. - Add a new mutating-webhook unit test for cluster-scoped
ClusterPropagationPolicywhenspec.placementis missing.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/webhook/propagationpolicy/mutating_test.go | Adds a regression test covering omitted spec.placement for namespaced propagation policies. |
| pkg/webhook/clusterpropagationpolicy/mutating_test.go | Adds a regression test covering omitted spec.placement for cluster-scoped propagation policies. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Spec: policyv1alpha1.PropagationSpec{ | ||
| // Keep the selector namespace empty so the webhook can default it. | ||
| ResourceSelectors: []policyv1alpha1.ResourceSelector{ | ||
| {Namespace: ""}, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
fixed the issue in the commit
| Spec: policyv1alpha1.PropagationSpec{ | ||
| // Keep a minimal selector so the test focuses on placement handling. | ||
| ResourceSelectors: []policyv1alpha1.ResourceSelector{ | ||
| {}, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
fixed the issue in the commit
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7640 +/- ##
==========================================
+ Coverage 42.04% 42.06% +0.01%
==========================================
Files 879 879
Lines 54827 54827
==========================================
+ Hits 23053 23061 +8
+ Misses 30027 30021 -6
+ Partials 1747 1745 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…utating webhooks Signed-off-by: Priyanshu8023 <priyanshukumar8023@gmail.com>
7d7eb87 to
19f4dc0
Compare
| // Empty placement is valid and should not block admission. | ||
| got := mutatingHandler.Handle(context.Background(), req) | ||
| if !got.Allowed { | ||
| t.Errorf("Handle() got.Allowed = false, want true") | ||
| } |
There was a problem hiding this comment.
What is expected is that the request could be allowed. Why do you think this is a bug? @Priyanshu8023
What type of PR is this?
/kind bug
What this PR does / why we need it:
These PRs provide regression test cases for the
PropagationPolicyandClusterPropagationPolicymutating webhooks in casespec.placementis missing.spec.placementis an optional field with value type, and therefore, if it is not provided, it is decoded into an emptyPlacementvalue. These new test cases illustrate such behavior.Which issue(s) this PR fixes:
Fixes #7638
Special notes for your reviewer:
The reported panic scenario assumes
spec.placementis a pointer. In the current API,PropagationSpec.Placementis a value field:Because of that, omitting
spec.placementdecodes to an emptyPlacementvalue, notnil. This PR keeps the production webhook logic unchanged and adds focused tests to document and protect the expected behavior for both namespaced and cluster-scoped propagation policies.Tested with:
Does this PR introduce a user-facing change?:
NONE