Skip to content

Commit 31fef6b

Browse files
committed
HyperNode supports select Nodes By labels
Signed-off-by: wangbin <[email protected]>
1 parent 1d69621 commit 31fef6b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

docs/design/Network Topology Aware Scheduling.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,16 +458,20 @@ type MemberSpec struct {
458458
// regexMatch:
459459
// pattern: "^node-[0-9]+$"
460460
//
461-
// +kubebuilder:validation:XValidation:rule="self.exactMatch != null || self.regexMatch != null",message="Either ExactMatch or RegexMatch must be specified"
462-
// +kubebuilder:validation:XValidation:rule="!(self.exactMatch != null && self.regexMatch != null)",message="ExactMatch and RegexMatch cannot be specified together"
461+
// +kubebuilder:validation:XValidation:rule="has(self.exactMatch) || has(self.regexMatch) || has(self.LabelMatch)",message="Either ExactMatch or RegexMatch or LabelMatch must be specified"
462+
// +kubebuilder:validation:XValidation:rule="!(has(self.exactMatch) && has(self.regexMatch) && has(self.LabelMatch))",message="ExactMatch and RegexMatch and LabelMatch cannot be specified together"
463463
type MemberSelector struct {
464-
// ExactMatch defines the exact match criteria (required when Type is "Exact").
464+
// ExactMatch defines the exact match criteria.
465465
// +optional
466466
ExactMatch *ExactMatch `json:"exactMatch,omitempty"`
467467

468-
// RegexMatch defines the regex match criteria (required when Type is "Regex").
468+
// RegexMatch defines the regex match criteria.
469469
// +optional
470470
RegexMatch *RegexMatch `json:"regexMatch,omitempty"`
471+
472+
// LabelMatch defines the labels match criteria (only take effect when Member Type is "Node").
473+
// +optional
474+
LabelMatch *metav1.LabelSelector `json:"labelMatch,omitempty"`
471475
}
472476

473477
// ExactMatch represents the criteria for exact name matching.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ require (
4646
sigs.k8s.io/controller-runtime v0.13.0
4747
sigs.k8s.io/yaml v1.4.0
4848
stathat.com/c/consistent v1.0.0
49-
volcano.sh/apis v1.11.0-network-topology-preview.0
49+
volcano.sh/apis v0.0.0-20250306023628-7264f8fe811c
5050
)
5151

5252
require (

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,5 +510,5 @@ sigs.k8s.io/yaml v1.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
510510
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
511511
stathat.com/c/consistent v1.0.0 h1:ezyc51EGcRPJUxfHGSgJjWzJdj3NiMU9pNfLNGiXV0c=
512512
stathat.com/c/consistent v1.0.0/go.mod h1:QkzMWzcbB+yQBL2AttO6sgsQS/JSTapcDISJalmCDS0=
513-
volcano.sh/apis v1.11.0-network-topology-preview.0 h1:lUdLoNxgXks/yD5Q5xAkKF4dojSPuuyg2YwxpiXRIVU=
514-
volcano.sh/apis v1.11.0-network-topology-preview.0/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=
513+
volcano.sh/apis v0.0.0-20250306023628-7264f8fe811c h1:7asOFV/P5TV8kJaf7A/nHx7K2ZGrhQPdgye1V8aIWsk=
514+
volcano.sh/apis v0.0.0-20250306023628-7264f8fe811c/go.mod h1:FOdmG++9+8lgENJ9XXDh+O3Jcb9YVRnlMSpgIh3NSVI=

pkg/scheduler/api/hyper_node_info.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,19 @@ func (hni *HyperNodesInfo) getMembers(selector topologyv1alpha1.MemberSelector,
447447
}
448448
}
449449
}
450+
if selector.LabelMatch != nil {
451+
labelSelector, err := metav1.LabelSelectorAsSelector(selector.LabelMatch)
452+
if err != nil {
453+
klog.ErrorS(err, "Failed to construct labelSelector as labelMatch", "LabelMatch", selector.LabelMatch)
454+
return sets.Set[string]{}
455+
}
456+
for _, node := range nodes {
457+
nodeLabels := labels.Set(node.Labels)
458+
if labelSelector.Matches(nodeLabels) {
459+
members.Insert(node.Name)
460+
}
461+
}
462+
}
450463
return members
451464
}
452465

0 commit comments

Comments
 (0)