mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
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:
commit
4e6e4ee1f9
@ -135,31 +135,35 @@ func (g *genericScheduler) selectHost(priorityList schedulerapi.HostPriorityList
|
|||||||
// Filters the nodes to find the ones that fit based on the given predicate functions
|
// 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
|
// 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) {
|
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{}
|
filtered := []api.Node{}
|
||||||
failedPredicateMap := FailedPredicateMap{}
|
failedPredicateMap := FailedPredicateMap{}
|
||||||
errs := []error{}
|
|
||||||
|
|
||||||
checkNode := func(i int) {
|
if len(predicateFuncs) == 0 {
|
||||||
nodeName := nodes.Items[i].Name
|
filtered = nodes.Items
|
||||||
fits, failedPredicate, err := podFitsOnNode(pod, nodeNameToInfo[nodeName], predicateFuncs)
|
} else {
|
||||||
|
predicateResultLock := sync.Mutex{}
|
||||||
|
errs := []error{}
|
||||||
|
checkNode := func(i int) {
|
||||||
|
nodeName := nodes.Items[i].Name
|
||||||
|
fits, failedPredicate, err := podFitsOnNode(pod, nodeNameToInfo[nodeName], predicateFuncs)
|
||||||
|
|
||||||
predicateResultLock.Lock()
|
predicateResultLock.Lock()
|
||||||
defer predicateResultLock.Unlock()
|
defer predicateResultLock.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs = append(errs, err)
|
errs = append(errs, err)
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
if fits {
|
||||||
|
filtered = append(filtered, nodes.Items[i])
|
||||||
|
} else {
|
||||||
|
failedPredicateMap[nodeName] = failedPredicate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if fits {
|
workqueue.Parallelize(16, len(nodes.Items), checkNode)
|
||||||
filtered = append(filtered, nodes.Items[i])
|
if len(errs) > 0 {
|
||||||
} else {
|
return api.NodeList{}, FailedPredicateMap{}, errors.NewAggregate(errs)
|
||||||
failedPredicateMap[nodeName] = failedPredicate
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
workqueue.Parallelize(16, len(nodes.Items), checkNode)
|
|
||||||
if len(errs) > 0 {
|
|
||||||
return api.NodeList{}, FailedPredicateMap{}, errors.NewAggregate(errs)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(filtered) > 0 && len(extenders) != 0 {
|
if len(filtered) > 0 && len(extenders) != 0 {
|
||||||
for _, extender := range extenders {
|
for _, extender := range extenders {
|
||||||
|
Loading…
Reference in New Issue
Block a user