Skip to content

Commit

Permalink
Merge pull request #10401 from hashicorp/cp-cns-ent-test-fixes
Browse files Browse the repository at this point in the history
cherry-pick fixes from cns ent tests
  • Loading branch information
shoenig committed Apr 20, 2021
2 parents 95f55cf + 5173a12 commit d86cd6c
Show file tree
Hide file tree
Showing 10 changed files with 529 additions and 85 deletions.
65 changes: 33 additions & 32 deletions client/allocrunner/taskrunner/script_check_hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,16 @@ func (h *scriptCheckHook) newScriptChecks() map[string]*scriptCheck {
serviceID := agentconsul.MakeAllocServiceID(
h.alloc.ID, h.task.Name, service)
sc := newScriptCheck(&scriptCheckConfig{
namespace: h.consulNamespace,
allocID: h.alloc.ID,
taskName: h.task.Name,
check: check,
serviceID: serviceID,
ttlUpdater: h.consul,
driverExec: h.driverExec,
taskEnv: h.taskEnv,
logger: h.logger,
shutdownCh: h.shutdownCh,
consulNamespace: h.consulNamespace,
allocID: h.alloc.ID,
taskName: h.task.Name,
check: check,
serviceID: serviceID,
ttlUpdater: h.consul,
driverExec: h.driverExec,
taskEnv: h.taskEnv,
logger: h.logger,
shutdownCh: h.shutdownCh,
})
if sc != nil {
scriptChecks[sc.id] = sc
Expand Down Expand Up @@ -225,16 +225,17 @@ func (h *scriptCheckHook) newScriptChecks() map[string]*scriptCheck {
serviceID := agentconsul.MakeAllocServiceID(
h.alloc.ID, groupTaskName, service)
sc := newScriptCheck(&scriptCheckConfig{
allocID: h.alloc.ID,
taskName: groupTaskName,
check: check,
serviceID: serviceID,
ttlUpdater: h.consul,
driverExec: h.driverExec,
taskEnv: h.taskEnv,
logger: h.logger,
shutdownCh: h.shutdownCh,
isGroup: true,
consulNamespace: h.consulNamespace,
allocID: h.alloc.ID,
taskName: groupTaskName,
check: check,
serviceID: serviceID,
ttlUpdater: h.consul,
driverExec: h.driverExec,
taskEnv: h.taskEnv,
logger: h.logger,
shutdownCh: h.shutdownCh,
isGroup: true,
})
if sc != nil {
scriptChecks[sc.id] = sc
Expand Down Expand Up @@ -277,17 +278,17 @@ type scriptCheck struct {

// scriptCheckConfig is a parameter struct for newScriptCheck
type scriptCheckConfig struct {
allocID string
taskName string
serviceID string
namespace string // consul namespace (TODO: SET)
check *structs.ServiceCheck
ttlUpdater TTLUpdater
driverExec tinterfaces.ScriptExecutor
taskEnv *taskenv.TaskEnv
logger log.Logger
shutdownCh chan struct{}
isGroup bool
allocID string
taskName string
serviceID string
consulNamespace string
check *structs.ServiceCheck
ttlUpdater TTLUpdater
driverExec tinterfaces.ScriptExecutor
taskEnv *taskenv.TaskEnv
logger log.Logger
shutdownCh chan struct{}
isGroup bool
}

// newScriptCheck constructs a scriptCheck. we're only going to
Expand Down Expand Up @@ -330,7 +331,7 @@ func newScriptCheck(config *scriptCheckConfig) *scriptCheck {
} else {
sc.id = agentconsul.MakeCheckID(config.serviceID, sc.check)
}
sc.consulNamespace = config.namespace
sc.consulNamespace = config.consulNamespace
return sc
}

Expand Down
3 changes: 2 additions & 1 deletion command/agent/consul/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1303,7 +1303,8 @@ func (c *ServiceClient) AllocRegistrations(allocID string) (*AllocRegistration,
// UpdateTTL is used to update the TTL of a check. Typically this will only be
// called to heartbeat script checks.
func (c *ServiceClient) UpdateTTL(id, namespace, output, status string) error {
return c.agentAPI.UpdateTTLOpts(id, output, status, &api.QueryOptions{Namespace: normalizeNamespace(namespace)})
ns := normalizeNamespace(namespace)
return c.agentAPI.UpdateTTLOpts(id, output, status, &api.QueryOptions{Namespace: ns})
}

// Shutdown the Consul client. Update running task registrations and deregister
Expand Down
4 changes: 2 additions & 2 deletions e2e/consul/input/namespaces/connect_terminating.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ job "connect_terminating" {
}

env {
PORT = "9001"
PORT = "${NOMAD_PORT_port}"
}
}
}
Expand Down Expand Up @@ -64,7 +64,7 @@ job "connect_terminating" {
}

env {
PORT = "9011"
PORT = "${NOMAD_PORT_port}"
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions e2e/consul/input/namespaces/template_kv.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ job "template_kv" {
}

task "task-b" {
driver = "docker"
driver = "raw_exec"

config {
image = "busybox:1"
command = "cat"
args = ["local/a.txt"]
}
Expand All @@ -34,10 +33,9 @@ job "template_kv" {
# no consul namespace set

task "task-z" {
driver = "docker"
driver = "raw_exec"

config {
image = "busybox:1"
command = "cat"
args = ["local/a.txt"]
}
Expand Down
Loading

0 comments on commit d86cd6c

Please sign in to comment.