Skip to content

Commit

Permalink
backport of commit 365f26f (#16241)
Browse files Browse the repository at this point in the history
This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-nomad-core committed Feb 22, 2023
1 parent 401bd1a commit d73ccd7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .changelog/16240.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
services: Fixed a bug where check_restart on nomad services on tasks failed with incorrect CheckIDs
```
16 changes: 10 additions & 6 deletions client/allocrunner/taskrunner/script_check_hook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

"github.com/hashicorp/consul/api"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/nomad/ci"
"github.com/hashicorp/nomad/client/allocrunner/taskrunner/interfaces"
"github.com/hashicorp/nomad/client/serviceregistration"
Expand All @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/nomad/helper/testlog"
"github.com/hashicorp/nomad/nomad/mock"
"github.com/hashicorp/nomad/nomad/structs"
"github.com/shoenig/test/must"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -271,14 +272,17 @@ func TestScript_TaskEnvInterpolation(t *testing.T) {
scHook.taskEnv = env
scHook.driverExec = exec

expectedSvc := svcHook.getWorkloadServices().Services[0]
workload := svcHook.getWorkloadServices()
must.Eq(t, "web", workload.AllocInfo.Group)

expectedSvc := workload.Services[0]
expected := agentconsul.MakeCheckID(serviceregistration.MakeAllocServiceID(
alloc.ID, task.Name, expectedSvc), expectedSvc.Checks[0])

actual := scHook.newScriptChecks()
check, ok := actual[expected]
require.True(t, ok)
require.Equal(t, "my-job-frontend-check", check.check.Name)
must.True(t, ok)
must.Eq(t, "my-job-frontend-check", check.check.Name)

// emulate an update
env = taskenv.NewBuilder(mock.Node(), alloc, task, "global").SetHookEnv(
Expand All @@ -293,8 +297,8 @@ func TestScript_TaskEnvInterpolation(t *testing.T) {

actual = scHook.newScriptChecks()
check, ok = actual[expected]
require.True(t, ok)
require.Equal(t, "my-job-backend-check", check.check.Name)
must.True(t, ok)
must.Eq(t, "my-job-backend-check", check.check.Name)
}

func TestScript_associated(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions client/allocrunner/taskrunner/service_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (h *serviceHook) getWorkloadServices() *serviceregistration.WorkloadService
info := structs.AllocInfo{
AllocID: h.allocID,
JobID: h.jobID,
Group: h.groupName,
Task: h.taskName,
Namespace: h.namespace,
}
Expand Down

0 comments on commit d73ccd7

Please sign in to comment.