-
Notifications
You must be signed in to change notification settings - Fork 1k
fix: use QuotaExceeded reason when FederatedResourceQuota is exceeded #7086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
fix: use QuotaExceeded reason when FederatedResourceQuota is exceeded #7086
Conversation
|
[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 |
|
Welcome @kajal-jotwani! It looks like this is your first PR to karmada-io/karmada 🎉 |
Summary of ChangesHello @kajal-jotwani, 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 refines the behavior of the admission webhook responsible for FederatedResourceQuota enforcement. The primary goal is to provide more precise feedback to users when resource quotas are exceeded. Instead of a general denial, the system will now explicitly indicate a 'QuotaExceeded' reason with a 403 Forbidden status, which allows for better programmatic handling and clearer error messages for users. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. 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 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 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
|
There was a problem hiding this 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 correctly fixes an issue where a generic error was returned when a FederatedResourceQuota was exceeded. The new buildDenyResponse helper function properly constructs a specific QuotaExceeded response with a 403 status code. The tests have been effectively updated to verify this new behavior, and the addition of the quotaExceededResponse test helper improves the clarity of the test cases. Overall, the changes are well-implemented and address the problem effectively.
| } | ||
|
|
||
| func buildDenyResponse(errMsg string) admission.Response { | ||
| if strings.Contains(errMsg, "FederatedResourceQuota") && strings.Contains(errMsg, "exceeded") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation for detecting a quota exceeded error relies on strings.Contains, which could be a bit brittle. Since the error message for a quota violation has a specific format starting with FederatedResourceQuota(, using strings.HasPrefix would make this check more robust and less prone to accidentally matching other error messages that might contain the substring "FederatedResourceQuota" in a different context.
| if strings.Contains(errMsg, "FederatedResourceQuota") && strings.Contains(errMsg, "exceeded") { | |
| if strings.HasPrefix(errMsg, "FederatedResourceQuota(") && strings.Contains(errMsg, "exceeded") { |
There was a problem hiding this 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 fixes the admission webhook to return the specific QuotaExceeded reason (with HTTP 403 status) when FederatedResourceQuota limits are exceeded, instead of a generic admission denied error. This ensures proper error classification for downstream components like the scheduler to handle quota exceeded scenarios appropriately.
Key Changes:
- Added
buildDenyResponsehelper function to detect quota exceeded errors and set the appropriate reason and status code - Updated test helper
quotaExceededResponseand test assertions to verify the correct reason is returned - Modified all quota exceeded test cases to use the new response helper
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/webhook/resourcebinding/validating.go | Added buildDenyResponse function to detect quota exceeded errors via string matching and return proper HTTP 403 status with QuotaExceeded reason; updated error handling to use this new function |
| pkg/webhook/resourcebinding/validating_test.go | Added quotaExceededResponse test helper function; updated all quota exceeded test cases to verify the correct status code and reason; added assertion to check the Reason field in test validation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| func buildDenyResponse(errMsg string) admission.Response { | ||
| if strings.Contains(errMsg, "FederatedResourceQuota") && strings.Contains(errMsg, "exceeded") { |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string matching approach using Contains for both "FederatedResourceQuota" and "exceeded" is fragile and could produce false positives. For example, if a future error message contains both strings in an unrelated context, it would incorrectly be treated as a quota exceeded error. Consider using a more robust approach such as: 1) Creating a custom error type for quota exceeded errors and using errors.As() to check for it, or 2) Using a specific prefix or pattern matching instead of two independent Contains checks.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7086 +/- ##
==========================================
- Coverage 46.55% 46.55% -0.01%
==========================================
Files 700 700
Lines 48091 48104 +13
==========================================
+ Hits 22389 22393 +4
- Misses 24020 24027 +7
- Partials 1682 1684 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: kajal-jotwani <[email protected]>
aa23390 to
c03efdb
Compare
RainbowMango
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/assign
|
/retest |
| } | ||
|
|
||
| func buildDenyResponse(errMsg string) admission.Response { | ||
| if strings.Contains(errMsg, "FederatedResourceQuota") && strings.Contains(errMsg, "exceeded") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zhzhuang-zju could you please help confirm if we need to match the error message here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid so. The scheduler distinguishes specific scenarios by the return code and predefined reason from the webhook. The corresponding return code for quota exceeded is 403, with the reason being QuotaExceeded. For this purpose, the corresponding return code and reason need to be set when the webhook denies a request.
karmada/pkg/scheduler/helper.go
Lines 140 to 142 in 050353e
| if errors.As(ae, &statusErr) && statusErr.Status().Code == http.StatusForbidden && statusErr.Status().Reason == util.QuotaExceededReason { | |
| return util.NewCondition(workv1alpha2.Scheduled, workv1alpha2.BindingReasonQuotaExceeded, ae.Error(), metav1.ConditionFalse), false | |
| } |
I can confirm this behavior is necessary, but I need to look over the implementation method again.
In addition, this also exposes an issue with the E2E test. At present, it only checks the status and type of the condition; other fields such as condition.reason also require attention.
| return rb != nil && meta.IsStatusConditionPresentAndEqual(rb.Status.Conditions, workv1alpha2.Scheduled, metav1.ConditionFalse) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, this also exposes an issue with the E2E test. At present, it only checks the status and type of the condition; other fields such as condition.reason also require attention.
+1
|
/assign |
What type of PR is this?
What this PR does / why we need it:
Fixes the admission webhook to return the specific QuotaExceeded reason (and 403 status) when FRQ limits are hit, instead of a generic error. Added a buildDenyResponse helper to handle this case and updated tests to verify.
Which issue(s) this PR fixes:
Fixes #7069
Special notes for your reviewer:
Does this PR introduce a user-facing change?: