Skip to content

Commit

Permalink
allow only positive shutdown delay
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbailey committed Dec 3, 2019
1 parent c8f05a8 commit 2381202
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion client/allocrunner/alloc_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func TestAllocRunner_TaskLeader_KillTG(t *testing.T) {

func TestAllocRunner_TaskGroup_ShutdownDelay(t *testing.T) {
t.Parallel()
shutdownDelay := 1 * time.Second

alloc := mock.Alloc()
tr := alloc.AllocatedResources.Tasks[alloc.Job.TaskGroups[0].Tasks[0].Name]
Expand All @@ -170,6 +169,7 @@ func TestAllocRunner_TaskGroup_ShutdownDelay(t *testing.T) {
alloc.AllocatedResources.Tasks[task2.Name] = tr

// Set a shutdown delay
shutdownDelay := 1 * time.Second
alloc.Job.TaskGroups[0].ShutdownDelay = &shutdownDelay

conf, cleanup := testAllocRunnerConfig(t, alloc)
Expand Down
16 changes: 9 additions & 7 deletions client/allocrunner/interfaces/runner_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ type RunnerPrerunHook interface {
Prerun() error
}

// RunnerPreKillHooks are executed inside of KillTasks before
// iterating and killing each task. It will run before the Leader
// task is killed.
type RunnerPreKillHook interface {
RunnerHook

PreKill()
}

// RunnerPostrunHooks are executed after calling TaskRunner.Run, even for
// terminal allocations. Therefore Postrun hooks must be safe to call without
// first calling Prerun hooks.
Expand Down Expand Up @@ -53,10 +62,3 @@ type ShutdownHook interface {

Shutdown()
}

//
type RunnerPreKillHook interface {
RunnerHook

PreKill()
}
6 changes: 3 additions & 3 deletions nomad/structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3547,9 +3547,9 @@ func (j *Job) Validate() error {
taskGroups[tg.Name] = idx
}

// if tg.ShutdownDelay < 0 {
// mErr.Errors = append(mErr.Errors, errors.New("ShutdownDelay must be a positive value"))
// }
if tg.ShutdownDelay != nil && *tg.ShutdownDelay < 0 {
mErr.Errors = append(mErr.Errors, errors.New("ShutdownDelay must be a positive value"))
}

if j.Type == "system" && tg.Count > 1 {
mErr.Errors = append(mErr.Errors,
Expand Down

0 comments on commit 2381202

Please sign in to comment.