From 0dc407cfe33891d0433db7bf90bdffa9d82b4052 Mon Sep 17 00:00:00 2001 From: Seth Hoenig Date: Mon, 4 Jan 2021 13:03:51 -0600 Subject: [PATCH] consul: always include task services hook Previously, Nomad would optimize out the services task runner hook for tasks which were initially submitted with no services defined. This causes a problem when the job is later updated to include service(s) on that task, which will result in nothing happening because the hook is not present to handle the service registration in the .Update. Instead, always enable the services hook. The group services alloc runner hook is already always enabled. Fixes #9707 --- .../taskrunner/task_runner_hooks.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/client/allocrunner/taskrunner/task_runner_hooks.go b/client/allocrunner/taskrunner/task_runner_hooks.go index dea3d53fbc1..7a86adc7f50 100644 --- a/client/allocrunner/taskrunner/task_runner_hooks.go +++ b/client/allocrunner/taskrunner/task_runner_hooks.go @@ -101,16 +101,15 @@ func (tr *TaskRunner) initHooks() { })) } - // If there are any services, add the service hook - if len(task.Services) != 0 { - tr.runnerHooks = append(tr.runnerHooks, newServiceHook(serviceHookConfig{ - alloc: tr.Alloc(), - task: tr.Task(), - consul: tr.consulServiceClient, - restarter: tr, - logger: hookLogger, - })) - } + // Always add the service hook. A task with no services on initial registration + // may be updated to include services, which must be handled with this hook. + tr.runnerHooks = append(tr.runnerHooks, newServiceHook(serviceHookConfig{ + alloc: tr.Alloc(), + task: tr.Task(), + consul: tr.consulServiceClient, + restarter: tr, + logger: hookLogger, + })) // If this is a Connect sidecar proxy (or a Connect Native) service, // add the sidsHook for requesting a Service Identity token (if ACLs).