Repository navigation
Support identifying network topology from node labels and converted i… - #4629
Conversation
|
Welcome @zhaoqi612! |
Summary of ChangesHello @zhaoqi612, 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 introduces a new feature that automates the discovery and conversion of network topology defined by Kubernetes node labels into Volcano HyperNode resources. This significantly simplifies the process for users to leverage HyperNode capabilities by eliminating the need for manual configuration and maintenance. The changes involve extending the discovery manager to support a new 'label' source, updating interfaces to include Volcano client access, and implementing the core logic for label-based topology discovery and HyperNode creation. Highlights
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 a new feature to automatically discover and create HyperNode resources from node labels, which is a great addition for usability. The implementation is comprehensive, using informers and a work queue for efficient event handling. The synchronization mechanism between the discoverer and the controller to wait for reconciliation is well-designed.
I've found a few issues, mainly in the new label discoverer implementation. There are a couple of correctness issues related to non-deterministic behavior and incorrect label checking that should be addressed. I've also included some suggestions to improve logging, error messages, and test robustness. Overall, this is a solid contribution.
| value, _ := labelMap[key] | ||
| if value == "" { | ||
| klog.V(7).Info("The label does not exist in the node") | ||
| break |
There was a problem hiding this comment.
The current logic to check for a label's presence on a node is value, _ := labelMap[key] followed by if value == "". This is incorrect because an empty string is a valid value for a Kubernetes label. This check will incorrectly skip processing for nodes that have a relevant topology label with an empty value. You should check for the existence of the label key instead.
| value, _ := labelMap[key] | |
| if value == "" { | |
| klog.V(7).Info("The label does not exist in the node") | |
| break | |
| value, exists := labelMap[key] | |
| if !exists { | |
| klog.V(7).Info("The label does not exist in the node") | |
| break | |
| } |
| if len(list) > 0 { | ||
| hyperNode := list[0] | ||
| targetName := fmt.Sprintf("hypernode-%s-tier%d", topologyTypeName, tier) | ||
| if strings.HasPrefix(hyperNode.Name, targetName) { | ||
| return hyperNode.Name, nil | ||
| } | ||
| } |
There was a problem hiding this comment.
When looking for an existing HyperNode to reuse its name, the code fetches a list of matching hypernodes but only checks the first element (list[0]). The order of items returned by the lister is not guaranteed, so if multiple HyperNodes match the label selector, which one is picked is non-deterministic. This could lead to unpredictable behavior.
To ensure deterministic behavior, you should iterate through all returned hypernodes to find one with a matching name prefix. Sorting them by name first ensures that if multiple could match, you pick one consistently.
Note: You will need to add import "sort".
if len(list) > 0 {
targetName := fmt.Sprintf("hypernode-%s-tier%d", topologyTypeName, tier)
// To ensure deterministic behavior, sort by name before iterating.
sort.Slice(list, func(i, j int) bool {
return list[i].Name < list[j].Name
})
for _, hyperNode := range list {
if strings.HasPrefix(hyperNode.Name, targetName) {
return hyperNode.Name, nil
}
}
}| // If we reached here it means the HyperNode was deleted but its final state is unrecorded. | ||
| tombstones, ok := obj.(cache.DeletedFinalStateUnknown) | ||
| if !ok { | ||
| klog.Errorf("Couldn't get object from tomstone %#v", obj) |
| klog.Errorf("unable to get hyperNodeName") | ||
| return "", errors.New("unable to get hyperNodeName") |
There was a problem hiding this comment.
The error message "unable to get hyperNodeName" is not very descriptive. It would be more helpful for debugging if it included more context, such as why it failed (e.g., after how many retries).
klog.Errorf("unable to get unique hyperNodeName after %d attempts", LoopCount)
return "", fmt.Errorf("unable to get unique hyperNodeName after %d attempts", LoopCount)| select { | ||
| case hyperNodes = <-outputCh: | ||
| } |
There was a problem hiding this comment.
The test waits for results on outputCh without a timeout. If the channel never receives data for some reason, the test will hang indefinitely. It's good practice to add a timeout to prevent this.
| select { | |
| case hyperNodes = <-outputCh: | |
| } | |
| select { | |
| case hyperNodes = <-outputCh: | |
| case <-time.After(5 * time.Second): | |
| t.Fatal("timed out waiting for hypernodes") | |
| } |
8c0d234 to
1355c3f
Compare
|
/ok-to-test |
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for automatically creating and maintaining HyperNode resources based on node labels configuration, introducing a new "label" discoverer alongside the existing UFM discoverer. This enables users to define network topology hierarchies through node labels without manually creating HyperNode resources.
Key changes:
- Implements a new label-based topology discoverer that watches node labels and creates corresponding HyperNode resources
- Extends the discovery framework to support multiple discoverer types with a notification mechanism for result processing
- Updates the API interface to include a
ResultSynced()method for coordinating between discovery results and their processing
Reviewed Changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/controllers/hypernode/api/interface.go | Extends Discoverer interface with ResultSynced method and updates constructor signature |
| pkg/controllers/hypernode/discovery/manager.go | Adds ResultSynced method and vcClient parameter to manager |
| pkg/controllers/hypernode/discovery/label/label.go | New label discoverer implementation with node watching and HyperNode generation |
| pkg/controllers/hypernode/discovery/label/label_test.go | Comprehensive test cases for label discoverer functionality |
| pkg/controllers/hypernode/hypernode_controller.go | Integrates ResultSynced notification in controller |
| pkg/controllers/hypernode/discovery/ufm/ufm.go | Updates UFM discoverer to match new interface |
| installer/helm/chart/volcano/values.yaml | Updates documentation comment and adds label discoverer example |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| }, | ||
| }, map[string]string{api.NetworkTopologySourceLabelKey: "label", | ||
| "volcano.sh_torA2-1": "s3"}), | ||
| "hypernode-topologya2-tier2-7hslk": buildHyperNode("hypernode-topologya2-tier2", 2, |
There was a problem hiding this comment.
The hypernode name in the map key ('hypernode-topologya2-tier2-7hslk') doesn't match the name passed to buildHyperNode ('hypernode-topologya2-tier2'). This inconsistency could cause test failures or incorrect assertions.
| "hypernode-topologya2-tier2-7hslk": buildHyperNode("hypernode-topologya2-tier2", 2, | |
| "hypernode-topologya2-tier2-7hslk": buildHyperNode("hypernode-topologya2-tier2-7hslk", 2, |
| }, | ||
| }, map[string]string{api.NetworkTopologySourceLabelKey: "label", | ||
| "volcano.sh/torA2-2": "s4"}), | ||
| "hypernode-topologya2-tier2-zmonf": buildHyperNode("hypernode-topologya2-tier2", 2, |
There was a problem hiding this comment.
The hypernode name in the map key ('hypernode-topologya2-tier2-zmonf') doesn't match the name passed to buildHyperNode ('hypernode-topologya2-tier2'). This inconsistency could cause test failures or incorrect assertions.
| "hypernode-topologya2-tier2-zmonf": buildHyperNode("hypernode-topologya2-tier2", 2, | |
| "hypernode-topologya2-tier2-zmonf": buildHyperNode("hypernode-topologya2-tier2-zmonf", 2, |
| }, | ||
| }, map[string]string{api.NetworkTopologySourceLabelKey: "label", | ||
| "volcano.sh_torA2-1": "s1"}), | ||
| "hypernode-topologya2-tier2-fanfn": buildHyperNode("hypernode-topologya2-tier2-fanfn", 2, |
There was a problem hiding this comment.
The member selector references 'hn-topologya2-s0' but this name format doesn't match the expected hypernode naming pattern used elsewhere in the tests. This could cause incorrect member references.
| if len(list) > 0 { | ||
| targetName := fmt.Sprintf("hypernode-%s-tier%d", topologyTypeName, tier) | ||
| // To ensure deterministic behavior, sort by name before iterating. | ||
| sort.Slice(list, func(i, j int) bool { | ||
| return list[i].Name < list[j].Name | ||
| }) | ||
| for _, hyperNode := range list { | ||
| if strings.HasPrefix(hyperNode.Name, targetName) { | ||
| return hyperNode.Name, nil | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
[nitpick] This logic returns the first hypernode found with the target prefix, but there's no guarantee this is the correct one if multiple hypernodes share the same prefix. Consider using more specific matching criteria or documenting the expected behavior when multiple matches exist.
There was a problem hiding this comment.
Here, hypernodes are searched for precisely through their labels, and multiple hypernodes will not appear.
03b1df0 to
eb78555
Compare
|
Please also add the user guide for label convertion in |
|
|
||
| // NewUFMDiscoverer creates a new UFM topology discoverer | ||
| func NewUFMDiscoverer(cfg api.DiscoveryConfig, kubeClient clientset.Interface) api.Discoverer { | ||
| func NewUFMDiscoverer(cfg api.DiscoveryConfig, kubeClient clientset.Interface, vcClient vcclientset.Interface) api.Discoverer { |
There was a problem hiding this comment.
vcClient is added but not used.
There was a problem hiding this comment.
The label and UFM share a single constructor interface. When the label constructs an object by passing the vcClient parameter, the interface change requires UFM to also accept the vcClient parameter.
| api.RegisterDiscoverer("label", NewLabelDiscoverer) | ||
| } | ||
|
|
||
| // NodeLabel |
| NodeLabel string `mapstructure:"nodeLabel"` | ||
| } | ||
|
|
||
| // NetworkTopologyType |
| NetworkTopologyTypes map[string][]NodeLabel `mapstructure:"networkTopologyTypes"` | ||
| } | ||
|
|
||
| type HyperNodeInfo struct { |
| } | ||
|
|
||
| // NetworkTopologyType | ||
| type NetworkTopologyType struct { |
|
|
||
| stopCh := make(chan struct{}) | ||
| completedCh := make(chan struct{}) | ||
| informerFactory := informers.NewSharedInformerFactory(kubeClient, 0) |
There was a problem hiding this comment.
Why not just reuse the informer initialized in Hypernode controller?
There was a problem hiding this comment.
The current test has been verified and passed. The optimization changes you proposed involve significant modifications, so I will create a separate PR later to make the adjustments.
| continue | ||
| } | ||
| networkTopologyRecord[name] = make([]string, 0) | ||
| for i := len(labels) - 2; i >= 0; i-- { |
There was a problem hiding this comment.
Please give a comment for the magic number 2.
There was a problem hiding this comment.
The review comments have been revised.
|
|
||
| // parseCfg Parse the ConfigMap and read the topology information. | ||
| func parseCfg(cfg api.DiscoveryConfig) map[string][]string { | ||
| klog.InfoS("start parseCfg") |
There was a problem hiding this comment.
| klog.InfoS("start parseCfg") | |
| klog.InfoS("Start parse label based hyperNode auto discovery config") |
There was a problem hiding this comment.
The review comments have been revised.
| networkTopologyRecord[name] = append(networkTopologyRecord[name], labels[i].NodeLabel) | ||
| } | ||
| } | ||
| klog.InfoS("end parseCfg", "networkTopologyRecord", networkTopologyRecord) |
There was a problem hiding this comment.
| klog.InfoS("end parseCfg", "networkTopologyRecord", networkTopologyRecord) | |
| klog.InfoS("Successfully parsed label based hyperNode auto discovery config", "networkTopologyRecord", networkTopologyRecord) |
There was a problem hiding this comment.
The review comments have been revised.
| } | ||
|
|
||
| // parseCfg Parse the ConfigMap and read the topology information. | ||
| func parseCfg(cfg api.DiscoveryConfig) map[string][]string { |
There was a problem hiding this comment.
Seems label doesn't support hot load, but the initial Hypernode auto discovery supports hot load.
There was a problem hiding this comment.
manager.go monitors changes in the configmap, creates a new labelDiscoverer, parses the content of the config, and executes a hypernode automatic discovery. Labels support hot reloading.
| ) | ||
|
|
||
| const ( | ||
| NetworkTopologyTypeLength = 20 |
There was a problem hiding this comment.
The review comments have been revised.
| } | ||
|
|
||
| func (l *labelDiscoverer) enqueue() { | ||
| l.queue.AddAfter("update", 1000*time.Microsecond) |
There was a problem hiding this comment.
Why delay here, we should add a comment.
There was a problem hiding this comment.
Each call triggers a full discovery process, so rate limiting is needed to prevent excessive API pressure caused by frequent calls. Added comments
|
Please also add label example in |
| for i, key := range labelKey { | ||
| value, exists := labelMap[key] | ||
| if !exists { | ||
| klog.V(7).Info("The label does not exist in the node") |
There was a problem hiding this comment.
The review comments have been revised.
| } | ||
|
|
||
| func (l *labelDiscoverer) discovery() error { | ||
| klog.InfoS("start discovery hyperNode") |
There was a problem hiding this comment.
| klog.InfoS("start discovery hyperNode") | |
| klog.InfoS("Started label based hyperNode auto discovery") |
There was a problem hiding this comment.
The review comments have been revised.
| // Send discovered nodes through the channel | ||
| l.outputCh <- hyperNodes | ||
|
|
||
| klog.InfoS("end discovery hyperNode") |
There was a problem hiding this comment.
| klog.InfoS("end discovery hyperNode") | |
| klog.InfoS("End label based hyperNode auto discovery") |
There was a problem hiding this comment.
The review comments have been revised.
| } | ||
| } | ||
| hyperNodeInfo := hyperNodeInfoMap[hyperNodeName] | ||
| hyperNodeInfo.members = append(hyperNodeInfo.members, memberName) |
There was a problem hiding this comment.
The member name is the physical node name, seems only leaf hyernode is built, when non-leaf hypernode is built?
There was a problem hiding this comment.
When constructing hypernode information, the tier where the label is located will be automatically identified based on the defined configmap. If the tier equals 1 (i.e., a leaf node), the memberType will be set to Node; otherwise (i.e., a non-leaf node), the memberType will be set to HyperNode.
eb78555 to
2190f24
Compare
…nto hyperNode resources Signed-off-by: zhaoqi <342622945@qq.com>
2190f24 to
3346a39
Compare
|
/approved @Monokaix |
|
Need to submit another pr to fix sharedinformer issue. |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Monokaix 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 |
| go.uber.org/multierr v1.11.0 // indirect | ||
| go.uber.org/zap v1.27.0 // indirect | ||
| golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect | ||
| golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 |
There was a problem hiding this comment.
Why is there an indirect delete here? Was it an accident?
There was a problem hiding this comment.
The Licenses Lint / Licenses Lint (pull_request) check requires that if no modifications are made, the check will report an error.
What type of PR is this?
/kind feature
What this PR does / why we need it:
This feature can automatically identify and convert the network topology in node labels into hyperNode resources, thereby reducing the cost for users to utilize the HyperNode functionality.
Which issue(s) this PR fixes:
Fixes #4145
Special notes for your reviewer:
Does this PR introduce a user-facing change?