[release-1.14] Update root queue capability and enhance queue validation logic - #5080
Conversation
Signed-off-by: guoqinwill <gq411will@163.com>
Signed-off-by: guoqinwill <gq411will@163.com>
Signed-off-by: guoqinwill <gq411will@163.com>
… flag enable-root-queue-protection to control if root queue can be modifeid; and fix somme comments Signed-off-by: guoqinwill <gq411will@163.com>
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 significantly enhances the robustness and configurability of queue management within the system. It introduces new safeguards to prevent accidental data loss or misconfiguration, particularly concerning queue deletion and the modification of the critical root queue. Furthermore, it refines the validation logic for hierarchical queue resource attributes and introduces a configurable depth limit, leading to a more stable and efficient scheduling environment. 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. Changelog
Activity
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.
Code Review
This pull request introduces several valuable enhancements to queue validation and management. Key changes include adding flags to control queue deletion based on allocated pods, setting a maximum depth for hierarchical queues, and protecting the root queue's resource attributes from modification. The validation logic for hierarchical resources is significantly improved, with more robust checks and clearer error messages. The implementation thoughtfully moves complex validation from CEL expressions to Go code within the webhook, which enhances maintainability. The changes are well-supported by new unit and e2e tests. I have a couple of suggestions for minor code improvements to enhance efficiency and maintainability.
Note: Security Review did not run due to the size of the PR.
| for _, sibling := range siblings { | ||
| if sibling.Name != queue.Name { | ||
| totalGuarantee.Add(api.NewResource(sibling.Spec.Guarantee.Resource)) | ||
| if parentGuarantee.LessPartly(totalGuarantee, api.Zero) { | ||
| return fmt.Errorf("parent queue %s validation failed: sum of children's guarantee (%s) exceeds parent's guarantee limit (%s)", | ||
| parent.Name, totalGuarantee, parentGuarantee) | ||
| } | ||
|
|
||
| totalDeserved.Add(api.NewResource(sibling.Spec.Deserved)) | ||
| if parentDeserved.LessPartly(totalDeserved, api.Zero) { | ||
| return fmt.Errorf("parent queue %s validation failed: sum of children's deserved (%s) exceeds parent's deserved limit (%s)", | ||
| parent.Name, totalDeserved, parentDeserved) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Add the current queue's resources | ||
| totalGuarantee.Add(api.NewResource(queue.Spec.Guarantee.Resource)) | ||
| totalDeserved.Add(api.NewResource(queue.Spec.Deserved)) | ||
|
|
||
| // Validate guarantee sum | ||
| if err := validateResourceLimit(parent, totalGuarantee, "guarantee", parent.Spec.Guarantee.Resource); err != nil { | ||
| return fmt.Errorf("parent queue %s validation failed: %v", parent.Name, err) | ||
| if parentGuarantee.LessPartly(totalGuarantee, api.Zero) { | ||
| return fmt.Errorf("parent queue %s validation failed: sum of children's guarantee (%s) exceeds parent's guarantee limit (%s)", | ||
| parent.Name, totalGuarantee, parentGuarantee) | ||
| } | ||
|
|
||
| // Validate deserved sum | ||
| if err := validateResourceLimit(parent, totalDeserved, "deserved", parent.Spec.Deserved); err != nil { | ||
| return fmt.Errorf("parent queue %s validation failed: %v", parent.Name, err) | ||
| totalDeserved.Add(api.NewResource(queue.Spec.Deserved)) | ||
| if parentDeserved.LessPartly(totalDeserved, api.Zero) { | ||
| return fmt.Errorf("parent queue %s validation failed: sum of children's deserved (%s) exceeds parent's deserved limit (%s)", | ||
| parent.Name, totalDeserved, parentDeserved) | ||
| } |
There was a problem hiding this comment.
The checks for parentGuarantee.LessPartly and parentDeserved.LessPartly are performed inside the loop over siblings, and then again after adding the current queue's resources. This can be optimized. By accumulating all sibling and current queue resources first and then performing the checks once after the loop, you can reduce redundant computations and improve readability.
for _, sibling := range siblings {
if sibling.Name != queue.Name {
totalGuarantee.Add(api.NewResource(sibling.Spec.Guarantee.Resource))
totalDeserved.Add(api.NewResource(sibling.Spec.Deserved))
}
}
// Add the current queue's resources
totalGuarantee.Add(api.NewResource(queue.Spec.Guarantee.Resource))
totalDeserved.Add(api.NewResource(queue.Spec.Deserved))
if parentGuarantee.LessPartly(totalGuarantee, api.Zero) {
return fmt.Errorf("parent queue %s validation failed: sum of children's guarantee (%s) exceeds parent's guarantee limit (%s)",
parent.Name, totalGuarantee, parentGuarantee)
}
if parentDeserved.LessPartly(totalDeserved, api.Zero) {
return fmt.Errorf("parent queue %s validation failed: sum of children's deserved (%s) exceeds parent's deserved limit (%s)",
parent.Name, totalDeserved, parentDeserved)
}| for _, child := range children { | ||
| // Accumulate children's guarantee and deserved | ||
| totalGuarantee.Add(api.NewResource(child.Spec.Guarantee.Resource)) | ||
| if parentGuarantee.LessPartly(totalGuarantee, api.Zero) { | ||
| return fmt.Errorf("queue %s validation failed: sum of children's guarantee (%s) exceeds parent's guarantee limit (%s)", | ||
| parent.Name, totalGuarantee, parentGuarantee) | ||
| } | ||
|
|
||
| // validateResourceLimit checks if children's sum exceeds parent's limit | ||
| // It checks against parent's explicit limit first, then falls back to capability | ||
| func validateResourceLimit(parent *schedulingv1beta1.Queue, childrenSum *api.Resource, | ||
| resourceType string, parentResource v1.ResourceList) error { | ||
| if len(parentResource) > 0 { | ||
| // Parent has explicit resource limit - check against it | ||
| parentLimit := api.NewResource(parentResource) | ||
| if parentLimit.LessPartly(childrenSum, api.Zero) { | ||
| return fmt.Errorf("sum of children's %s (%s) exceeds parent's %s limit (%s)", | ||
| resourceType, childrenSum, resourceType, parentLimit) | ||
| } | ||
| } else if len(parent.Spec.Capability) > 0 { | ||
| // Parent has no explicit limit but has capability - check against capability | ||
| parentCapability := api.NewResource(parent.Spec.Capability) | ||
| if parentCapability.LessPartly(childrenSum, api.Zero) { | ||
| return fmt.Errorf("sum of children's %s (%s) exceeds parent's capability (%s)", | ||
| resourceType, childrenSum, parentCapability) | ||
| totalDeserved.Add(api.NewResource(child.Spec.Deserved)) | ||
| if parentDeserved.LessPartly(totalDeserved, api.Zero) { | ||
| return fmt.Errorf("queue %s validation failed: sum of children's deserved (%s) exceeds parent's deserved limit (%s)", | ||
| parent.Name, totalDeserved, parentDeserved) | ||
| } | ||
| } |
There was a problem hiding this comment.
Similar to validateSiblingsSum, the checks for parentGuarantee.LessPartly and parentDeserved.LessPartly are inside a loop. This can be optimized by accumulating the total resources first and then performing the checks once after the loop. This improves efficiency and readability.
for _, child := range children {
// Accumulate children's guarantee and deserved
totalGuarantee.Add(api.NewResource(child.Spec.Guarantee.Resource))
totalDeserved.Add(api.NewResource(child.Spec.Deserved))
}
if parentGuarantee.LessPartly(totalGuarantee, api.Zero) {
return fmt.Errorf("queue %s validation failed: sum of children's guarantee (%s) exceeds parent's guarantee limit (%s)",
parent.Name, totalGuarantee, parentGuarantee)
}
if parentDeserved.LessPartly(totalDeserved, api.Zero) {
return fmt.Errorf("queue %s validation failed: sum of children's deserved (%s) exceeds parent's deserved limit (%s)",
parent.Name, totalDeserved, parentDeserved)
}| func contains(s, substr string) bool { | ||
| return len(s) >= len(substr) && (s == substr || len(substr) == 0 || | ||
| (len(s) > 0 && len(substr) > 0 && searchSubstring(s, substr))) | ||
| } | ||
|
|
||
| func searchSubstring(s, substr string) bool { | ||
| for i := 0; i <= len(s)-len(substr); i++ { | ||
| if s[i:i+len(substr)] == substr { | ||
| return true | ||
| } | ||
| } | ||
| return false | ||
| } |
There was a problem hiding this comment.
The helper functions contains and searchSubstring are custom implementations of strings.Contains. It's generally better to use functions from the standard library for simplicity and maintainability. You can replace the calls to contains(err.Error(), tt.errSubstr) with strings.Contains(err.Error(), tt.errSubstr) and remove these helper functions.
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: hajnalmt, JesseStutler 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 |
7bcaeed
into
volcano-sh:release-1.14
This is an automated cherry-pick of #4973