Skip to content

Commit

Permalink
func: add validation for kill timeout smaller than progress dealine
Browse files Browse the repository at this point in the history
  • Loading branch information
Juanadelacuesta committed Apr 4, 2023
1 parent 6b64b20 commit 49d265b
Show file tree
Hide file tree
Showing 2 changed files with 485 additions and 66 deletions.
17 changes: 17 additions & 0 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5136,6 +5136,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 cero is enough to know if the
// update block is empty.

return u.MaxParallel == 0
}

Expand Down Expand Up @@ -6708,6 +6714,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 @@ -6727,6 +6735,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 49d265b

Please sign in to comment.