Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Support Weight for NodeOrder Plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
thandayuthapani committed Mar 13, 2019
1 parent 1512f6e commit 6421a63
Showing 1 changed file with 92 additions and 4 deletions.
96 changes: 92 additions & 4 deletions pkg/scheduler/plugins/nodeorder/nodeorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package nodeorder

import (
"fmt"
"strconv"

"github.com/golang/glog"

Expand Down Expand Up @@ -155,9 +156,92 @@ func (pp *nodeOrderPlugin) Name() string {
return "nodeorder"
}

type priorityWeight struct {
leastReqWeight int
nodeAffinityWeight int
podAffinityWeight int
balancedRescourceWeight int
}

func calculateWeight(args map[string]string) priorityWeight {
/*
User Should give priorityWeight in this format(nodeaffinity.weight, podaffinity.weight, leastrequested.weight, balancedresource.weight).
Currently supported only for nodeaffinity, podaffinity, leastrequested, balancedresouce priorities.
actions: "reclaim, allocate, backfill, preempt"
tiers:
- plugins:
- name: priority
- name: gang
- name: conformance
- plugins:
- name: drf
- name: predicates
- name: proportion
- name: nodeorder
arguments:
nodeaffinity.weight: 2
podaffinity.weight: 2
leastrequested.weight: 2
balancedresource.weight: 2
*/

// Values are initialized to 1.
weight := priorityWeight{
leastReqWeight: 1,
nodeAffinityWeight: 1,
podAffinityWeight: 1,
balancedRescourceWeight: 1,
}

// Checks whether nodeaffinity.weight is provided or not, if given, modifies the value in weight struct.
if args["nodeaffinity.weight"] != "" {
val, err := strconv.Atoi(args["nodeaffinity.weight"])
if err != nil {
glog.Warningf("Not able to Parse Weight for %v because of error: %v", args["nodeaffinity.weight"], err)
} else {
weight.nodeAffinityWeight = val
}
}

// Checks whether podaffinity.weight is provided or not, if given, modifies the value in weight struct.
if args["podaffinity.weight"] != "" {
val, err := strconv.Atoi(args["podaffinity.weight"])
if err != nil {
glog.Warningf("Not able to Parse Weight for %v because of error: %v", args["podaffinity.weight"], err)
} else {
weight.podAffinityWeight = val
}
}

// Checks whether leastrequested.weight is provided or not, if given, modifies the value in weight struct.
if args["leastrequested.weight"] != "" {
val, err := strconv.Atoi(args["leastrequested.weight"])
if err != nil {
glog.Warningf("Not able to Parse Weight for %v because of error: %v", args["leastrequested.weight"], err)
} else {
weight.leastReqWeight = val
}
}

// Checks whether balancedresource.weight is provided or not, if given, modifies the value in weight struct.
if args["balancedresource.weight"] != "" {
val, err := strconv.Atoi(args["balancedresource.weight"])
if err != nil {
glog.Warningf("Not able to Parse Weight for %v because of error: %v", args["balancedresource.weight"], err)
} else {
weight.balancedRescourceWeight = val
}
}

return weight
}

func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
nodeOrderFn := func(task *api.TaskInfo, node *api.NodeInfo) (int, error) {

weight := calculateWeight(pp.pluginArguments)

pl := &podLister{
session: ssn,
}
Expand Down Expand Up @@ -188,21 +272,24 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
glog.Warningf("Least Requested Priority Failed because of Error: %v", err)
return 0, err
}
score = score + host.Score
// If leastReqWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
score = score + (host.Score * weight.leastReqWeight)

host, err = priorities.BalancedResourceAllocationMap(task.Pod, nil, nodeInfo)
if err != nil {
glog.Warningf("Balanced Resource Allocation Priority Failed because of Error: %v", err)
return 0, err
}
score = score + host.Score
// If balancedRescourceWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
score = score + (host.Score * weight.balancedRescourceWeight)

host, err = priorities.CalculateNodeAffinityPriorityMap(task.Pod, nil, nodeInfo)
if err != nil {
glog.Warningf("Calculate Node Affinity Priority Failed because of Error: %v", err)
return 0, err
}
score = score + host.Score
// If nodeAffinityWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
score = score + (host.Score * weight.nodeAffinityWeight)

mapFn := priorities.NewInterPodAffinityPriority(cn, nl, pl, v1.DefaultHardPodAffinitySymmetricWeight)
interPodAffinityScore, err = mapFn(task.Pod, nodeMap, nodeSlice)
Expand All @@ -211,7 +298,8 @@ func (pp *nodeOrderPlugin) OnSessionOpen(ssn *framework.Session) {
return 0, err
}
hostScore := getInterPodAffinityScore(node.Name, interPodAffinityScore)
score = score + hostScore
// If podAffinityWeight in provided, host.Score is multiplied with weight, if not, host.Score is added to total score.
score = score + (hostScore * weight.podAffinityWeight)

glog.V(4).Infof("Total Score for that node is: %d", score)
return score, nil
Expand Down

0 comments on commit 6421a63

Please sign in to comment.