From e8ba20fc9201c6081455276df39556450b2c2d41 Mon Sep 17 00:00:00 2001 From: Drew Bailey <2614075+drewbailey@users.noreply.github.com> Date: Tue, 3 Dec 2019 08:58:29 -0500 Subject: [PATCH] allow only positive shutdown delay --- client/allocrunner/alloc_runner_test.go | 2 +- .../allocrunner/interfaces/runner_lifecycle.go | 16 +++++++++------- nomad/structs/structs.go | 6 +++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/client/allocrunner/alloc_runner_test.go b/client/allocrunner/alloc_runner_test.go index 8aaba67b4d5..1c44639830a 100644 --- a/client/allocrunner/alloc_runner_test.go +++ b/client/allocrunner/alloc_runner_test.go @@ -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] @@ -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) diff --git a/client/allocrunner/interfaces/runner_lifecycle.go b/client/allocrunner/interfaces/runner_lifecycle.go index f0b2e6c74fa..33713b2c100 100644 --- a/client/allocrunner/interfaces/runner_lifecycle.go +++ b/client/allocrunner/interfaces/runner_lifecycle.go @@ -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. @@ -53,10 +62,3 @@ type ShutdownHook interface { Shutdown() } - -// -type RunnerPreKillHook interface { - RunnerHook - - PreKill() -} diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 80253a36352..ef6f67d19c8 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -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 < 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,