Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Few more optimizations of priority functions in scheduler #28958

Merged
merged 1 commit into from
Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 21 additions & 18 deletions plugin/pkg/scheduler/algorithm/priorities/priorities.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
var score int
nodes, err := nodeLister.List()
if err != nil {
return nil, err
}

result := []schedulerapi.HostPriority{}

// TODO: Once we have ownerReference fully implemented, use it to find controller for the pod.
rcs, err := npa.controllerLister.GetPodControllers(pod)
rss, err := npa.replicaSetLister.GetPodReplicaSets(pod)
if len(rcs) == 0 && len(rss) == 0 {
result := make(schedulerapi.HostPriorityList, 0, len(nodes))
for _, node := range nodes {
result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: 10})
}
return result, nil
}

avoidNodes := map[string]bool{}
avoidNodes := make(map[string]bool, len(nodes))
avoidNode := false
for _, node := range nodes {
avoidNodes[node.Name] = false

avoids, err := api.GetAvoidPodsFromNodeAnnotations(node.Annotations)
if err != nil {
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 {
if avoid.PodSignature.PodController.Kind == "ReplicationController" && avoid.PodSignature.PodController.UID == rc.UID {
avoidNodes[node.Name] = true
break
avoidNode = true
}
}
if avoidNodes[node.Name] {
break
}
for _, rs := range rss {
if avoid.PodSignature.PodController.Kind == "ReplicaSet" && avoid.PodSignature.PodController.UID == rs.UID {
avoidNodes[node.Name] = true
break
avoidNode = true
}
}
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
}
}
}

var score int
result := make(schedulerapi.HostPriorityList, 0, len(nodes))
//score int - scale of 0-10
// 0 being the lowest priority and 10 being the highest
for nodeName, shouldAvoid := range avoidNodes {
if shouldAvoid {
for _, node := range nodes {
if avoidNodes[node.Name] {
score = 0
} else {
score = 10
}
result = append(result, schedulerapi.HostPriority{Host: nodeName, Score: score})
result = append(result, schedulerapi.HostPriority{Host: node.Name, Score: score})
}
return result, nil
}
9 changes: 6 additions & 3 deletions plugin/pkg/scheduler/algorithm/priorities/taint_toleration.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,12 @@ func ComputeTaintTolerationPriority(pod *api.Pod, nodeNameToInfo map[string]*sch
}

count := countIntolerableTaintsPreferNoSchedule(taints, tolerationList)
counts[node.Name] = count
if count > maxCount {
maxCount = count
if count > 0 {
// 0 is default value, so avoid unnecessary map operations.
counts[node.Name] = count
if count > maxCount {
maxCount = count
}
}
}

Expand Down