Skip to content

Commit 4707244

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

File tree

8 files changed

+446
-33
lines changed

8 files changed

+446
-33
lines changed

config/crd/volcano/bases/topology.volcano.sh_hypernodes.yaml

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,62 @@ spec:
6363
description: Selector defines the selection rules for this member.
6464
properties:
6565
exactMatch:
66-
description: ExactMatch defines the exact match criteria
67-
(required when Type is "Exact").
66+
description: ExactMatch defines the exact match criteria.
6867
properties:
6968
name:
7069
description: Name specifies the exact name of the node
7170
to match.
7271
type: string
7372
type: object
73+
labelMatch:
74+
description: LabelMatch defines the labels match criteria
75+
(only take effect when Member Type is "Node").
76+
properties:
77+
matchExpressions:
78+
description: matchExpressions is a list of label selector
79+
requirements. The requirements are ANDed.
80+
items:
81+
description: |-
82+
A label selector requirement is a selector that contains values, a key, and an operator that
83+
relates the key and values.
84+
properties:
85+
key:
86+
description: key is the label key that the selector
87+
applies to.
88+
type: string
89+
operator:
90+
description: |-
91+
operator represents a key's relationship to a set of values.
92+
Valid operators are In, NotIn, Exists and DoesNotExist.
93+
type: string
94+
values:
95+
description: |-
96+
values is an array of string values. If the operator is In or NotIn,
97+
the values array must be non-empty. If the operator is Exists or DoesNotExist,
98+
the values array must be empty. This array is replaced during a strategic
99+
merge patch.
100+
items:
101+
type: string
102+
type: array
103+
x-kubernetes-list-type: atomic
104+
required:
105+
- key
106+
- operator
107+
type: object
108+
type: array
109+
x-kubernetes-list-type: atomic
110+
matchLabels:
111+
additionalProperties:
112+
type: string
113+
description: |-
114+
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
115+
map is equivalent to an element of matchExpressions, whose key field is "key", the
116+
operator is "In", and the values array contains only "value". The requirements are ANDed.
117+
type: object
118+
type: object
119+
x-kubernetes-map-type: atomic
74120
regexMatch:
75-
description: RegexMatch defines the regex match criteria
76-
(required when Type is "Regex").
121+
description: RegexMatch defines the regex match criteria.
77122
properties:
78123
pattern:
79124
description: Pattern defines the regex pattern to match
@@ -82,10 +127,12 @@ spec:
82127
type: object
83128
type: object
84129
x-kubernetes-validations:
85-
- message: Either ExactMatch or RegexMatch must be specified
86-
rule: has(self.exactMatch) || has(self.regexMatch)
87-
- message: ExactMatch and RegexMatch cannot be specified together
88-
rule: '!(has(self.exactMatch) && has(self.regexMatch))'
130+
- message: Either ExactMatch or RegexMatch or LabelMatch must
131+
be specified
132+
rule: has(self.exactMatch) || has(self.regexMatch) || has(self.LabelMatch)
133+
- message: ExactMatch and RegexMatch and LabelMatch cannot be
134+
specified together
135+
rule: '!(has(self.exactMatch) && has(self.regexMatch) && has(self.LabelMatch))'
89136
type:
90137
description: Type specifies the member type.
91138
enum:

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 v1.11.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=

installer/helm/chart/volcano/crd/bases/topology.volcano.sh_hypernodes.yaml

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,62 @@ spec:
6262
description: Selector defines the selection rules for this member.
6363
properties:
6464
exactMatch:
65-
description: ExactMatch defines the exact match criteria
66-
(required when Type is "Exact").
65+
description: ExactMatch defines the exact match criteria.
6766
properties:
6867
name:
6968
description: Name specifies the exact name of the node
7069
to match.
7170
type: string
7271
type: object
72+
labelMatch:
73+
description: LabelMatch defines the labels match criteria
74+
(only take effect when Member Type is "Node").
75+
properties:
76+
matchExpressions:
77+
description: matchExpressions is a list of label selector
78+
requirements. The requirements are ANDed.
79+
items:
80+
description: |-
81+
A label selector requirement is a selector that contains values, a key, and an operator that
82+
relates the key and values.
83+
properties:
84+
key:
85+
description: key is the label key that the selector
86+
applies to.
87+
type: string
88+
operator:
89+
description: |-
90+
operator represents a key's relationship to a set of values.
91+
Valid operators are In, NotIn, Exists and DoesNotExist.
92+
type: string
93+
values:
94+
description: |-
95+
values is an array of string values. If the operator is In or NotIn,
96+
the values array must be non-empty. If the operator is Exists or DoesNotExist,
97+
the values array must be empty. This array is replaced during a strategic
98+
merge patch.
99+
items:
100+
type: string
101+
type: array
102+
x-kubernetes-list-type: atomic
103+
required:
104+
- key
105+
- operator
106+
type: object
107+
type: array
108+
x-kubernetes-list-type: atomic
109+
matchLabels:
110+
additionalProperties:
111+
type: string
112+
description: |-
113+
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
114+
map is equivalent to an element of matchExpressions, whose key field is "key", the
115+
operator is "In", and the values array contains only "value". The requirements are ANDed.
116+
type: object
117+
type: object
118+
x-kubernetes-map-type: atomic
73119
regexMatch:
74-
description: RegexMatch defines the regex match criteria
75-
(required when Type is "Regex").
120+
description: RegexMatch defines the regex match criteria.
76121
properties:
77122
pattern:
78123
description: Pattern defines the regex pattern to match
@@ -81,10 +126,12 @@ spec:
81126
type: object
82127
type: object
83128
x-kubernetes-validations:
84-
- message: Either ExactMatch or RegexMatch must be specified
85-
rule: has(self.exactMatch) || has(self.regexMatch)
86-
- message: ExactMatch and RegexMatch cannot be specified together
87-
rule: '!(has(self.exactMatch) && has(self.regexMatch))'
129+
- message: Either ExactMatch or RegexMatch or LabelMatch must
130+
be specified
131+
rule: has(self.exactMatch) || has(self.regexMatch) || has(self.LabelMatch)
132+
- message: ExactMatch and RegexMatch and LabelMatch cannot be
133+
specified together
134+
rule: '!(has(self.exactMatch) && has(self.regexMatch) && has(self.LabelMatch))'
88135
type:
89136
description: Type specifies the member type.
90137
enum:

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)