open-nomad/client/allocrunner/taskrunner/interfaces/lifecycle.go
Tim Gross 1785822386
template: trigger change_mode for dynamic secrets on restore (#9636)
When a task is restored after a client restart, the template runner will
create a new lease for any dynamic secret (ex. Consul or PKI secrets
engines). But because this lease is being created in the prestart hook, we
don't trigger the `change_mode`.

This changeset uses the the existence of the task handle to detect a
previously running task that's been restored, so that we can trigger the
template `change_mode` if the template is changed, as it will be only with
dynamic secrets.
2020-12-16 13:36:19 -05:00

28 lines
930 B
Go

package interfaces
import (
"context"
"github.com/hashicorp/nomad/nomad/structs"
)
type TaskLifecycle interface {
// Restart a task in place. If failure=false then the restart does not
// count as an attempt in the restart policy.
Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
// Sends a signal to a task.
Signal(event *structs.TaskEvent, signal string) error
// Kill a task permanently.
Kill(ctx context.Context, event *structs.TaskEvent) error
// IsRunning returns true if the task runner has a handle to the task
// driver, which is useful for distinguishing restored tasks during
// prestart hooks. But note that the driver handle could go away after you
// check this, so callers should make sure they're handling that case
// safely. Ideally prestart hooks should be idempotent whenever possible
// to handle restored tasks; use this as an escape hatch.
IsRunning() bool
}