-
Notifications
You must be signed in to change notification settings - Fork 1.2k
HyperNode supports select Nodes By labels #4068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HyperNode supports select Nodes By labels #4068
Conversation
|
/assign @Monokaix |
ab01534 to
e5489c1
Compare
go.mod
Outdated
| sigs.k8s.io/yaml v1.4.0 | ||
| stathat.com/c/consistent v1.0.0 | ||
| volcano.sh/apis v1.11.0-network-topology-preview.0 | ||
| volcano.sh/apis v0.0.0-20250306023628-7264f8fe811c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version number looks a bit strange. It shouldn't start with v0.0.0. At least should start with v1.11.0-network-topology-preview, maybe ask @Monokaix how to generate it
pkg/scheduler/api/hyper_node_info.go
Outdated
| if selector.LabelMatch != nil { | ||
| labelSelector, err := metav1.LabelSelectorAsSelector(selector.LabelMatch) | ||
| if err != nil { | ||
| klog.ErrorS(err, "Failed to construct labelSelector as labelMatch", "LabelMatch", selector.LabelMatch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with the order of subject and object here. It's "Failed to convert labelMatch to labelSelector"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Done.
| if selector.RegexMatch == nil && selector.ExactMatch == nil { | ||
| err := field.Invalid(fldPath, selector, | ||
| "member selector must have one of regexMatch or exactMatch") | ||
| if memberType != hypernodev1alpha1.MemberTypeHyperNode && memberType != hypernodev1alpha1.MemberTypeNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is best to extract a function that validate memberType separately, otherwise the responsibility of the func validateHyperNodeMemberSelector does not match
| "member selector cannot have both regexMatch and exactMatch") | ||
| errs = append(errs, err) | ||
| return errs | ||
| if memberType == hypernodev1alpha1.MemberTypeHyperNode { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation using kubebuilder is not consistent with here. MemberType is also verified here. I think we should keep consistent? @Monokaix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have delete it. Just ignore it when the MemberType is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean, do we need to distinguish MemberTypeHyperNode from MemberTypeNode? Currently, our kubebuilder rules do not distinguish between them. We should keep consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at the cel validation in kubebuilder and it also supports referencing other fields. Perhaps if type validation is needed here, when memberType is HyperNode, it can only use ExactMatch. You should also update in apis repo to distinguish memberType is HyperNode and Node to keep consistent
| return errs | ||
| } | ||
| } else { | ||
| if (selector.LabelMatch != nil && (selector.RegexMatch != nil || selector.ExactMatch != nil)) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit too complext to understand, making it difficult for others to read. Esstentially, we want to verify that there can not be two or more matches. Perhaps we can use a counting method to do the same thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have modify it, you can check again.
| } | ||
| } | ||
| if selector.LabelMatch != nil { | ||
| if (selector.LabelMatch.MatchExpressions == nil || len(selector.LabelMatch.MatchExpressions) == 1) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these codes for? If matchExpressions and matchLabels are both be empty, it means matching all nodes. And we didn't add validation in kubebuilder validation format, I don't think we need these codes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can skip the verification here. Not configuring the label matching rule will match all Nodes, which seems really strange. Wouldn't it be more appropriate to match the empty nodes? @Monokaix , what's your opinion?
|
Please fix the CI :), and I think we should also add tese cases for the new webhook validation codes. |
|
Also need to execute |
|
Besides, what if node label updates? We need to handle these cases |
4707244 to
8a2319a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we generate so many new files, shouldn't only config/crd/volcano/bases/topology.volcano.sh_hypernodes.yaml change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have modified it, you can check again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also add test cases into admit_hypernode_test.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, Done
Done |
pkg/scheduler/api/hyper_node_info.go
Outdated
|
|
||
| // NodeRegexMatchLeafHyperNode checks if a given node regex matches the MemberSelector of a HyperNode. | ||
| func (hni *HyperNodesInfo) NodeRegexMatchLeafHyperNode(nodeName string, hyperNodeName string) (bool, error) { | ||
| // NodeMatchLeafHyperNode checks if a given node regex matches the MemberSelector of a HyperNode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should also be adapted and modified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok,Done
pkg/scheduler/api/hyper_node_info.go
Outdated
| return false, nil | ||
| } | ||
|
|
||
| // nodeMatchRegexSelector checks if a node matches a MemberSelector. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should also be adapted and modified
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok,done
| return | ||
| } | ||
| sc.nodeQueue.Add(newNode.Name) | ||
| if len(oldNode.GetLabels()) != len(newNode.GetLabels()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think use reflect.DeepEqual is better?
if !reflect.DeepEqual(oldNode.GetLabels(), newNode.GetLabels()) {
sc.hyperNodesQueue.Add(string(hyperNodeEventSourceNode) + "/" + newNode.Name)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, Done
| assert.NoError(t, err) | ||
| } | ||
| for _, node := range initialNodes { | ||
| // err := nodeInformer.Informer().GetIndexer().Add(node) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
delete useless comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
|
Please make CI happy :) |
abe1d3c to
f5059fa
Compare
|
/lgtm cc @Monokaix |
| continue | ||
| } | ||
| match, err := sc.HyperNodesInfo.NodeRegexMatchLeafHyperNode(name, hn.Name) | ||
| match, err := sc.HyperNodesInfo.NodeMatchLeafHyperNode(name, hn.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 726 GetRegexSelectorLeafHyperNodes should also consider label selector.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
pkg/scheduler/api/hyper_node_info.go
Outdated
| // NodeRegexMatchLeafHyperNode checks if a given node regex matches the MemberSelector of a HyperNode. | ||
| func (hni *HyperNodesInfo) NodeRegexMatchLeafHyperNode(nodeName string, hyperNodeName string) (bool, error) { | ||
| // NodeMatchLeafHyperNode checks if a given node matches the MemberSelector of a HyperNode. | ||
| func (hni *HyperNodesInfo) NodeMatchLeafHyperNode(nodeName string, hyperNodeName string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| func (hni *HyperNodesInfo) NodeMatchLeafHyperNode(nodeName string, hyperNodeName string) (bool, error) { | |
| func (hni *HyperNodesInfo) NodeRegexOrSelectorMatchLeafHyperNode(nodeName string, hyperNodeName string) (bool, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces support for selecting Nodes by labels in addition to the previously supported regex-based selection. The changes update the MemberConfig and BuildHyperNode APIs, adjust node matching logic in HyperNodesInfo, and update related tests and utilities accordingly.
- Updated test files to use the new BuildHyperNode signature with an extra LabelSelector parameter.
- Modified node update logic to trigger hyper-node events upon label changes.
- Refactored node matching functions to support both regex‐ and label-based matching.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/scheduler/cache/event_handlers_test.go | Updated BuildHyperNode calls to pass nil for the new LabelSelector parameter. |
| pkg/scheduler/cache/event_handlers.go | Extended UpdateNode to check for label changes and updated node matching to use the new NodeMatchLeafHyperNode function. |
| pkg/scheduler/api/test_utils_test.go | Adjusted BuildHyperNode calls to include the new nil parameter. |
| pkg/scheduler/api/test_utils.go | Modified BuildNode and BuildHyperNode to support a LabelSelector and added the "label" case. |
| pkg/scheduler/api/node_info_test.go | Updated BuildNode calls to account for the new BuildNode signature. |
| pkg/scheduler/api/hyper_node_info.go | Updated node matching logic to support label selectors and renamed the node matching function accordingly. |
6776c4f to
daa3d0d
Compare
|
/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
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: wangbin <[email protected]>
|
/lgtm |
074478f
into
volcano-sh:network-topology
|
In the finalized merged code, I noticed that the Is this behavior intentional? If not, I would be glad to submit a PR to update the admission webhook. |
Yeah there is no check in webhook for label selector, but the scheduler should work well. |
|
Hi, when we attempting to create a We are currently using the Helm chart version: Example YAML: apiVersion: hypernode.volcano.sh/v1alpha1
kind: HyperNode
metadata:
name: example-hypernode
spec:
members:
selector:
labelMatch:
matchLabels:
node-group: workersAdmission webhook denies the request with the following error: Looking into the webhook validation logic, it appears that support for func validateHyperNodeMemberSelector(selector hypernodev1alpha1.MemberSelector, fldPath *field.Path) field.ErrorList {
errs := field.ErrorList{}
if selector.RegexMatch == nil && selector.ExactMatch == nil {
err := field.Invalid(fldPath, selector,
"member selector must have one of regexMatch or exactMatch")
errs = append(errs, err)
return errs
}
}This validation does not account for the presence of |
Please feel free to fix it. |
What this PR does / why we need it:
HyperNode supports select Nodes By labels.
Which issue(s) this PR fixes:
#4007