Commit 437e133b authored by PingWang's avatar PingWang

Optimise the process of the CalculateSpreadPriority in selector_spreading.go

parent 54c8c820
...@@ -62,6 +62,11 @@ func NewSelectorSpreadPriority(podLister algorithm.PodLister, serviceLister algo ...@@ -62,6 +62,11 @@ func NewSelectorSpreadPriority(podLister algorithm.PodLister, serviceLister algo
// pods which match the same service selectors or RC selectors as the pod being scheduled. // pods which match the same service selectors or RC selectors as the pod being scheduled.
// Where zone information is included on the nodes, it favors nodes in zones with fewer existing matching pods. // Where zone information is included on the nodes, it favors nodes in zones with fewer existing matching pods.
func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) { func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
nodes, err := nodeLister.List()
if err != nil {
return nil, err
}
selectors := make([]labels.Selector, 0, 3) selectors := make([]labels.Selector, 0, 3)
if services, err := s.serviceLister.GetPodServices(pod); err == nil { if services, err := s.serviceLister.GetPodServices(pod); err == nil {
for _, service := range services { for _, service := range services {
...@@ -81,11 +86,6 @@ func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo ma ...@@ -81,11 +86,6 @@ func (s *SelectorSpread) CalculateSpreadPriority(pod *api.Pod, nodeNameToInfo ma
} }
} }
nodes, err := nodeLister.List()
if err != nil {
return nil, err
}
// Count similar pods by node // Count similar pods by node
countsByNodeName := make(map[string]float32, len(nodes)) countsByNodeName := make(map[string]float32, len(nodes))
countsByZone := make(map[string]float32, 10) countsByZone := make(map[string]float32, 10)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment