Merge pull request #28672 from ping035627/ping035627-patch-0708

Automatic merge from submit-queue

Inspect the nodeInfo first for CheckServiceAffinity in predicates.go

Suggest to inspect the nodeInfo first for CheckServiceAffinity in predicates.go. When nodeInfo.Node() is nil, return quickly.
This commit is contained in:
k8s-merge-robot 2016-07-10 21:17:37 -07:00 committed by GitHub
commit 1c535008ca

View File

@ -666,6 +666,11 @@ func NewServiceAffinityPredicate(podLister algorithm.PodLister, serviceLister al
// - the pod does not have any NodeSelector for L
// - some other pod from the same service is already scheduled onto a node that has value V for label L
func (s *ServiceAffinity) CheckServiceAffinity(pod *api.Pod, meta interface{}, nodeInfo *schedulercache.NodeInfo) (bool, error) {
node := nodeInfo.Node()
if node == nil {
return false, fmt.Errorf("node not found")
}
var affinitySelector labels.Selector
// check if the pod being scheduled has the affinity labels specified in its NodeSelector
@ -725,11 +730,6 @@ func (s *ServiceAffinity) CheckServiceAffinity(pod *api.Pod, meta interface{}, n
affinitySelector = labels.Set(affinityLabels).AsSelector()
}
node := nodeInfo.Node()
if node == nil {
return false, fmt.Errorf("node not found")
}
// check if the node matches the selector
if affinitySelector.Matches(labels.Set(node.Labels)) {
return true, nil