diff --git a/client/allocrunner/groupservice_hook.go b/client/allocrunner/groupservice_hook.go index f7372b1bd..3e567537b 100644 --- a/client/allocrunner/groupservice_hook.go +++ b/client/allocrunner/groupservice_hook.go @@ -35,7 +35,7 @@ type groupServiceHook struct { shutdownDelayCtx context.Context // namespace is the Nomad or Consul namespace in which service - // registrations will be made. + // registrations will be made. This field may be updated. namespace string // serviceRegWrapper is the handler wrapper that is used to perform service @@ -163,6 +163,10 @@ func (h *groupServiceHook) Update(req *interfaces.RunnerUpdateRequest) error { h.delay = shutdown h.taskEnvBuilder.UpdateTask(req.Alloc, nil) + // An update may change the service provider, therefore we need to account + // for how namespaces work across providers also. + h.namespace = req.Alloc.ServiceProviderNamespace() + // Create new task services struct with those new values newWorkloadServices := h.getWorkloadServices() diff --git a/client/allocrunner/taskrunner/service_hook.go b/client/allocrunner/taskrunner/service_hook.go index 872453527..5a29a82e6 100644 --- a/client/allocrunner/taskrunner/service_hook.go +++ b/client/allocrunner/taskrunner/service_hook.go @@ -61,7 +61,7 @@ type serviceHook struct { taskEnv *taskenv.TaskEnv // namespace is the Nomad or Consul namespace in which service - // registrations will be made. + // registrations will be made. This field may be updated. namespace string // serviceRegWrapper is the handler wrapper that is used to perform service @@ -173,6 +173,10 @@ func (h *serviceHook) updateHookFields(req *interfaces.TaskUpdateRequest) error h.canary = canary h.ports = req.Alloc.AllocatedResources.Shared.Ports + // An update may change the service provider, therefore we need to account + // for how namespaces work across providers also. + h.namespace = req.Alloc.ServiceProviderNamespace() + return nil }