mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	Few more optimizations of priority functions in scheduler
This commit is contained in:
		@@ -295,64 +295,67 @@ func NewNodePreferAvoidPodsPriority(controllerLister algorithm.ControllerLister,
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (npa *NodePreferAvoidPod) CalculateNodePreferAvoidPodsPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
 | 
					func (npa *NodePreferAvoidPod) CalculateNodePreferAvoidPodsPriority(pod *api.Pod, nodeNameToInfo map[string]*schedulercache.NodeInfo, nodeLister algorithm.NodeLister) (schedulerapi.HostPriorityList, error) {
 | 
				
			||||||
	var score int
 | 
					 | 
				
			||||||
	nodes, err := nodeLister.List()
 | 
						nodes, err := nodeLister.List()
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, err
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	result := []schedulerapi.HostPriority{}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// TODO: Once we have ownerReference fully implemented, use it to find controller for the pod.
 | 
						// TODO: Once we have ownerReference fully implemented, use it to find controller for the pod.
 | 
				
			||||||
	rcs, err := npa.controllerLister.GetPodControllers(pod)
 | 
						rcs, err := npa.controllerLister.GetPodControllers(pod)
 | 
				
			||||||
	rss, err := npa.replicaSetLister.GetPodReplicaSets(pod)
 | 
						rss, err := npa.replicaSetLister.GetPodReplicaSets(pod)
 | 
				
			||||||
	if len(rcs) == 0 && len(rss) == 0 {
 | 
						if len(rcs) == 0 && len(rss) == 0 {
 | 
				
			||||||
 | 
							result := make(schedulerapi.HostPriorityList, 0, len(nodes))
 | 
				
			||||||
		for _, node := range nodes {
 | 
							for _, node := range nodes {
 | 
				
			||||||
			result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: 10})
 | 
								result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: 10})
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return result, nil
 | 
							return result, nil
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	avoidNodes := map[string]bool{}
 | 
						avoidNodes := make(map[string]bool, len(nodes))
 | 
				
			||||||
 | 
						avoidNode := false
 | 
				
			||||||
	for _, node := range nodes {
 | 
						for _, node := range nodes {
 | 
				
			||||||
		avoidNodes[node.Name] = false
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		avoids, err := api.GetAvoidPodsFromNodeAnnotations(node.Annotations)
 | 
							avoids, err := api.GetAvoidPodsFromNodeAnnotations(node.Annotations)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
			continue
 | 
								continue
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for _, avoid := range avoids.PreferAvoidPods {
 | 
							avoidNode = false
 | 
				
			||||||
 | 
							for i := range avoids.PreferAvoidPods {
 | 
				
			||||||
 | 
								avoid := &avoids.PreferAvoidPods[i]
 | 
				
			||||||
 | 
								// TODO: Once we have controllerRef implemented there will be at most one owner
 | 
				
			||||||
 | 
								// of our pod. That said we won't even need loop theoretically. That said for
 | 
				
			||||||
 | 
								// code simplicity, we can get rid of all breaks.
 | 
				
			||||||
 | 
								// Also, we can simply compare fields from ownerRef with avoid.
 | 
				
			||||||
			for _, rc := range rcs {
 | 
								for _, rc := range rcs {
 | 
				
			||||||
				if avoid.PodSignature.PodController.Kind == "ReplicationController" && avoid.PodSignature.PodController.UID == rc.UID {
 | 
									if avoid.PodSignature.PodController.Kind == "ReplicationController" && avoid.PodSignature.PodController.UID == rc.UID {
 | 
				
			||||||
					avoidNodes[node.Name] = true
 | 
										avoidNode = true
 | 
				
			||||||
					break
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if avoidNodes[node.Name] {
 | 
					 | 
				
			||||||
				break
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			for _, rs := range rss {
 | 
								for _, rs := range rss {
 | 
				
			||||||
				if avoid.PodSignature.PodController.Kind == "ReplicaSet" && avoid.PodSignature.PodController.UID == rs.UID {
 | 
									if avoid.PodSignature.PodController.Kind == "ReplicaSet" && avoid.PodSignature.PodController.UID == rs.UID {
 | 
				
			||||||
					avoidNodes[node.Name] = true
 | 
										avoidNode = true
 | 
				
			||||||
					break
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			if avoidNodes[node.Name] {
 | 
								if avoidNode {
 | 
				
			||||||
 | 
									// false is default value, so we don't even need to set it
 | 
				
			||||||
 | 
									// to avoid unnecessary map operations.
 | 
				
			||||||
 | 
									avoidNodes[node.Name] = true
 | 
				
			||||||
				break
 | 
									break
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						var score int
 | 
				
			||||||
 | 
						result := make(schedulerapi.HostPriorityList, 0, len(nodes))
 | 
				
			||||||
	//score int - scale of 0-10
 | 
						//score int - scale of 0-10
 | 
				
			||||||
	// 0 being the lowest priority and 10 being the highest
 | 
						// 0 being the lowest priority and 10 being the highest
 | 
				
			||||||
	for nodeName, shouldAvoid := range avoidNodes {
 | 
						for _, node := range nodes {
 | 
				
			||||||
		if shouldAvoid {
 | 
							if avoidNodes[node.Name] {
 | 
				
			||||||
			score = 0
 | 
								score = 0
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			score = 10
 | 
								score = 10
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		result = append(result, schedulerapi.HostPriority{Host: nodeName, Score: score})
 | 
							result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: score})
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return result, nil
 | 
						return result, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -78,9 +78,12 @@ func ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*sch
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		count := countIntolerableTaintsPreferNoSchedule(taints, tolerationList)
 | 
							count := countIntolerableTaintsPreferNoSchedule(taints, tolerationList)
 | 
				
			||||||
		counts[node.Name] = count
 | 
							if count > 0 {
 | 
				
			||||||
		if count > maxCount {
 | 
								// 0 is default value, so avoid unnecessary map operations.
 | 
				
			||||||
			maxCount = count
 | 
								counts[node.Name] = count
 | 
				
			||||||
 | 
								if count > maxCount {
 | 
				
			||||||
 | 
									maxCount = count
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user