diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 14dcc3c94..0e5012193 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -9831,17 +9831,13 @@ func (p *Plan) PopUpdate(alloc *Allocation) { } // AppendAlloc appends the alloc to the plan allocations. -// To save space, it clears the Job field so it can be derived from the plan Job. -// If keepJob is true, the normalizatin skipped to accommodate cases where a plan -// needs to support multiple versions of the same job. -func (p *Plan) AppendAlloc(alloc *Allocation, keepJob bool) { +// Uses the passed job if explicitly passed, otherwise +// it is assumed the alloc will use the plan Job version. +func (p *Plan) AppendAlloc(alloc *Allocation, job *Job) { node := alloc.NodeID existing := p.NodeAllocation[node] - // Normalize the job - if !keepJob { - alloc.Job = nil - } + alloc.Job = job p.NodeAllocation[node] = append(existing, alloc) } diff --git a/scheduler/generic_sched.go b/scheduler/generic_sched.go index bc48dbf5c..ee51fcb6a 100644 --- a/scheduler/generic_sched.go +++ b/scheduler/generic_sched.go @@ -388,12 +388,12 @@ func (s *GenericScheduler) computeJobAllocs() error { update.DeploymentID = s.deployment.GetID() update.DeploymentStatus = nil } - s.ctx.Plan().AppendAlloc(update, false) + s.ctx.Plan().AppendAlloc(update, nil) } // Handle the annotation updates for _, update := range results.attributeUpdates { - s.ctx.Plan().AppendAlloc(update, false) + s.ctx.Plan().AppendAlloc(update, nil) } // Nothing remaining to do if placement is not required @@ -601,14 +601,10 @@ func (s *GenericScheduler) computePlacements(destructive, place []placementResul } } - if downgradedJob != nil { - alloc.Job = downgradedJob - } - s.handlePreemptions(option, alloc, missing) // Track the placement - s.plan.AppendAlloc(alloc, downgradedJob != nil) + s.plan.AppendAlloc(alloc, downgradedJob) } else { // Lazy initialize the failed map diff --git a/scheduler/system_sched.go b/scheduler/system_sched.go index c0fe396b7..f8088b02a 100644 --- a/scheduler/system_sched.go +++ b/scheduler/system_sched.go @@ -398,7 +398,7 @@ func (s *SystemScheduler) computePlacements(place []allocTuple) error { alloc.PreemptedAllocations = preemptedAllocIDs } - s.plan.AppendAlloc(alloc, false) + s.plan.AppendAlloc(alloc, nil) } return nil diff --git a/scheduler/util.go b/scheduler/util.go index b465efb19..1799ede53 100644 --- a/scheduler/util.go +++ b/scheduler/util.go @@ -655,7 +655,7 @@ func inplaceUpdate(ctx Context, eval *structs.Evaluation, job *structs.Job, }, } newAlloc.Metrics = ctx.Metrics() - ctx.Plan().AppendAlloc(newAlloc, false) + ctx.Plan().AppendAlloc(newAlloc, nil) // Remove this allocation from the slice doInplace(&i, &n, &inplaceCount)