Skip to content

Commit fb13c5b

Browse files
committed
client: add support for task group checks
When tasks are checked for script checks, we walk back through their task group to see if there are script checks associated with the task. If so, we'll spin off script check tasklets for them. The group-level service and any restart behaviors it needs are entirely encapsulated within the group service hook.
1 parent 2dfa318 commit fb13c5b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

client/allocrunner/taskrunner/script_check_hook.go

+26
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ func newScriptCheckHook(c scriptCheckHookConfig) *scriptCheckHook {
7373
}
7474
}
7575

76+
// Walk back through the task group to see if there are script checks
77+
// associated with the task. If so, we'll create scriptCheck tasklets
78+
// for them. The group-level service and any check restart behaviors it
79+
// needs are entirely encapsulated within the group service hook which
80+
// watches Consul for status changes.
81+
tg := c.alloc.Job.LookupTaskGroup(c.alloc.TaskGroup)
82+
for _, service := range tg.Services {
83+
for _, check := range service.Checks {
84+
if check.Type != structs.ServiceCheckScript {
85+
continue
86+
}
87+
if check.TaskName != c.task.Name {
88+
continue
89+
}
90+
groupTaskName := "group-" + tg.Name
91+
sc := newScriptCheck(&scriptCheckConfig{
92+
allocID: c.alloc.ID,
93+
taskName: groupTaskName,
94+
service: service,
95+
check: check,
96+
agent: c.consul,
97+
})
98+
scriptChecks[sc.id] = sc
99+
}
100+
}
101+
76102
h := &scriptCheckHook{
77103
consul: c.consul,
78104
allocID: c.alloc.ID,

0 commit comments

Comments
 (0)