Update RegisterMandatoryFitPredicate to avoid double register.

This commit is contained in:
Klaus Ma 2017-08-14 09:02:41 +08:00
parent 2820b45caa
commit 4a32bde4a5
2 changed files with 12 additions and 10 deletions

View File

@ -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.

View File

@ -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 = make(map[string]bool)
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
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[name] = true
return name return name
} }
@ -321,10 +322,12 @@ 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, mandatory := range mandatoryFitPredicates {
if _, found := predicates[name]; !found { if mandatory {
predicates[name] = factory(args) if factory, found := fitPredicateMap[name]; found {
predicates[name] = factory(args)
}
} }
} }