Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scheduler: fix panic in render_templates destructive update check #18100

Merged
merged 1 commit into from
Jul 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions scheduler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,9 @@ 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,
"group restart render_templates"); c.modified {
return c
}

// Check each task
Expand Down Expand Up @@ -327,9 +328,11 @@ func tasksUpdated(jobA, jobB *structs.Job, taskGroup string) comparison {
}

// Check if restart.render_templates is updated
if at.RestartPolicy.RenderTemplates != bt.RestartPolicy.RenderTemplates {
return difference("task restart render_templates", at.RestartPolicy.RenderTemplates, bt.RestartPolicy.RenderTemplates)
if c := renderTemplatesUpdated(at.RestartPolicy, bt.RestartPolicy,
"task restart render_templates"); c.modified {
return c
}

}

// none of the fields that trigger a destructive update were modified,
Expand Down Expand Up @@ -574,6 +577,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, msg string) comparison {

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

if noRenderA && !noRenderB {
return difference(msg, false, true)
}
if !noRenderA && noRenderB {
return difference(msg, 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