Merge pull request #38084 from tanshanshan/fix-little1

Automatic merge from submit-queue

Fix comment and optimize code

**What this PR does / why we need it**:

Fix comment and optimize code.

Thanks.

**Special notes for your reviewer**:

**Release note**:

```release-note
```
This commit is contained in:
Kubernetes Submit Queue 2017-01-04 06:56:32 -08:00 committed by GitHub
commit bd100b3b80
2 changed files with 12 additions and 13 deletions

View File

@ -59,7 +59,7 @@ type Topologies struct {
} }
// NodesHaveSameTopologyKey checks if nodeA and nodeB have same label value with given topologyKey as label key. // NodesHaveSameTopologyKey checks if nodeA and nodeB have same label value with given topologyKey as label key.
// If the topologyKey is nil/empty, check if the two nodes have any of the default topologyKeys, and have same corresponding label value. // If the topologyKey is empty, check if the two nodes have any of the default topologyKeys, and have same corresponding label value.
func (tps *Topologies) NodesHaveSameTopologyKey(nodeA, nodeB *v1.Node, topologyKey string) bool { func (tps *Topologies) NodesHaveSameTopologyKey(nodeA, nodeB *v1.Node, topologyKey string) bool {
if len(topologyKey) == 0 { if len(topologyKey) == 0 {
// assumes this is allowed only for PreferredDuringScheduling pod anti-affinity (ensured by api/validation) // assumes this is allowed only for PreferredDuringScheduling pod anti-affinity (ensured by api/validation)

View File

@ -82,7 +82,7 @@ var (
predicateMetadataProducer MetadataProducerFactory predicateMetadataProducer MetadataProducerFactory
// get equivalence pod function // get equivalence pod function
getEquivalencePodFunc algorithm.GetEquivalencePodFunc = nil getEquivalencePodFunc algorithm.GetEquivalencePodFunc
) )
const ( const (
@ -110,7 +110,7 @@ func RegisterFitPredicateFactory(name string, predicateFactory FitPredicateFacto
return name return name
} }
// Registers a custom fit predicate with the algorithm registry. // RegisterCustomFitPredicate registers a custom fit predicate with the algorithm registry.
// Returns the name, with which the predicate was registered. // Returns the name, with which the predicate was registered.
func RegisterCustomFitPredicate(policy schedulerapi.PredicatePolicy) string { func RegisterCustomFitPredicate(policy schedulerapi.PredicatePolicy) string {
var predicateFactory FitPredicateFactory var predicateFactory FitPredicateFactory
@ -154,7 +154,7 @@ func RegisterCustomFitPredicate(policy schedulerapi.PredicatePolicy) string {
return RegisterFitPredicateFactory(policy.Name, predicateFactory) return RegisterFitPredicateFactory(policy.Name, predicateFactory)
} }
// This check is useful for testing providers. // IsFitPredicateRegistered is useful for testing providers.
func IsFitPredicateRegistered(name string) bool { func IsFitPredicateRegistered(name string) bool {
schedulerFactoryMutex.Lock() schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock() defer schedulerFactoryMutex.Unlock()
@ -187,7 +187,7 @@ func RegisterPriorityFunction(name string, function algorithm.PriorityFunction,
}) })
} }
// Registers a priority function with the algorithm registry. Returns the name, // RegisterPriorityFunction2 registers a priority function with the algorithm registry. Returns the name,
// with which the function was registered. // with which the function was registered.
// FIXME: Rename to PriorityFunctionFactory. // FIXME: Rename to PriorityFunctionFactory.
func RegisterPriorityFunction2( func RegisterPriorityFunction2(
@ -211,7 +211,7 @@ func RegisterPriorityConfigFactory(name string, pcf PriorityConfigFactory) strin
return name return name
} }
// Registers a custom priority function with the algorithm registry. // RegisterCustomPriorityFunction registers a custom priority function with the algorithm registry.
// Returns the name, with which the priority function was registered. // Returns the name, with which the priority function was registered.
func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string { func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
var pcf *PriorityConfigFactory var pcf *PriorityConfigFactory
@ -242,12 +242,12 @@ func RegisterCustomPriorityFunction(policy schedulerapi.PriorityPolicy) string {
Weight: policy.Weight, Weight: policy.Weight,
} }
} }
} else if existing_pcf, ok := priorityFunctionMap[policy.Name]; ok { } else if existingPcf, ok := priorityFunctionMap[policy.Name]; ok {
glog.V(2).Infof("Priority type %s already registered, reusing.", policy.Name) glog.V(2).Infof("Priority type %s already registered, reusing.", policy.Name)
// set/update the weight based on the policy // set/update the weight based on the policy
pcf = &PriorityConfigFactory{ pcf = &PriorityConfigFactory{
Function: existing_pcf.Function, Function: existingPcf.Function,
MapReduceFunction: existing_pcf.MapReduceFunction, MapReduceFunction: existingPcf.MapReduceFunction,
Weight: policy.Weight, Weight: policy.Weight,
} }
} }
@ -263,7 +263,7 @@ func RegisterGetEquivalencePodFunction(equivalenceFunc algorithm.GetEquivalenceP
getEquivalencePodFunc = equivalenceFunc getEquivalencePodFunc = equivalenceFunc
} }
// This check is useful for testing providers. // IsPriorityFunctionRegistered is useful for testing providers.
func IsPriorityFunctionRegistered(name string) bool { func IsPriorityFunctionRegistered(name string) bool {
schedulerFactoryMutex.Lock() schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock() defer schedulerFactoryMutex.Unlock()
@ -271,7 +271,7 @@ func IsPriorityFunctionRegistered(name string) bool {
return ok return ok
} }
// Registers a new algorithm provider with the algorithm registry. This should // RegisterAlgorithmProvider registers a new algorithm provider with the algorithm registry. This should
// be called from the init function in a provider plugin. // be called from the init function in a provider plugin.
func RegisterAlgorithmProvider(name string, predicateKeys, priorityKeys sets.String) string { func RegisterAlgorithmProvider(name string, predicateKeys, priorityKeys sets.String) string {
schedulerFactoryMutex.Lock() schedulerFactoryMutex.Lock()
@ -284,12 +284,11 @@ func RegisterAlgorithmProvider(name string, predicateKeys, priorityKeys sets.Str
return name return name
} }
// This function should not be used to modify providers. It is publicly visible for testing. // GetAlgorithmProvider should not be used to modify providers. It is publicly visible for testing.
func GetAlgorithmProvider(name string) (*AlgorithmProviderConfig, error) { func GetAlgorithmProvider(name string) (*AlgorithmProviderConfig, error) {
schedulerFactoryMutex.Lock() schedulerFactoryMutex.Lock()
defer schedulerFactoryMutex.Unlock() defer schedulerFactoryMutex.Unlock()
var provider AlgorithmProviderConfig
provider, ok := algorithmProviderMap[name] provider, ok := algorithmProviderMap[name]
if !ok { if !ok {
return nil, fmt.Errorf("plugin %q has not been registered", name) return nil, fmt.Errorf("plugin %q has not been registered", name)