Merge pull request #25934 from ping035627/ping035627-patch-3

Automatic merge from submit-queue

Fix  #25606: Add the length detection of the "predicateFuncs" in generic_scheduler.go

Fix  #25606

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:
k8s-merge-robot 2016-06-25 03:04:44 -07:00 committed by GitHub
commit 4e6e4ee1f9

View File

@ -135,11 +135,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)
@ -160,6 +163,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 {