[refactor] use shared functions to reduce redundancy in the estimator pkg#7296
[refactor] use shared functions to reduce redundancy in the estimator pkg#7296XiShanYongYe-Chang wants to merge 1 commit intokarmada-io:masterfrom
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 |
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 refactors the Highlights
Changelog
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 effectively refactors the estimator package to improve code reuse and performance. Key improvements include introducing a shared MatchNode function to avoid redundant node affinity parsing within loops, and extracting duplicated logic for handling disabled plugins and calculating available node resources into helper functions (disabledResult and getNodeAvailableResource). The changes are clear and align well with the goal of reducing redundancy. I have one suggestion to further reduce duplication by creating a helper for extracting affinity and tolerations.
There was a problem hiding this comment.
Pull request overview
This PR refactors the estimator package to reuse shared node-matching and node-available-resource helpers, aiming to reduce redundant logic and avoid repeated nodeAffinity parsing during scheduling simulation.
Changes:
- Reused a shared
MatchNodehelper (now exported frompkg/estimator) across the scheduling simulator and the node resource estimator plugin. - Factored out node available-resource computation into
getNodeAvailableResourceand reused it for both replica and component-set estimation. - Consolidated the “plugin disabled” return path into a shared
disabledResult()helper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/estimator/server/framework/plugins/noderesource/noderesource.go | Refactors node filtering and available-resource calculation; adds shared disabled handling. |
| pkg/estimator/scheduling_simulator_components.go | Avoids per-node parsing by precomputing affinity/tolerations once per component; exports MatchNode. |
| pkg/estimator/scheduling_simulator_components_test.go | Updates node-matching tests to call the new exported MatchNode and precompute inputs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7296 +/- ##
==========================================
+ Coverage 42.02% 42.03% +0.01%
==========================================
Files 874 874
Lines 53551 53552 +1
==========================================
+ Hits 22503 22510 +7
+ Misses 29356 29349 -7
- Partials 1692 1693 +1
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: changzhen <changzhen5@huawei.com>
c5e98a4 to
b477b39
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request effectively refactors the estimator package to reduce code duplication and improve performance by avoiding redundant node affinity parsing. The introduction of shared functions like GetAffinityAndTolerations and MatchNode is a solid improvement. I have one suggestion to make the new getNodeAvailableResource function safer by removing a side effect, which will improve its robustness for future use.
|
/cc @zhzhuang-zju |
|
Thanks |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: