From 30107e9ed62aece14d0332c752044d7f4ff1117d Mon Sep 17 00:00:00 2001 From: Albin Severinson Date: Mon, 26 Jun 2023 16:09:06 +0100 Subject: [PATCH 1/3] Initialise nodeSelector/annotations --- internal/scheduler/jobdb/job.go | 14 ++++++++++++++ .../scheduler/preempting_queue_scheduler.go | 17 +++-------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/internal/scheduler/jobdb/job.go b/internal/scheduler/jobdb/job.go index 7a2a002df26..519fce9d495 100644 --- a/internal/scheduler/jobdb/job.go +++ b/internal/scheduler/jobdb/job.go @@ -71,6 +71,20 @@ func NewJob( cancelled bool, created int64, ) *Job { + // Initialise the annotation and nodeSelector maps if nil. + // Since those need to be mutated in-place. + if schedulingInfo != nil { + for _, req := range schedulingInfo.ObjectRequirements { + if podReq := req.GetPodRequirements(); podReq != nil { + if podReq.Annotations == nil { + podReq.Annotations = make(map[string]string) + } + if podReq.NodeSelector == nil { + podReq.NodeSelector = make(map[string]string) + } + } + } + } return &Job{ id: jobId, jobset: jobset, diff --git a/internal/scheduler/preempting_queue_scheduler.go b/internal/scheduler/preempting_queue_scheduler.go index 3025ca87ec2..63bcb83949c 100644 --- a/internal/scheduler/preempting_queue_scheduler.go +++ b/internal/scheduler/preempting_queue_scheduler.go @@ -861,22 +861,11 @@ func defaultPostEvictFunc(ctx context.Context, job interfaces.LegacySchedulerJob } // Add node selector ensuring this job is only re-scheduled onto the node it was evicted from. - req := PodRequirementFromLegacySchedulerJob(job, nil) - if req.NodeSelector == nil { + nodeSelector := job.GetNodeSelector() + if nodeSelector == nil { log := ctxlogrus.Extract(ctx) log.Errorf("error evicting job %s: nodeSelector not initialised", job.GetId()) } else { - req.NodeSelector[schedulerconfig.NodeIdLabel] = node.Id + nodeSelector[schedulerconfig.NodeIdLabel] = node.Id } - - // Add a toleration to allow the job to be re-scheduled even if node is unschedulable. - // - // TODO: Because req is allocated by GetJobSchedulingInfo() if job is an api.Job, this toleration may not persist. - // In practice, this isn't an issue now since we don't check static requirements for evicted jobs. - if node.Unschedulable { - req.Tolerations = append(req.Tolerations, nodedb.UnschedulableToleration()) - } - - // We've changed the scheduling requirements and must clear any cached key. - req.ClearCachedSchedulingKey() } From 17994236692c2a8d6273195e31a6ea1a4ddecc2c Mon Sep 17 00:00:00 2001 From: Albin Severinson Date: Mon, 26 Jun 2023 16:13:08 +0100 Subject: [PATCH 2/3] Remove unused functions --- .../scheduler/schedulerobjects/podutils.go | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/internal/scheduler/schedulerobjects/podutils.go b/internal/scheduler/schedulerobjects/podutils.go index 287401d2826..9bd476ca99a 100644 --- a/internal/scheduler/schedulerobjects/podutils.go +++ b/internal/scheduler/schedulerobjects/podutils.go @@ -212,25 +212,6 @@ func (skg *PodRequirementsSerialiser) AppendResourceList(out []byte, resourceLis return out } -// ClearCachedSchedulingKey clears any cached scheduling keys. -// Necessary after changing scheduling requirements to avoid inconsistency. -func (jobSchedulingInfo *JobSchedulingInfo) ClearCachedSchedulingKey() { - if jobSchedulingInfo == nil { - return - } - for _, objReq := range jobSchedulingInfo.ObjectRequirements { - if req := objReq.GetPodRequirements(); req != nil { - req.ClearCachedSchedulingKey() - } - } -} - -// ClearCachedSchedulingKey clears any cached scheduling key. -// Necessary after changing scheduling requirements to avoid inconsistency. -func (req *PodRequirements) ClearCachedSchedulingKey() { - req.CachedSchedulingKey = nil -} - func lessToleration(a, b v1.Toleration) bool { if a.Key < b.Key { return true From 791956becc699bd621f2db2e11066a6ab43e4b2f Mon Sep 17 00:00:00 2001 From: Albin Severinson Date: Mon, 26 Jun 2023 16:23:00 +0100 Subject: [PATCH 3/3] Lint --- internal/scheduler/scheduler.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/internal/scheduler/scheduler.go b/internal/scheduler/scheduler.go index b3d5423af5f..3a3459506a1 100644 --- a/internal/scheduler/scheduler.go +++ b/internal/scheduler/scheduler.go @@ -344,8 +344,6 @@ func (s *Scheduler) createSchedulingInfoWithNodeAntiAffinityForAttemptedRuns(job } } podSchedulingRequirement.Affinity = newAffinity - podSchedulingRequirement.ClearCachedSchedulingKey() - return newSchedulingInfo, nil }