Skip to content

Commit

Permalink
consul: always include task services hook
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shoenig committed Jan 4, 2021
1 parent 3153c14 commit 7198d7a
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions client/allocrunner/taskrunner/task_runner_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down

0 comments on commit 7198d7a

Please sign in to comment.