fix(webhook): enforce ResourceQuota using Status.Hard instead of Spec…#3016
fix(webhook): enforce ResourceQuota using Status.Hard instead of Spec…#3016saddamr3e wants to merge 1 commit into
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 to the Kubeflow Spark Operator! 🎉 Thanks for opening your first PR! We're happy to have you as part of our community 🚀 Here's what happens next:
Join the community:
Feel free to ask questions in the comments if you need any help or clarification! |
There was a problem hiding this comment.
Pull request overview
This PR fixes the webhook’s ResourceQuota enforcement logic to consistently use ResourceQuota.Status.Hard (the controller-reconciled enforced limit) for both resource presence checks and limit comparisons, and adds a regression test for the case where Spec.Hard and Status.Hard diverge.
Changes:
- Update
validateResourceQuotato compare againstresourceQuota.Status.Hardinstead ofresourceQuota.Spec.Hard. - Add a regression unit test covering divergent
Spec.HardvsStatus.Hardvalues to prevent reintroducing the inconsistency.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/webhook/resourcequota.go | Aligns quota comparison logic to use Status.Hard consistently. |
| internal/webhook/resourcequota_test.go | Adds regression test for Spec.Hard/Status.Hard divergence scenario. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| " Request CPU: 5\n"+ | ||
| " Status.Hard CPU: 4 (enforced limit — should be used for comparison)\n"+ | ||
| " Spec.Hard CPU: 100 (desired limit — INCORRECTLY used for comparison)\n"+ | ||
| "Root cause: line 254 of resourcequota.go compares against "+ | ||
| "resourceQuota.Spec.Hard[key] instead of resourceQuota.Status.Hard[key].", |
Signed-off-by: saddamr3e <saddamr3e@gmail.com>
dd63b4d to
a3bf9b6
Compare
|
any update? |
While reviewing the quota validation logic, I noticed that
validateResourceQuotachecks whether a resource exists inStatus.Hardbut performs the final comparison againstSpec.Hard.This change makes the validation consistent by using
Status.Hardfor both the lookup and the comparison. A regression test has also been added to cover the case whereSpec.HardandStatus.Hardcontain different values.Proposed changes:
validateResourceQuotato compare resource usage againstresourceQuota.Status.Hard.TestValidateResourceQuota_SpecHardDivergence) covering divergentSpec.HardandStatus.Hardvalues.Change Category
Bug fix (non-breaking change)
This change updates the resource quota validation logic to consistently use Status.Hard when checking resource limits and adds a regression test to verify the behavior when Spec.Hard and Status.Hard differ.
Rationale
The function already uses
Status.Hardto determine whether a resource is tracked. Using the same field for the limit comparison keeps the validation logic consistent and avoids mixing two different quota fields during the same validation.Checklist
[ ] I have conducted a self-review of my own code.
[ ] I have updated documentation accordingly.
[ ] I have added tests that prove my changes are effective.
[ ] Existing unit tests pass locally with my changes.
Additional Notes
The regression test covers the scenario where
Spec.HardandStatus.Harddiffer. Running the full webhook test suite locally requires the Kubernetes envtest binaries, which are not available in my current environment.