Skip to content

Commit

Permalink
Merge pull request #790 from jiangkaihua/release-0.4
Browse files Browse the repository at this point in the history
Add bestNodeFn for plugins to select best node of its own.
  • Loading branch information
volcano-sh-bot authored May 7, 2020
2 parents 60d5e99 + 068ca75 commit 32cca6b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pkg/scheduler/actions/allocate/allocate.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ func (alloc *allocateAction) Execute(ssn *framework.Session) {

nodeScores := util.PrioritizeNodes(task, candidateNodes, ssn.BatchNodeOrderFn, ssn.NodeOrderMapFn, ssn.NodeOrderReduceFn)

node := util.SelectBestNode(nodeScores)
node := ssn.BestNodeFn(task, nodeScores)
if node == nil {
node = util.SelectBestNode(nodeScores)
}

// Allocate idle resource to the task.
if task.InitResreq.LessEqual(node.Idle) {
klog.V(3).Infof("Binding Task <%v/%v> to node <%v>",
Expand Down
7 changes: 5 additions & 2 deletions pkg/scheduler/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,22 @@ type CompareFn func(interface{}, interface{}) int
// ValidateFn is the func declaration used to check object's status.
type ValidateFn func(interface{}) bool

// ValidateResult is struct to which can used to determine the result
// ValidateResult is struct to which can used to determine the result.
type ValidateResult struct {
Pass bool
Reason string
Message string
}

// ValidateExFn is the func declaration used to validate the result
// ValidateExFn is the func declaration used to validate the result.
type ValidateExFn func(interface{}) *ValidateResult

// PredicateFn is the func declaration used to predicate node for task.
type PredicateFn func(*TaskInfo, *NodeInfo) error

// BestNodeFn is the func declaration used to return the nodeScores to plugins.
type BestNodeFn func(*TaskInfo, map[float64][]*NodeInfo) *NodeInfo

// EvictableFn is the func declaration used to evict tasks.
type EvictableFn func(*TaskInfo, []*TaskInfo) []*TaskInfo

Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/conf/scheduler_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ type PluginOption struct {
EnabledQueueOrder *bool `yaml:"enableQueueOrder"`
// EnabledPredicate defines whether predicateFn is enabled
EnabledPredicate *bool `yaml:"enablePredicate"`
// EnabledBestNode defines whether bestNodeFn is enabled
EnabledBestNode *bool `yaml:"enableBestNode"`
// EnabledNodeOrder defines whether NodeOrderFn is enabled
EnabledNodeOrder *bool `yaml:"enableNodeOrder"`
// Arguments defines the different arguments that can be given to different plugins
Expand Down
2 changes: 2 additions & 0 deletions pkg/scheduler/framework/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type Session struct {
taskOrderFns map[string]api.CompareFn
namespaceOrderFns map[string]api.CompareFn
predicateFns map[string]api.PredicateFn
bestNodeFns map[string]api.BestNodeFn
nodeOrderFns map[string]api.NodeOrderFn
batchNodeOrderFns map[string]api.BatchNodeOrderFn
nodeMapFns map[string]api.NodeMapFn
Expand Down Expand Up @@ -86,6 +87,7 @@ func openSession(cache cache.Cache) *Session {
taskOrderFns: map[string]api.CompareFn{},
namespaceOrderFns: map[string]api.CompareFn{},
predicateFns: map[string]api.PredicateFn{},
bestNodeFns: map[string]api.BestNodeFn{},
nodeOrderFns: map[string]api.NodeOrderFn{},
batchNodeOrderFns: map[string]api.BatchNodeOrderFn{},
nodeMapFns: map[string]api.NodeMapFn{},
Expand Down
25 changes: 25 additions & 0 deletions pkg/scheduler/framework/session_plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func (ssn *Session) AddPredicateFn(name string, pf api.PredicateFn) {
ssn.predicateFns[name] = pf
}

// AddBestNodeFn add BestNode function
func (ssn *Session) AddBestNodeFn(name string, pf api.BestNodeFn) {
ssn.bestNodeFns[name] = pf
}

// AddNodeOrderFn add Node order function
func (ssn *Session) AddNodeOrderFn(name string, pf api.NodeOrderFn) {
ssn.nodeOrderFns[name] = pf
Expand Down Expand Up @@ -419,6 +424,26 @@ func (ssn *Session) PredicateFn(task *api.TaskInfo, node *api.NodeInfo) error {
return nil
}

// BestNodeFn invoke bestNode function of the plugins
func (ssn *Session) BestNodeFn(task *api.TaskInfo, nodeScores map[float64][]*api.NodeInfo) *api.NodeInfo {
for _, tier := range ssn.Tiers {
for _, plugin := range tier.Plugins {
if !isEnabled(plugin.EnabledBestNode) {
continue
}
pfn, found := ssn.bestNodeFns[plugin.Name]
if !found {
continue
}
// Only the first plugin that enables and realizes bestNodeFn is allowed to choose best node for task
if bestNode := pfn(task, nodeScores); bestNode != nil {
return bestNode
}
}
}
return nil
}

// NodeOrderFn invoke node order function of the plugins
func (ssn *Session) NodeOrderFn(task *api.TaskInfo, node *api.NodeInfo) (float64, error) {
priorityScore := 0.0
Expand Down

0 comments on commit 32cca6b

Please sign in to comment.