client: refactor common service registration objects from Consul.

This commit performs refactoring to pull out common service
registration objects into a new `client/serviceregistration`
package. This new package will form the base point for all
client specific service registration functionality.

The Consul specific implementation is not moved as it also
includes non-service registration implementations; this reduces
the blast radius of the changes as well.
This commit is contained in:
James Rasell
2022-03-15 09:38:30 +01:00
parent 066747ce79
commit 6e8f32a290
38 changed files with 1245 additions and 987 deletions

View File

@@ -10,7 +10,8 @@ import (
"github.com/hashicorp/consul/api"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces"
"github.com/hashicorp/nomad/client/consul"
"github.com/hashicorp/nomad/client/serviceregistration"
regMock "github.com/hashicorp/nomad/client/serviceregistration/mock"
"github.com/hashicorp/nomad/client/taskenv"
agentconsul "github.com/hashicorp/nomad/command/agent/consul"
"github.com/hashicorp/nomad/helper/testlog"
@@ -226,7 +227,7 @@ func TestScript_Exec_Codes(t *testing.T) {
func TestScript_TaskEnvInterpolation(t *testing.T) {
logger := testlog.HCLogger(t)
consulClient := consul.NewMockConsulServiceClient(t, logger)
consulClient := regMock.NewServiceRegistrationHandler(logger)
exec, cancel := newBlockingScriptExec()
defer cancel()
@@ -262,7 +263,7 @@ func TestScript_TaskEnvInterpolation(t *testing.T) {
scHook.driverExec = exec
expectedSvc := svcHook.getWorkloadServices().Services[0]
expected := agentconsul.MakeCheckID(agentconsul.MakeAllocServiceID(
expected := agentconsul.MakeCheckID(serviceregistration.MakeAllocServiceID(
alloc.ID, task.Name, expectedSvc), expectedSvc.Checks[0])
actual := scHook.newScriptChecks()
@@ -278,7 +279,7 @@ func TestScript_TaskEnvInterpolation(t *testing.T) {
svcHook.taskEnv = env
expectedSvc = svcHook.getWorkloadServices().Services[0]
expected = agentconsul.MakeCheckID(agentconsul.MakeAllocServiceID(
expected = agentconsul.MakeCheckID(serviceregistration.MakeAllocServiceID(
alloc.ID, task.Name, expectedSvc), expectedSvc.Checks[0])
actual = scHook.newScriptChecks()