mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +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
|
||||
// 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{}
|
||||
|
||||
checkNode := func(i int) {
|
||||
nodeName := nodes.Items[i].Name
|
||||
fits, failedPredicate, err := podFitsOnNode(pod, nodeNameToInfo[nodeName], predicateFuncs)
|
||||
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)
|
||||
|
||||
predicateResultLock.Lock()
|
||||
defer predicateResultLock.Unlock()
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return
|
||||
predicateResultLock.Lock()
|
||||
defer predicateResultLock.Unlock()
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
return
|
||||
}
|
||||
if fits {
|
||||
filtered = append(filtered, nodes.Items[i])
|
||||
} else {
|
||||
failedPredicateMap[nodeName] = failedPredicate
|
||||
}
|
||||
}
|
||||
if fits {
|
||||
filtered = append(filtered, nodes.Items[i])
|
||||
} else {
|
||||
failedPredicateMap[nodeName] = failedPredicate
|
||||
workqueue.Parallelize(16, len(nodes.Items), checkNode)
|
||||
if len(errs) > 0 {
|
||||
return api.NodeList{}, FailedPredicateMap{}, errors.NewAggregate(errs)
|
||||
}
|
||||
}
|
||||
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 {
|
||||
for _, extender := range extenders {
|
||||
|
Loading…
Reference in New Issue
Block a user