Skip to content

Commit

Permalink
Merge aa9ff3a into backport/checkInterpolate/loosely-big-bulldog
Browse files Browse the repository at this point in the history
  • Loading branch information
hc-github-team-nomad-core committed Oct 4, 2023
2 parents a19c837 + aa9ff3a commit f349068
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .changelog/18584.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
services: use interpolated address when performing nomad service health checks
```
4 changes: 2 additions & 2 deletions client/allocrunner/alloc_runner_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (ar *allocRunner) initRunnerHooks(config *clientconfig.Config) error {
}

// Create a taskenv.TaskEnv which is used for read only purposes by the
// newNetworkHook.
// newNetworkHook and newChecksHook.
builtTaskEnv := newEnvBuilder().Build()

// Create the alloc directory hook. This is run first to ensure the
Expand All @@ -134,7 +134,7 @@ func (ar *allocRunner) initRunnerHooks(config *clientconfig.Config) error {
newConsulGRPCSocketHook(hookLogger, alloc, ar.allocDir, config.ConsulConfig, config.Node.Attributes),
newConsulHTTPSocketHook(hookLogger, alloc, ar.allocDir, config.ConsulConfig),
newCSIHook(alloc, hookLogger, ar.csiManager, ar.rpcClient, ar, ar.hookResources, ar.clientConfig.Node.SecretID),
newChecksHook(hookLogger, alloc, ar.checkStore, ar),
newChecksHook(hookLogger, alloc, ar.checkStore, ar, builtTaskEnv),
}
if config.ExtraAllocHooks != nil {
ar.runnerHooks = append(ar.runnerHooks, config.ExtraAllocHooks...)
Expand Down
8 changes: 7 additions & 1 deletion client/allocrunner/checks_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/serviceregistration/checks"
"github.com/hashicorp/nomad/client/serviceregistration/checks/checkstore"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper"
"github.com/hashicorp/nomad/nomad/structs"
)
Expand Down Expand Up @@ -79,6 +80,7 @@ type checksHook struct {
shim checkstore.Shim
checker checks.Checker
allocID string
taskEnv *taskenv.TaskEnv

// fields that get re-initialized on allocation update
lock sync.RWMutex
Expand All @@ -93,6 +95,7 @@ func newChecksHook(
alloc *structs.Allocation,
shim checkstore.Shim,
network structs.NetworkStatus,
taskEnv *taskenv.TaskEnv,
) *checksHook {
h := &checksHook{
logger: logger.Named(checksHookName),
Expand All @@ -101,6 +104,7 @@ func newChecksHook(
shim: shim,
network: network,
checker: checks.New(logger),
taskEnv: taskEnv,
}
h.initialize(alloc)
return h
Expand Down Expand Up @@ -205,8 +209,10 @@ func (h *checksHook) Prerun() error {
return nil
}

interpolatedServices := taskenv.InterpolateServices(h.taskEnv, group.NomadServices())

// create and start observers of nomad service checks in alloc
h.observe(h.alloc, group.NomadServices())
h.observe(h.alloc, interpolatedServices)

return nil
}
Expand Down
9 changes: 7 additions & 2 deletions client/allocrunner/checks_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/nomad/client/allocrunner/interfaces"
"github.com/hashicorp/nomad/client/serviceregistration/checks/checkstore"
"github.com/hashicorp/nomad/client/state"
"github.com/hashicorp/nomad/client/taskenv"
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
Expand Down Expand Up @@ -166,7 +167,9 @@ func TestCheckHook_Checks_ResultsSet(t *testing.T) {

alloc := allocWithNomadChecks(addr, port, tc.onGroup)

h := newChecksHook(logger, alloc, checkStore, network)
envBuilder := taskenv.NewBuilder(mock.Node(), alloc, nil, alloc.Job.Region)

h := newChecksHook(logger, alloc, checkStore, network, envBuilder.Build())

// initialize is called; observers are created but not started yet
must.MapEmpty(t, h.observers)
Expand Down Expand Up @@ -231,7 +234,9 @@ func TestCheckHook_Checks_UpdateSet(t *testing.T) {

alloc := allocWithNomadChecks(addr, port, true)

h := newChecksHook(logger, alloc, shim, network)
envBuilder := taskenv.NewBuilder(mock.Node(), alloc, nil, alloc.Job.Region)

h := newChecksHook(logger, alloc, shim, network, envBuilder.Build())

// calling pre-run starts the observers
err := h.Prerun()
Expand Down

0 comments on commit f349068

Please sign in to comment.