pospt prep
This commit is contained in:
@@ -1,13 +1,27 @@
|
|||||||
package conf
|
package conf
|
||||||
|
|
||||||
import "sync"
|
import (
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
KubeHost string
|
KubeHost string
|
||||||
KubePort string
|
KubePort string
|
||||||
KubeCA string
|
KubeCA string
|
||||||
KubeCert string
|
KubeCert string
|
||||||
KubeData 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
|
var instance *Config
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package scheduler
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"oc-scheduler/conf"
|
||||||
"oc-scheduler/infrastructure/planner"
|
"oc-scheduler/infrastructure/planner"
|
||||||
"oc-scheduler/infrastructure/scheduling_resources"
|
"oc-scheduler/infrastructure/scheduling_resources"
|
||||||
infUtils "oc-scheduler/infrastructure/utils"
|
infUtils "oc-scheduler/infrastructure/utils"
|
||||||
@@ -20,8 +21,6 @@ import (
|
|||||||
"github.com/robfig/cron"
|
"github.com/robfig/cron"
|
||||||
)
|
)
|
||||||
|
|
||||||
const asapBuffer = 2 * time.Minute
|
|
||||||
|
|
||||||
// Schedule holds a resolved start/end pair for a single execution slot.
|
// Schedule holds a resolved start/end pair for a single execution slot.
|
||||||
type Schedule struct {
|
type Schedule struct {
|
||||||
Start time.Time
|
Start time.Time
|
||||||
@@ -80,9 +79,18 @@ func (ws *WorkflowSchedule) Check(wfID string, asap bool, preemption bool, reque
|
|||||||
}
|
}
|
||||||
wf := obj.(*workflow.Workflow)
|
wf := obj.(*workflow.Workflow)
|
||||||
|
|
||||||
|
prepLead := conf.GetConfig().PrepLead()
|
||||||
start := ws.Start
|
start := ws.Start
|
||||||
if asap || start.IsZero() {
|
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
|
end := ws.End
|
||||||
|
|||||||
1
main.go
1
main.go
@@ -13,6 +13,7 @@ const appname = "oc-scheduler"
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
o := oclib.GetConfLoader(appname)
|
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().KubeHost = o.GetStringDefault("KUBERNETES_SERVICE_HOST", "kubernetes.default.svc.cluster.local")
|
||||||
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
|
conf.GetConfig().KubePort = o.GetStringDefault("KUBERNETES_SERVICE_PORT", "6443")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user