From f8a6e69ef37aabad3e4ed54e4617d1dce668f64d Mon Sep 17 00:00:00 2001 From: mr Date: Thu, 26 Mar 2026 11:15:02 +0100 Subject: [PATCH] pospt prep --- conf/config.go | 26 ++++++++++++++++++++------ infrastructure/scheduler/scheduler.go | 14 +++++++++++--- main.go | 1 + 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/conf/config.go b/conf/config.go index 5462548..161abb6 100644 --- a/conf/config.go +++ b/conf/config.go @@ -1,13 +1,27 @@ package conf -import "sync" +import ( + "sync" + "time" +) type Config struct { - KubeHost string - KubePort string - KubeCA string - KubeCert string - KubeData string + KubeHost string + KubePort string + 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 diff --git a/infrastructure/scheduler/scheduler.go b/infrastructure/scheduler/scheduler.go index d7ff695..cd325d2 100644 --- a/infrastructure/scheduler/scheduler.go +++ b/infrastructure/scheduler/scheduler.go @@ -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 diff --git a/main.go b/main.go index 9642a68..2f3f620 100644 --- a/main.go +++ b/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")