Skip to content

Commit

Permalink
Backport of Prevent kill_timeout greater than progress_deadline into …
Browse files Browse the repository at this point in the history
…release/1.4.x (#17205)

* test: fix TestJobEndpoint_Scale_BatchJob

* Prevent kill_timeout greater than progress_deadline  (#16761)

* func: add validation for kill timeout smaller than progress dealine

* style: add changelog

* style: typo in changelog

* style: remove refactored test

* Update .changelog/16761.txt

Co-authored-by: James Rasell <jrasell@users.noreply.github.com>

* Update nomad/structs/structs.go

Co-authored-by: James Rasell <jrasell@users.noreply.github.com>

---------

Co-authored-by: James Rasell <jrasell@users.noreply.github.com>

---------

Co-authored-by: Luiz Aoqui <luiz@hashicorp.com>
Co-authored-by: Juana De La Cuesta <juanita.delacuestamorales@hashicorp.com>
Co-authored-by: James Rasell <jrasell@users.noreply.github.com>
  • Loading branch information
4 people committed May 16, 2023
1 parent 6ad39fe commit c7ad698
Show file tree
Hide file tree
Showing 3 changed files with 427 additions and 328 deletions.
3 changes: 3 additions & 0 deletions .changelog/16761.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
core: Prevent `task.kill_timeout` being greater than `update.progress_deadline`
```
17 changes: 17 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4972,6 +4972,12 @@ func (u *UpdateStrategy) IsEmpty() bool {
return true
}

// When the Job is transformed from api to struct, the Update Strategy block is
// copied into the existing task groups, the only things that are passed along
// are MaxParallel and Stagger, because they are enforced at job level.
// That is why checking if MaxParallel is zero is enough to know if the
// update block is empty.

return u.MaxParallel == 0
}

Expand Down Expand Up @@ -6540,6 +6546,8 @@ func (tg *TaskGroup) Validate(j *Job) error {
mErr.Errors = append(mErr.Errors, outer)
}

isTypeService := j.Type == JobTypeService

// Validate the tasks
for _, task := range tg.Tasks {
// Validate the task does not reference undefined volume mounts
Expand All @@ -6559,6 +6567,15 @@ func (tg *TaskGroup) Validate(j *Job) error {
outer := fmt.Errorf("Task %s validation failed: %v", task.Name, err)
mErr.Errors = append(mErr.Errors, outer)
}

// Validate the group's Update Strategy does not conflict with the Task's kill_timeout for service type jobs
if isTypeService && tg.Update != nil {
if task.KillTimeout > tg.Update.ProgressDeadline {
mErr.Errors = append(mErr.Errors, fmt.Errorf("Task %s has a kill timout (%s) longer than the group's progress deadline (%s)",
task.Name, task.KillTimeout.String(), tg.Update.ProgressDeadline.String()))
}
}

}

return mErr.ErrorOrNil()
Expand Down
Loading

0 comments on commit c7ad698

Please sign in to comment.