mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-10-30 17:58:14 +00:00 
			
		
		
		
	Fixes and minor cleanups to pod (anti)affinity predicate
This commit is contained in:
		| @@ -1074,14 +1074,13 @@ func getMatchingAntiAffinityTerms(pod *v1.Pod, nodeInfoMap map[string]*scheduler | ||||
| 				continue | ||||
| 			} | ||||
| 			for _, term := range getPodAntiAffinityTerms(affinity.PodAntiAffinity) { | ||||
| 				namespaces := priorityutil.GetNamespacesFromPodAffinityTerm(pod, &term) | ||||
| 				namespaces := priorityutil.GetNamespacesFromPodAffinityTerm(existingPod, &term) | ||||
| 				selector, err := metav1.LabelSelectorAsSelector(term.LabelSelector) | ||||
| 				if err != nil { | ||||
| 					catchError(err) | ||||
| 					return | ||||
| 				} | ||||
| 				match := priorityutil.PodMatchesTermsNamespaceAndSelector(pod, namespaces, selector) | ||||
| 				if match { | ||||
| 				if priorityutil.PodMatchesTermsNamespaceAndSelector(pod, namespaces, selector) { | ||||
| 					nodeResult = append(nodeResult, matchingPodAntiAffinityTerm{term: &term, node: node}) | ||||
| 				} | ||||
| 			} | ||||
| @@ -1109,8 +1108,7 @@ func (c *PodAffinityChecker) getMatchingAntiAffinityTerms(pod *v1.Pod, allPods [ | ||||
| 				if err != nil { | ||||
| 					return nil, err | ||||
| 				} | ||||
| 				match := priorityutil.PodMatchesTermsNamespaceAndSelector(pod, namespaces, selector) | ||||
| 				if match { | ||||
| 				if priorityutil.PodMatchesTermsNamespaceAndSelector(pod, namespaces, selector) { | ||||
| 					result = append(result, matchingPodAntiAffinityTerm{term: &term, node: existingPodNode}) | ||||
| 				} | ||||
| 			} | ||||
| @@ -1128,17 +1126,17 @@ func (c *PodAffinityChecker) satisfiesExistingPodsAntiAffinity(pod *v1.Pod, meta | ||||
| 	} else { | ||||
| 		allPods, err := c.podLister.List(labels.Everything()) | ||||
| 		if err != nil { | ||||
| 			glog.V(10).Infof("Failed to get all pods, %+v", err) | ||||
| 			glog.Errorf("Failed to get all pods, %+v", err) | ||||
| 			return false | ||||
| 		} | ||||
| 		if matchingTerms, err = c.getMatchingAntiAffinityTerms(pod, allPods); err != nil { | ||||
| 			glog.V(10).Infof("Failed to get all terms that pod %+v matches, err: %+v", podName(pod), err) | ||||
| 			glog.Errorf("Failed to get all terms that pod %+v matches, err: %+v", podName(pod), err) | ||||
| 			return false | ||||
| 		} | ||||
| 	} | ||||
| 	for _, term := range matchingTerms { | ||||
| 		if len(term.term.TopologyKey) == 0 { | ||||
| 			glog.V(10).Infof("Empty topologyKey is not allowed except for PreferredDuringScheduling pod anti-affinity") | ||||
| 			glog.Error("Empty topologyKey is not allowed except for PreferredDuringScheduling pod anti-affinity") | ||||
| 			return false | ||||
| 		} | ||||
| 		if priorityutil.NodesHaveSameTopologyKey(node, term.node, term.term.TopologyKey) { | ||||
| @@ -1167,7 +1165,7 @@ func (c *PodAffinityChecker) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod, node | ||||
| 	for _, term := range getPodAffinityTerms(affinity.PodAffinity) { | ||||
| 		termMatches, matchingPodExists, err := c.anyPodMatchesPodAffinityTerm(pod, allPods, node, &term) | ||||
| 		if err != nil { | ||||
| 			glog.V(10).Infof("Cannot schedule pod %+v onto node %v,because of PodAffinityTerm %v, err: %v", | ||||
| 			glog.Errorf("Cannot schedule pod %+v onto node %v,because of PodAffinityTerm %v, err: %v", | ||||
| 				podName(pod), node.Name, term, err) | ||||
| 			return false | ||||
| 		} | ||||
| @@ -1183,7 +1181,7 @@ func (c *PodAffinityChecker) satisfiesPodsAffinityAntiAffinity(pod *v1.Pod, node | ||||
| 			namespaces := priorityutil.GetNamespacesFromPodAffinityTerm(pod, &term) | ||||
| 			selector, err := metav1.LabelSelectorAsSelector(term.LabelSelector) | ||||
| 			if err != nil { | ||||
| 				glog.V(10).Infof("Cannot parse selector on term %v for pod %v. Details %v", | ||||
| 				glog.Errorf("Cannot parse selector on term %v for pod %v. Details %v", | ||||
| 					term, podName(pod), err) | ||||
| 				return false | ||||
| 			} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Wojciech Tyczynski
					Wojciech Tyczynski