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
```
pull/6/head
Kubernetes Submit Queue 2017-08-16 23:08:15 -07:00 committed by GitHub
commit acd5f22398
2 changed files with 9 additions and 9 deletions

View File

@ -176,7 +176,6 @@ func defaultPredicates() sets.String {
factory.RegisterFitPredicate("CheckNodeDiskPressure", predicates.CheckNodeDiskPressurePredicate),
// Fit is determied by node condtions: not ready, network unavailable and out of disk.
factory.RegisterFitPredicate("CheckNodeCondition", predicates.CheckNodeConditionPredicate),
factory.RegisterMandatoryFitPredicate("CheckNodeCondition", predicates.CheckNodeConditionPredicate),
// Fit is determined by volume zone requirements.

View File

@ -72,10 +72,10 @@ var (
schedulerFactoryMutex sync.Mutex
// maps that hold registered algorithm types
fitPredicateMap = make(map[string]FitPredicateFactory)
mandatoryFitPredicateMap = make(map[string]FitPredicateFactory)
priorityFunctionMap = make(map[string]PriorityConfigFactory)
algorithmProviderMap = make(map[string]AlgorithmProviderConfig)
fitPredicateMap = make(map[string]FitPredicateFactory)
mandatoryFitPredicates = sets.NewString()
priorityFunctionMap = make(map[string]PriorityConfigFactory)
algorithmProviderMap = make(map[string]AlgorithmProviderConfig)
// Registered metadata producers
priorityMetadataProducer MetadataProducerFactory
@ -107,7 +107,8 @@ func RegisterMandatoryFitPredicate(name string, predicate algorithm.FitPredicate
schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock()
validateAlgorithmNameOrDie(name)
mandatoryFitPredicateMap[name] = func(PluginFactoryArgs) algorithm.FitPredicate { return predicate }
fitPredicateMap[name] = func(PluginFactoryArgs) algorithm.FitPredicate { return predicate }
mandatoryFitPredicates.Insert(name)
return name
}
@ -321,9 +322,9 @@ func getFitPredicateFunctions(names sets.String, args PluginFactoryArgs) (map[st
predicates[name] = factory(args)
}
// Always include required fit predicates.
for name, factory := range mandatoryFitPredicateMap {
if _, found := predicates[name]; !found {
// Always include mandatory fit predicates.
for name := range mandatoryFitPredicates {
if factory, found := fitPredicateMap[name]; found {
predicates[name] = factory(args)
}
}