@@ -22,13 +22,11 @@ import (
22
22
"k8s.io/klog"
23
23
24
24
v1 "k8s.io/api/core/v1"
25
- "k8s.io/apimachinery/pkg/fields"
26
- "k8s.io/apimachinery/pkg/labels"
27
25
"k8s.io/apimachinery/pkg/util/sets"
28
26
utilfeature "k8s.io/apiserver/pkg/util/feature"
29
27
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
30
28
"k8s.io/kubernetes/pkg/features"
31
- "k8s.io/kubernetes/pkg/scheduler/algorithm "
29
+ pluginhelper "k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper "
32
30
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
33
31
schedutil "k8s.io/kubernetes/pkg/scheduler/util"
34
32
)
@@ -237,70 +235,13 @@ func PodFitsResourcesPredicate(pod *v1.Pod, podRequest *schedulernodeinfo.Resour
237
235
return len (predicateFails ) == 0 , predicateFails , nil
238
236
}
239
237
240
- // nodeMatchesNodeSelectorTerms checks if a node's labels satisfy a list of node selector terms,
241
- // terms are ORed, and an empty list of terms will match nothing.
242
- func nodeMatchesNodeSelectorTerms (node * v1.Node , nodeSelectorTerms []v1.NodeSelectorTerm ) bool {
243
- nodeFields := map [string ]string {}
244
- for k , f := range algorithm .NodeFieldSelectorKeys {
245
- nodeFields [k ] = f (node )
246
- }
247
- return v1helper .MatchNodeSelectorTerms (nodeSelectorTerms , labels .Set (node .Labels ), fields .Set (nodeFields ))
248
- }
249
-
250
- // PodMatchesNodeSelectorAndAffinityTerms checks whether the pod is schedulable onto nodes according to
251
- // the requirements in both NodeAffinity and nodeSelector.
252
- func PodMatchesNodeSelectorAndAffinityTerms (pod * v1.Pod , node * v1.Node ) bool {
253
- // Check if node.Labels match pod.Spec.NodeSelector.
254
- if len (pod .Spec .NodeSelector ) > 0 {
255
- selector := labels .SelectorFromSet (pod .Spec .NodeSelector )
256
- if ! selector .Matches (labels .Set (node .Labels )) {
257
- return false
258
- }
259
- }
260
-
261
- // 1. nil NodeSelector matches all nodes (i.e. does not filter out any nodes)
262
- // 2. nil []NodeSelectorTerm (equivalent to non-nil empty NodeSelector) matches no nodes
263
- // 3. zero-length non-nil []NodeSelectorTerm matches no nodes also, just for simplicity
264
- // 4. nil []NodeSelectorRequirement (equivalent to non-nil empty NodeSelectorTerm) matches no nodes
265
- // 5. zero-length non-nil []NodeSelectorRequirement matches no nodes also, just for simplicity
266
- // 6. non-nil empty NodeSelectorRequirement is not allowed
267
- nodeAffinityMatches := true
268
- affinity := pod .Spec .Affinity
269
- if affinity != nil && affinity .NodeAffinity != nil {
270
- nodeAffinity := affinity .NodeAffinity
271
- // if no required NodeAffinity requirements, will do no-op, means select all nodes.
272
- // TODO: Replace next line with subsequent commented-out line when implement RequiredDuringSchedulingRequiredDuringExecution.
273
- if nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution == nil {
274
- // if nodeAffinity.RequiredDuringSchedulingRequiredDuringExecution == nil && nodeAffinity.RequiredDuringSchedulingIgnoredDuringExecution == nil {
275
- return true
276
- }
277
-
278
- // Match node selector for requiredDuringSchedulingRequiredDuringExecution.
279
- // TODO: Uncomment this block when implement RequiredDuringSchedulingRequiredDuringExecution.
280
- // if nodeAffinity.RequiredDuringSchedulingRequiredDuringExecution != nil {
281
- // nodeSelectorTerms := nodeAffinity.RequiredDuringSchedulingRequiredDuringExecution.NodeSelectorTerms
282
- // klog.V(10).Infof("Match for RequiredDuringSchedulingRequiredDuringExecution node selector terms %+v", nodeSelectorTerms)
283
- // nodeAffinityMatches = nodeMatchesNodeSelectorTerms(node, nodeSelectorTerms)
284
- // }
285
-
286
- // Match node selector for requiredDuringSchedulingIgnoredDuringExecution.
287
- if nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution != nil {
288
- nodeSelectorTerms := nodeAffinity .RequiredDuringSchedulingIgnoredDuringExecution .NodeSelectorTerms
289
- klog .V (10 ).Infof ("Match for RequiredDuringSchedulingIgnoredDuringExecution node selector terms %+v" , nodeSelectorTerms )
290
- nodeAffinityMatches = nodeAffinityMatches && nodeMatchesNodeSelectorTerms (node , nodeSelectorTerms )
291
- }
292
-
293
- }
294
- return nodeAffinityMatches
295
- }
296
-
297
238
// PodMatchNodeSelector checks if a pod node selector matches the node label.
298
239
func PodMatchNodeSelector (pod * v1.Pod , meta Metadata , nodeInfo * schedulernodeinfo.NodeInfo ) (bool , []PredicateFailureReason , error ) {
299
240
node := nodeInfo .Node ()
300
241
if node == nil {
301
242
return false , nil , fmt .Errorf ("node not found" )
302
243
}
303
- if PodMatchesNodeSelectorAndAffinityTerms (pod , node ) {
244
+ if pluginhelper . PodMatchesNodeSelectorAndAffinityTerms (pod , node ) {
304
245
return true , nil , nil
305
246
}
306
247
return false , []PredicateFailureReason {ErrNodeSelectorNotMatch }, nil
0 commit comments