Skip to content

Commit

Permalink
scheduler: fix panic in render_templates destructive update check
Browse files Browse the repository at this point in the history
In #18054 we introduced a new field `render_templates` in the `restart`
block. Previously changes to the `restart` block were always non-destructive in
the scheduler but we now need to check the new field so that we can update the
template runner. The check assumed that the block was always non-nil, which
causes panics in our scheduler tests.
  • Loading branch information
tgross committed Jul 31, 2023
1 parent 9e98d69 commit 1468413
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) comparison {

// Check if restart.render_templates is updated
// this requires a destructive update for template hook to receive the new config
if a.RestartPolicy.RenderTemplates != b.RestartPolicy.RenderTemplates {
return difference("group restart render_templates", a.RestartPolicy.RenderTemplates, b.RestartPolicy.RenderTemplates)
if c := renderTemplatesUpdated(a.RestartPolicy, b.RestartPolicy); c.modified {
return c
}

// Check each task
Expand Down Expand Up @@ -574,6 +574,23 @@ func spreadsUpdated(jobA, jobB *structs.Job, taskGroup string) comparison {
return same
}

// renderTemplatesUpdated returns the difference in the RestartPolicy's
// render_templates field, if set
func renderTemplatesUpdated(a, b *structs.RestartPolicy) comparison {

noRenderA := a == nil || !a.RenderTemplates
noRenderB := b == nil || !b.RenderTemplates

if noRenderA && !noRenderB {
return difference("group restart render_templates", false, true)
}
if !noRenderA && noRenderB {
return difference("group restart render_templates", true, false)
}

return same // both nil, or one nil and the other false
}

// setStatus is used to update the status of the evaluation
func setStatus(logger log.Logger, planner Planner,
eval, nextEval, spawnedBlocked *structs.Evaluation,
Expand Down

0 comments on commit 1468413

Please sign in to comment.