Add the length detection of the "predicateFuncs" in generic_scheduler.go

The PR add the length detection of the "predicateFuncs" for "findNodesThatFit" function of generic_scheduler.go. 
In “findNodesThatFit” function, if the length of the "predicateFuncs" parameter is 0, it can set filtered equals nodes.Items, and needn't to traverse the nodes.Items.
This commit is contained in:
PingWang 2016-05-20 08:49:53 +08:00
parent 5ffebfa303
commit b973670344

View File

@ -137,11 +137,14 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
// Filters the nodes to find the ones that fit based on the given predicate functions
// Each node is passed through the predicate functions to determine if it is a fit
func findNodesThatFit(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, predicateFuncs map[string]algorithm.FitPredicate, nodes api.NodeList, extenders []algorithm.SchedulerExtender) (api.NodeList, FailedPredicateMap, error) {
predicateResultLock := sync.Mutex{}
filtered := []api.Node{}
failedPredicateMap := FailedPredicateMap{}
errs := []error{}
if len(predicateFuncs) == 0 {
filtered = nodes.Items
} else {
predicateResultLock := sync.Mutex{}
errs := []error{}
checkNode := func(i int) {
nodeName := nodes.Items[i].Name
fits, failedPredicate, err := podFitsOnNode(pod, nodeNameToInfo[nodeName], predicateFuncs)
@ -162,6 +165,7 @@ func findNodesThatFit(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.No
if len(errs) > 0 {
return api.NodeList{}, FailedPredicateMap{}, errors.NewAggregate(errs)
}
}
if len(filtered) > 0 && len(extenders) != 0 {
for _, extender := range extenders {