Skip to content

Commit

Permalink
Support JobReady for extender plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxubeii committed Jul 6, 2022
1 parent 9698fbb commit 74c55df
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/scheduler/plugins/extender/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ type QueueOverusedRequest struct {
type QueueOverusedResponse struct {
Overused bool `json:"overused"`
}

type JobReadyRequest struct {
Job *api.JobInfo `json:"job"`
}

type JobReadyResponse struct {
Status bool `json:"status"`
}
19 changes: 19 additions & 0 deletions pkg/scheduler/plugins/extender/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const (
ExtenderQueueOverusedVerb = "extender.queueOverusedVerb"
// ExtenderJobEnqueueableVerb is the verb of JobEnqueueable method
ExtenderJobEnqueueableVerb = "extender.jobEnqueueableVerb"
// ExtenderJobReadyVerb is the verb of JobReady method
ExtenderJobReadyVerb = "extender.jobReadyVerb"
// ExtenderIgnorable indicates whether the extender can ignore unexpected errors
ExtenderIgnorable = "extender.ignorable"
)
Expand All @@ -69,6 +71,7 @@ type extenderConfig struct {
reclaimableVerb string
queueOverusedVerb string
jobEnqueueableVerb string
jobReadyVerb string
ignorable bool
}

Expand Down Expand Up @@ -114,6 +117,7 @@ func parseExtenderConfig(arguments framework.Arguments) *extenderConfig {
ec.reclaimableVerb, _ = arguments[ExtenderReclaimableVerb].(string)
ec.queueOverusedVerb, _ = arguments[ExtenderQueueOverusedVerb].(string)
ec.jobEnqueueableVerb, _ = arguments[ExtenderJobEnqueueableVerb].(string)
ec.jobReadyVerb, _ = arguments[ExtenderJobReadyVerb].(string)

arguments.GetBool(&ec.ignorable, ExtenderIgnorable)

Expand Down Expand Up @@ -260,6 +264,21 @@ func (ep *extenderPlugin) OnSessionOpen(ssn *framework.Session) {
return resp.Overused
})
}

if ep.config.jobReadyVerb != "" {
ssn.AddJobReadyFn(ep.Name(), func(obj interface{}) bool {
job := obj.(*api.JobInfo)
resp := &JobReadyResponse{}
err := ep.send(ep.config.jobReadyVerb, &JobReadyRequest{Job: job}, resp)
if err != nil {
klog.Warningf("JobReady failed with error %v", err)

return !ep.config.ignorable
}

return resp.Status
})
}
}

func (ep *extenderPlugin) OnSessionClose(ssn *framework.Session) {
Expand Down

0 comments on commit 74c55df

Please sign in to comment.