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).