client: account for service provider namespace updates in hooks. (#12479)

When a service is updated, the service hooks update a number of
internal fields which helps generate the new workload. This also
needs to update the namespace for the service provider. It is
possible for these to be different, and in the case of Nomad and
Consul running OSS, this is to be expected.
This commit is contained in:
James Rasell
2022-04-06 19:26:22 +02:00
committed by GitHub
parent 9dc0b88cb5
commit a024b15796
2 changed files with 10 additions and 2 deletions

View File

@@ -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()

View File

@@ -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
}