Commit acd5f223 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50581 from k82cn/k8s_50360_1

Automatic merge from submit-queue (batch tested with PRs 49342, 50581, 50777) Update RegisterMandatoryFitPredicate to avoid double register. **What this PR does / why we need it**: In https://github.com/kubernetes/kubernetes/pull/50362 , we introduced `RegisterMandatoryFitPredicate` to make some predicates always included by scheduler. This PRs is to improve it by avoiding double register: `RegisterFitPredicate` and `RegisterMandatoryFitPredicate` **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #50360 **Release note**: ```release-note None ```
parents ccc40f49 051dfb1b
...@@ -176,7 +176,6 @@ func defaultPredicates() sets.String { ...@@ -176,7 +176,6 @@ func defaultPredicates() sets.String {
factory.RegisterFitPredicate("CheckNodeDiskPressure", predicates.CheckNodeDiskPressurePredicate), factory.RegisterFitPredicate("CheckNodeDiskPressure", predicates.CheckNodeDiskPressurePredicate),
// Fit is determied by node condtions: not ready, network unavailable and out of disk. // Fit is determied by node condtions: not ready, network unavailable and out of disk.
factory.RegisterFitPredicate("CheckNodeCondition", predicates.CheckNodeConditionPredicate),
factory.RegisterMandatoryFitPredicate("CheckNodeCondition", predicates.CheckNodeConditionPredicate), factory.RegisterMandatoryFitPredicate("CheckNodeCondition", predicates.CheckNodeConditionPredicate),
// Fit is determined by volume zone requirements. // Fit is determined by volume zone requirements.
......
...@@ -72,10 +72,10 @@ var ( ...@@ -72,10 +72,10 @@ var (
schedulerFactoryMutex sync.Mutex schedulerFactoryMutex sync.Mutex
// maps that hold registered algorithm types // maps that hold registered algorithm types
fitPredicateMap = make(map[string]FitPredicateFactory) fitPredicateMap = make(map[string]FitPredicateFactory)
mandatoryFitPredicateMap = make(map[string]FitPredicateFactory) mandatoryFitPredicates = sets.NewString()
priorityFunctionMap = make(map[string]PriorityConfigFactory) priorityFunctionMap = make(map[string]PriorityConfigFactory)
algorithmProviderMap = make(map[string]AlgorithmProviderConfig) algorithmProviderMap = make(map[string]AlgorithmProviderConfig)
// Registered metadata producers // Registered metadata producers
priorityMetadataProducer MetadataProducerFactory priorityMetadataProducer MetadataProducerFactory
...@@ -107,7 +107,8 @@ func RegisterMandatoryFitPredicate(name string, predicate algorithm.FitPredicate ...@@ -107,7 +107,8 @@ func RegisterMandatoryFitPredicate(name string, predicate algorithm.FitPredicate
schedulerFactoryMutex.Lock() schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock() defer schedulerFactoryMutex.Unlock()
validateAlgorithmNameOrDie(name) validateAlgorithmNameOrDie(name)
mandatoryFitPredicateMap[name] = func(PluginFactoryArgs) algorithm.FitPredicate { return predicate } fitPredicateMap[name] = func(PluginFactoryArgs) algorithm.FitPredicate { return predicate }
mandatoryFitPredicates.Insert(name)
return name return name
} }
...@@ -321,9 +322,9 @@ func getFitPredicateFunctions(names sets.String, args PluginFactoryArgs) (map[st ...@@ -321,9 +322,9 @@ func getFitPredicateFunctions(names sets.String, args PluginFactoryArgs) (map[st
predicates[name] = factory(args) predicates[name] = factory(args)
} }
// Always include required fit predicates. // Always include mandatory fit predicates.
for name, factory := range mandatoryFitPredicateMap { for name := range mandatoryFitPredicates {
if _, found := predicates[name]; !found { if factory, found := fitPredicateMap[name]; found {
predicates[name] = factory(args) predicates[name] = factory(args)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment