mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-04 12:18:16 +00:00 
			
		
		
		
	fix inter-pod anti-affinity issue
This commit is contained in:
		@@ -96,7 +96,7 @@ func (c *CachedNodeInfo) GetNodeInfo(id string) (*v1.Node, error) {
 | 
				
			|||||||
	node, err := c.Get(id)
 | 
						node, err := c.Get(id)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if apierrors.IsNotFound(err) {
 | 
						if apierrors.IsNotFound(err) {
 | 
				
			||||||
		return nil, fmt.Errorf("node '%v' not found", id)
 | 
							return nil, err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
@@ -1125,6 +1125,10 @@ func (c *PodAffinityChecker) getMatchingAntiAffinityTerms(pod *v1.Pod, allPods [
 | 
				
			|||||||
		if affinity != nil && affinity.PodAntiAffinity != nil {
 | 
							if affinity != nil && affinity.PodAntiAffinity != nil {
 | 
				
			||||||
			existingPodNode, err := c.info.GetNodeInfo(existingPod.Spec.NodeName)
 | 
								existingPodNode, err := c.info.GetNodeInfo(existingPod.Spec.NodeName)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
 | 
									if apierrors.IsNotFound(err) {
 | 
				
			||||||
 | 
										glog.Errorf("Node not found, %v", existingPod.Spec.NodeName)
 | 
				
			||||||
 | 
										continue
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
				return nil, err
 | 
									return nil, err
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			existingPodMatchingTerms, err := getMatchingAntiAffinityTermsOfExistingPod(pod, existingPod, existingPodNode)
 | 
								existingPodMatchingTerms, err := getMatchingAntiAffinityTermsOfExistingPod(pod, existingPod, existingPodNode)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -33,6 +33,7 @@ go_library(
 | 
				
			|||||||
        "//plugin/pkg/scheduler/schedulercache:go_default_library",
 | 
					        "//plugin/pkg/scheduler/schedulercache:go_default_library",
 | 
				
			||||||
        "//vendor/github.com/golang/glog:go_default_library",
 | 
					        "//vendor/github.com/golang/glog:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
					        "//vendor/k8s.io/api/core/v1:go_default_library",
 | 
				
			||||||
 | 
					        "//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/api/resource:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
 | 
				
			||||||
        "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
 | 
					        "//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -21,6 +21,7 @@ import (
 | 
				
			|||||||
	"sync"
 | 
						"sync"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"k8s.io/api/core/v1"
 | 
						"k8s.io/api/core/v1"
 | 
				
			||||||
 | 
						apierrors "k8s.io/apimachinery/pkg/api/errors"
 | 
				
			||||||
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
						metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 | 
				
			||||||
	"k8s.io/client-go/util/workqueue"
 | 
						"k8s.io/client-go/util/workqueue"
 | 
				
			||||||
	kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
 | 
						kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
 | 
				
			||||||
@@ -137,6 +138,10 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
 | 
				
			|||||||
	processPod := func(existingPod *v1.Pod) error {
 | 
						processPod := func(existingPod *v1.Pod) error {
 | 
				
			||||||
		existingPodNode, err := ipa.info.GetNodeInfo(existingPod.Spec.NodeName)
 | 
							existingPodNode, err := ipa.info.GetNodeInfo(existingPod.Spec.NodeName)
 | 
				
			||||||
		if err != nil {
 | 
							if err != nil {
 | 
				
			||||||
 | 
								if apierrors.IsNotFound(err) {
 | 
				
			||||||
 | 
									glog.Errorf("Node not found, %v", existingPod.Spec.NodeName)
 | 
				
			||||||
 | 
									return nil
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			return err
 | 
								return err
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		existingPodAffinity := existingPod.Spec.Affinity
 | 
							existingPodAffinity := existingPod.Spec.Affinity
 | 
				
			||||||
@@ -189,19 +194,21 @@ func (ipa *InterPodAffinity) CalculateInterPodAffinityPriority(pod *v1.Pod, node
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
	processNode := func(i int) {
 | 
						processNode := func(i int) {
 | 
				
			||||||
		nodeInfo := nodeNameToInfo[allNodeNames[i]]
 | 
							nodeInfo := nodeNameToInfo[allNodeNames[i]]
 | 
				
			||||||
		if hasAffinityConstraints || hasAntiAffinityConstraints {
 | 
							if nodeInfo.Node() != nil {
 | 
				
			||||||
			// We need to process all the nodes.
 | 
								if hasAffinityConstraints || hasAntiAffinityConstraints {
 | 
				
			||||||
			for _, existingPod := range nodeInfo.Pods() {
 | 
									// We need to process all the nodes.
 | 
				
			||||||
				if err := processPod(existingPod); err != nil {
 | 
									for _, existingPod := range nodeInfo.Pods() {
 | 
				
			||||||
					pm.setError(err)
 | 
										if err := processPod(existingPod); err != nil {
 | 
				
			||||||
 | 
											pm.setError(err)
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								} else {
 | 
				
			||||||
		} else {
 | 
									// The pod doesn't have any constraints - we need to check only existing
 | 
				
			||||||
			// The pod doesn't have any constraints - we need to check only existing
 | 
									// ones that have some.
 | 
				
			||||||
			// ones that have some.
 | 
									for _, existingPod := range nodeInfo.PodsWithAffinity() {
 | 
				
			||||||
			for _, existingPod := range nodeInfo.PodsWithAffinity() {
 | 
										if err := processPod(existingPod); err != nil {
 | 
				
			||||||
				if err := processPod(existingPod); err != nil {
 | 
											pm.setError(err)
 | 
				
			||||||
					pm.setError(err)
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user