From eefc18a763f4f0d8af1422e30ff916edb3dc68e8 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Wed, 8 May 2019 15:58:42 -0700 Subject: [PATCH] EvenPodsSpread: Define a new Priority --- .../algorithm/priorities/even_pods_spread.go | 17 +++++++++++++++++ .../algorithm/priorities/priorities.go | 3 +++ .../algorithmprovider/defaults/defaults.go | 7 ++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 pkg/scheduler/algorithm/priorities/even_pods_spread.go diff --git a/pkg/scheduler/algorithm/priorities/even_pods_spread.go b/pkg/scheduler/algorithm/priorities/even_pods_spread.go new file mode 100644 index 00000000000..6045934f601 --- /dev/null +++ b/pkg/scheduler/algorithm/priorities/even_pods_spread.go @@ -0,0 +1,17 @@ +/* +Copyright 2019 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package priorities diff --git a/pkg/scheduler/algorithm/priorities/priorities.go b/pkg/scheduler/algorithm/priorities/priorities.go index 605fdd143e3..5c2d76b94de 100644 --- a/pkg/scheduler/algorithm/priorities/priorities.go +++ b/pkg/scheduler/algorithm/priorities/priorities.go @@ -51,4 +51,7 @@ const ( ImageLocalityPriority = "ImageLocalityPriority" // ResourceLimitsPriority defines the nodes of prioritizer function ResourceLimitsPriority. ResourceLimitsPriority = "ResourceLimitsPriority" + // EvenPodsSpreadPriority defines the name of prioritizer function that prioritizes nodes + // which have pods and labels matching the incoming pod's topologySpreadConstraints. + EvenPodsSpreadPriority = "EvenPodsSpreadPriority" ) diff --git a/pkg/scheduler/algorithmprovider/defaults/defaults.go b/pkg/scheduler/algorithmprovider/defaults/defaults.go index a77ee69e069..6fd14d4513f 100644 --- a/pkg/scheduler/algorithmprovider/defaults/defaults.go +++ b/pkg/scheduler/algorithmprovider/defaults/defaults.go @@ -87,10 +87,15 @@ func ApplyFeatureGates() { klog.Infof("TaintNodesByCondition is enabled, PodToleratesNodeTaints predicate is mandatory") } - // Only register EvenPodsSpreadPredicate if the feature is enabled + // Only register EvenPodsSpread predicate & priority if the feature is enabled if utilfeature.DefaultFeatureGate.Enabled(features.EvenPodsSpread) { + klog.Infof("Registering EvenPodsSpread predicate and priority function") + // register predicate factory.InsertPredicateKeyToAlgorithmProviderMap(predicates.EvenPodsSpreadPred) factory.RegisterFitPredicate(predicates.EvenPodsSpreadPred, predicates.EvenPodsSpreadPredicate) + // register priority + factory.InsertPriorityKeyToAlgorithmProviderMap(priorities.EvenPodsSpreadPriority) + factory.RegisterPriorityFunction(priorities.EvenPodsSpreadPriority, priorities.CalculateEvenPodsSpreadPriority, 1) } // Prioritizes nodes that satisfy pod's resource limits