services: get Consul token from hook resources (#18600)

When Workload Identity is being used with Consul, the `consul_hook` will add
Consul tokens to the alloc hook resources. Update the `group_service_hook` and
`service_hook` to use those tokens when available for registering and
deregistering Consul workloads.
This commit is contained in:
Tim Gross
2023-10-04 08:35:18 -04:00
committed by GitHub
parent e7136f80c5
commit fb7582d596
8 changed files with 49 additions and 0 deletions

View File

@@ -17,6 +17,7 @@ import (
"github.com/hashicorp/nomad/client/serviceregistration"
regMock "github.com/hashicorp/nomad/client/serviceregistration/mock"
"github.com/hashicorp/nomad/client/serviceregistration/wrapper"
cstructs "github.com/hashicorp/nomad/client/structs"
"github.com/hashicorp/nomad/client/taskenv"
agentconsul "github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/testlog"
@@ -260,6 +261,7 @@ func TestScript_TaskEnvInterpolation(t *testing.T) {
task: task,
serviceRegWrapper: regWrap,
logger: logger,
hookResources: cstructs.NewAllocHookResources(),
})
// emulate prestart having been fired
svcHook.taskEnv = env