2018-06-22 00:35:07 +00:00
|
|
|
package interfaces
|
|
|
|
|
|
|
|
import (
|
2018-08-30 21:33:50 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2018-06-22 00:35:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// RunnnerHook is a lifecycle hook into the life cycle of an allocation runner.
|
|
|
|
type RunnerHook interface {
|
|
|
|
Name() string
|
|
|
|
}
|
|
|
|
|
2019-02-21 23:37:22 +00:00
|
|
|
// RunnerPrerunHooks are executed before calling TaskRunner.Run for
|
|
|
|
// non-terminal allocations. Terminal allocations do *not* call prerun.
|
2018-06-22 00:35:07 +00:00
|
|
|
type RunnerPrerunHook interface {
|
|
|
|
RunnerHook
|
2019-03-12 22:03:54 +00:00
|
|
|
Prerun() error
|
2018-06-22 00:35:07 +00:00
|
|
|
}
|
|
|
|
|
2019-12-03 13:58:29 +00:00
|
|
|
// RunnerPreKillHooks are executed inside of KillTasks before
|
|
|
|
// iterating and killing each task. It will run before the Leader
|
|
|
|
// task is killed.
|
|
|
|
type RunnerPreKillHook interface {
|
|
|
|
RunnerHook
|
|
|
|
|
|
|
|
PreKill()
|
|
|
|
}
|
|
|
|
|
2019-02-21 23:37:22 +00:00
|
|
|
// RunnerPostrunHooks are executed after calling TaskRunner.Run, even for
|
|
|
|
// terminal allocations. Therefore Postrun hooks must be safe to call without
|
|
|
|
// first calling Prerun hooks.
|
2018-06-22 00:35:07 +00:00
|
|
|
type RunnerPostrunHook interface {
|
|
|
|
RunnerHook
|
|
|
|
Postrun() error
|
|
|
|
}
|
|
|
|
|
2019-02-21 23:37:22 +00:00
|
|
|
// RunnerDestroyHooks are executed after AllocRunner.Run has exited and must
|
|
|
|
// make a best effort cleanup allocation resources. Destroy hooks must be safe
|
|
|
|
// to call without first calling Prerun.
|
2018-06-22 00:35:07 +00:00
|
|
|
type RunnerDestroyHook interface {
|
|
|
|
RunnerHook
|
|
|
|
Destroy() error
|
|
|
|
}
|
|
|
|
|
2019-02-21 23:37:22 +00:00
|
|
|
// RunnerUpdateHooks are executed when an allocation update is received from
|
|
|
|
// the server. Update is called concurrently with AllocRunner execution and
|
|
|
|
// therefore must be safe for concurrent access with other hook methods. Calls
|
|
|
|
// to Update are serialized so allocaiton updates will always be processed in
|
|
|
|
// order.
|
2018-06-22 00:35:07 +00:00
|
|
|
type RunnerUpdateHook interface {
|
|
|
|
RunnerHook
|
2018-08-30 21:33:50 +00:00
|
|
|
Update(*RunnerUpdateRequest) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type RunnerUpdateRequest struct {
|
|
|
|
Alloc *structs.Allocation
|
2018-06-22 00:35:07 +00:00
|
|
|
}
|
|
|
|
|
2021-01-21 16:36:00 +00:00
|
|
|
// RunnerTaskRestartHooks are executed just before the allocation runner is
|
|
|
|
// going to restart all tasks.
|
|
|
|
type RunnerTaskRestartHook interface {
|
|
|
|
RunnerHook
|
|
|
|
|
|
|
|
PreTaskRestart() error
|
|
|
|
}
|
|
|
|
|
2018-11-14 18:29:07 +00:00
|
|
|
// ShutdownHook may be implemented by AllocRunner or TaskRunner hooks and will
|
|
|
|
// be called when the agent process is being shutdown gracefully.
|
|
|
|
type ShutdownHook interface {
|
|
|
|
RunnerHook
|
|
|
|
|
|
|
|
Shutdown()
|
|
|
|
}
|