mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 04:08:16 +00:00 
			
		
		
		
	Merge pull request #28459 from ping035627/ping035627-patch-0704
Automatic merge from submit-queue Optimise the process of the CalculateSpreadPriority in selector_spreading.go It had better inspect if the nodeLister is normal first in the CalculateSpreadPriority in selector_spreading.go. If the nodeLister.List return error, the function return directly, not need deal the serviceLister and controllerLister and replicaSetLister.
This commit is contained in:
		@@ -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
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	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)
 | 
				
			||||||
@@ -195,6 +195,10 @@ func NewServiceAntiAffinityPriority(podLister algorithm.PodLister, serviceLister
 | 
				
			|||||||
// The label to be considered is provided to the struct (ServiceAntiAffinity).
 | 
					// The label to be considered is provided to the struct (ServiceAntiAffinity).
 | 
				
			||||||
func (s *ServiceAntiAffinity) CalculateAntiAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
 | 
					func (s *ServiceAntiAffinity) CalculateAntiAffinityPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
 | 
				
			||||||
	var nsServicePods []*api.Pod
 | 
						var nsServicePods []*api.Pod
 | 
				
			||||||
 | 
						nodes, err := nodeLister.List()
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if services, err := s.serviceLister.GetPodServices(pod); err == nil {
 | 
						if services, err := s.serviceLister.GetPodServices(pod); err == nil {
 | 
				
			||||||
		// just use the first service and get the other pods within the service
 | 
							// just use the first service and get the other pods within the service
 | 
				
			||||||
@@ -212,11 +216,6 @@ func (s *ServiceAntiAffinity) CalculateAntiAffinityPriority(pod *api.Pod, nodeNa
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	nodes, err := nodeLister.List()
 | 
					 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		return nil, err
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// separate out the nodes that have the label from the ones that don't
 | 
						// separate out the nodes that have the label from the ones that don't
 | 
				
			||||||
	otherNodes := []string{}
 | 
						otherNodes := []string{}
 | 
				
			||||||
	labeledNodes := map[string]string{}
 | 
						labeledNodes := map[string]string{}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user