simplify else

This commit is contained in:
Mayank Kumar 2018-05-24 23:26:02 -07:00
parent d7c40cf69e
commit 83818ee0c8
2 changed files with 14 additions and 15 deletions

View File

@ -37,12 +37,11 @@ func CalculateNodeAffinityPriorityMap(pod *v1.Pod, meta interface{}, nodeInfo *s
return schedulerapi.HostPriority{}, fmt.Errorf("node not found") return schedulerapi.HostPriority{}, fmt.Errorf("node not found")
} }
var affinity *v1.Affinity // default is the podspec.
affinity := pod.Spec.Affinity
if priorityMeta, ok := meta.(*priorityMetadata); ok { if priorityMeta, ok := meta.(*priorityMetadata); ok {
// We were able to parse metadata, use affinity from there.
affinity = priorityMeta.affinity affinity = priorityMeta.affinity
} else {
// We couldn't parse metadata - fallback to the podspec.
affinity = pod.Spec.Affinity
} }
var count int32 var count int32

View File

@ -603,18 +603,18 @@ func (n *NodeInfo) FilterOutPods(pods []*v1.Pod) []*v1.Pod {
} }
filtered := make([]*v1.Pod, 0, len(pods)) filtered := make([]*v1.Pod, 0, len(pods))
for _, p := range pods { for _, p := range pods {
if p.Spec.NodeName == node.Name { if p.Spec.NodeName != node.Name {
// If pod is on the given node, add it to 'filtered' only if it is present in nodeInfo.
podKey, _ := getPodKey(p)
for _, np := range n.Pods() {
npodkey, _ := getPodKey(np)
if npodkey == podKey {
filtered = append(filtered, p)
break
}
}
} else {
filtered = append(filtered, p) filtered = append(filtered, p)
continue
}
// If pod is on the given node, add it to 'filtered' only if it is present in nodeInfo.
podKey, _ := getPodKey(p)
for _, np := range n.Pods() {
npodkey, _ := getPodKey(np)
if npodkey == podKey {
filtered = append(filtered, p)
break
}
} }
} }
return filtered return filtered