fix(device): use HasPrefix and TrimPrefix in DelQuota - #2272
Conversation
|
Welcome @SK8-infi! It looks like this is your first PR to Project-HAMi/HAMi 🎉 |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthrough
ChangesQuota validation
Estimated code review effort: 2 (Simple) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
i mean i dont see a functional behavior change here. IsManagedQuota() already appears to reject any malformed dn produced by the previous logic.
can you share a case where the old implementation behaved incorrectly? otherwise this seems more like a clean code kinda change than a bug fix
If a key has a 7 char prefix before the resource name (thake this for ex... custom.nvidia.com/gpumem), stripping offset [7:] leaves the exact valid resource name (---> nvidia.com/gpumem). IsManagedQuota accepts it and accidentally wipes out the active quota limit for that namespace. Kind of maybe considered a very remote edge case but still better to be safe...do let me know if I am overlooking something. |
|
makes sense. lgtm |
mesutoezdil
left a comment
There was a problem hiding this comment.
heads up, #2172 also touches quota.go and quota_test.go so watch for conflicts.
no ai assistance disclosure is present. if any ai tool was used, it must be disclosed per CONTRIBUTING.md: https://github.com/Project-HAMi/HAMi/blob/master/CONTRIBUTING.md#ai-assistance-notice
#2172 seems to be closed for now....so ig we are good to go
As for ai tool, will keep in mind to disclose prior next time. But was not used in this one due to minor fix. |
|
please fix the go-lint |
Signed-off-by: SK8-infi <shivansh.katiyar1712@gmail.com>
|
@archlitchi fixed the linting issue. Will take care from now on... |
for future: pls refrain from force pushing once you have started getting reviews, it makes it much harder to tell what has changed from review to review. |
Okay sure. there was this one project I was working with..they say to keep one commit. So got confused |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Shouren, SK8-infi The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Codecov Report✅ All modified and coverable lines are covered by tests.
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 6 files with indirect coverage changes 🚀 New features to boost your workflow:
|

What type of PR is this?
/kind bug
What this PR does / why we need it:
Fixes an issue in
QuotaManager.DelQuotawhere resource quota keys were not validated for the "limits." prefix before slicing.Previously, DelQuota only checked if the key length was greater than len("limits.") (7 characters) and sliced the first 7 characters. As a result, any non-limits. key longer than 7 characters whose suffix after 7 matched a managed resource (e.g., 0123456nvidia.com/gpumem) would pass IsManagedQuota and reset quotaInfo.Limit = 0, unexpectedly corrupting namespace quota limits.
This PR updates DelQuota to use strings.HasPrefix(idx.String(), "limits.") and strings.TrimPrefix(idx.String(), "limits.") to be the same as AddQuota, ensuring non-limits. keys are safely ignored.
Which issue(s) this PR fixes:
Fixes #2271
Special notes for your reviewer:
This would be me first time contributing to HAMI. If anything is out of order or I made some mistake do let me know. Thanks.
Does this PR introduce a user-facing change?:
NA
Summary by CodeRabbit