pospt prep
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package conf
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
KubeHost string
|
||||
@@ -8,6 +11,17 @@ type Config struct {
|
||||
KubeCA string
|
||||
KubeCert string
|
||||
KubeData string
|
||||
// PrepLeadSeconds must match oc-schedulerd's PREP_LEAD_SECONDS.
|
||||
// Used both as the ASAP buffer and as the minimum allowed lead time
|
||||
// when validating explicit booking start dates.
|
||||
PrepLeadSeconds int
|
||||
}
|
||||
|
||||
func (c *Config) PrepLead() time.Duration {
|
||||
if c.PrepLeadSeconds <= 0 {
|
||||
return 2 * time.Minute
|
||||
}
|
||||
return time.Duration(c.PrepLeadSeconds) * time.Second
|
||||
}
|
||||
|
||||
var instance *Config
|
||||
|
||||
@@ -3,6 +3,7 @@ package scheduler
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"oc-scheduler/conf"
|
||||
"oc-scheduler/infrastructure/planner"
|
||||
"oc-scheduler/infrastructure/scheduling_resources"
|
||||
infUtils "oc-scheduler/infrastructure/utils"
|
||||
@@ -20,8 +21,6 @@ import (
|
||||
"github.com/robfig/cron"
|
||||
)
|
||||
|
||||
const asapBuffer = 2 * time.Minute
|
||||
|
||||
// Schedule holds a resolved start/end pair for a single execution slot.
|
||||
type Schedule struct {
|
||||
Start time.Time
|
||||
@@ -80,9 +79,18 @@ func (ws *WorkflowSchedule) Check(wfID string, asap bool, preemption bool, reque
|
||||
}
|
||||
wf := obj.(*workflow.Workflow)
|
||||
|
||||
prepLead := conf.GetConfig().PrepLead()
|
||||
start := ws.Start
|
||||
if asap || start.IsZero() {
|
||||
start = time.Now().UTC().Add(asapBuffer)
|
||||
start = time.Now().UTC().Add(prepLead)
|
||||
} else if start.Before(time.Now().UTC().Add(prepLead)) {
|
||||
// Explicit date is within the prep window — impossible to guarantee on time.
|
||||
return nil, fmt.Errorf(
|
||||
"start date %s is too soon: minimum lead time is %s (earliest: %s)",
|
||||
start.Format(time.RFC3339),
|
||||
prepLead,
|
||||
time.Now().UTC().Add(prepLead).Format(time.RFC3339),
|
||||
)
|
||||
}
|
||||
|
||||
end := ws.End
|
||||
|
||||
1
main.go
1
main.go
@@ -13,6 +13,7 @@ const appname = "oc-scheduler"
|
||||
|
||||
func main() {
|
||||
o := oclib.GetConfLoader(appname)
|
||||
conf.GetConfig().PrepLeadSeconds = o.GetIntDefault("PREP_LEAD_SECONDS", 120)
|
||||
conf.GetConfig().KubeHost = o.GetStringDefault("KUBERNETES_SERVICE_HOST", "kubernetes.default.svc.cluster.local")
|
||||
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user