Skip to content

Commit fe97b91

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 d01c07f commit fe97b91

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
@@ -71,6 +71,32 @@ func newScriptCheckHook(c scriptCheckHookConfig) *scriptCheckHook {
7171
scriptChecks[sc.id] = sc
7272
}
7373
}
74+
75+
// Walk back through the task group to see if there are script checks
76+
// associated with the task. If so, we'll create scriptCheck tasklets
77+
// for them. The group-level service and any check restart behaviors it
78+
// needs are entirely encapsulated within the group service hook which
79+
// watches Consul for status changes.
80+
tg := c.alloc.Job.LookupTaskGroup(c.alloc.TaskGroup)
81+
for _, service := range tg.Services {
82+
for _, check := range service.Checks {
83+
if check.Type != structs.ServiceCheckScript {
84+
continue
85+
}
86+
if check.TaskName != c.task.Name {
87+
continue
88+
}
89+
groupTaskName := "group-" + tg.Name
90+
sc := newScriptCheck(&scriptCheckConfig{
91+
allocID: c.alloc.ID,
92+
taskName: groupTaskName,
93+
service: service,
94+
check: check,
95+
agent: c.consul,
96+
})
97+
scriptChecks[sc.id] = sc
98+
}
99+
}
74100
if len(scriptChecks) == 0 {
75101
return nil // the caller should not register this hook
76102
}

0 commit comments

Comments
 (0)