Documentation ¶
Index ¶
- Constants
- Variables
- func NewHookError(err error, taskEvent *structs.TaskEvent) error
- type Config
- type DriverHandle
- func (h *DriverHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)
- func (h *DriverHandle) ExecStreaming(ctx context.Context, command []string, tty bool, stream drivers.ExecTaskStream) error
- func (h *DriverHandle) ID() string
- func (h *DriverHandle) Kill() error
- func (h *DriverHandle) Network() *drivers.DriverNetwork
- func (h *DriverHandle) Signal(s string) error
- func (h *DriverHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
- func (h *DriverHandle) Update(task *structs.Task) error
- func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)
- type LazyHandle
- type StatsUpdater
- type TaskRunner
- func (tr *TaskRunner) Alloc() *structs.Allocation
- func (tr *TaskRunner) AppendEvent(event *structs.TaskEvent)
- func (tr *TaskRunner) DriverCapabilities() (*drivers.Capabilities, error)
- func (tr *TaskRunner) EmitEvent(event *structs.TaskEvent)
- func (tr *TaskRunner) IsLeader() bool
- func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error
- func (tr *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage
- func (tr *TaskRunner) MarkFailedDead(reason string)
- func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error
- func (tr *TaskRunner) Restore() error
- func (tr *TaskRunner) Run()
- func (tr *TaskRunner) SetAllocHookResources(res *cstructs.AllocHookResources)
- func (tr *TaskRunner) SetNetworkIsolation(n *drivers.NetworkIsolationSpec)
- func (tr *TaskRunner) Shutdown()
- func (tr *TaskRunner) Signal(event *structs.TaskEvent, s string) error
- func (tr *TaskRunner) Task() *structs.Task
- func (tr *TaskRunner) TaskExecHandler() drivermanager.TaskExecHandler
- func (tr *TaskRunner) TaskState() *structs.TaskState
- func (tr *TaskRunner) Update(update *structs.Allocation)
- func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent)
- func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage)
- func (tr *TaskRunner) WaitCh() <-chan struct{}
Constants ¶
const (
// HookNameDevices is the name of the devices hook
HookNameDevices = "devices"
)
const ( // TaskDirHookIsDoneDataKey is used to mark whether the hook is done. We // do not use the Done response value because we still need to set the // environment variables every time a task starts. // TODO(0.9.1): Use the resp.Env map and switch to resp.Done. We need to // remove usage of the envBuilder TaskDirHookIsDoneDataKey = "is_done" )
Variables ¶
var (
ErrTaskNotRunning = errors.New(errTaskNotRunning)
)
Functions ¶
Types ¶
type Config ¶
type Config struct { Alloc *structs.Allocation ClientConfig *config.Config Task *structs.Task TaskDir *allocdir.TaskDir Logger log.Logger // Consul is the client to use for managing Consul service registrations Consul consul.ConsulServiceAPI // ConsulSI is the client to use for managing Consul SI tokens ConsulSI consul.ServiceIdentityAPI // DynamicRegistry is where dynamic plugins should be registered. DynamicRegistry dynamicplugins.Registry // Vault is the client to use to derive and renew Vault tokens Vault vaultclient.VaultClient // StateDB is used to store and restore state. StateDB cstate.StateDB // StateUpdater is used to emit updated task state StateUpdater interfaces.TaskStateHandler // deviceStatsReporter is used to lookup resource usage for alloc devices DeviceStatsReporter cinterfaces.DeviceStatsReporter // CSIManager is used to manage the mounting of CSI volumes into tasks CSIManager csimanager.Manager // DeviceManager is used to mount devices as well as lookup device // statistics DeviceManager devicemanager.Manager // DriverManager is used to dispense driver plugins and register event // handlers DriverManager drivermanager.Manager // ServersContactedCh is closed when the first GetClientAllocs call to // servers succeeds and allocs are synced. ServersContactedCh chan struct{} // startConditionMetCtx is done when TR should start the task StartConditionMetCtx <-chan struct{} }
type DriverHandle ¶
type DriverHandle struct {
// contains filtered or unexported fields
}
DriverHandle encapsulates a driver plugin client and task identifier and exposes an api to perform driver operations on the task
func NewDriverHandle ¶
func NewDriverHandle(driver drivers.DriverPlugin, taskID string, task *structs.Task, net *drivers.DriverNetwork) *DriverHandle
NewDriverHandle returns a handle for task operations on a specific task
func (*DriverHandle) Exec ¶
Exec is the handled used by client endpoint handler to invoke the appropriate task driver exec.
func (*DriverHandle) ExecStreaming ¶ added in v0.9.2
func (h *DriverHandle) ExecStreaming(ctx context.Context, command []string, tty bool, stream drivers.ExecTaskStream) error
ExecStreaming is the handled used by client endpoint handler to invoke the appropriate task driver exec. while allowing to stream input and output
func (*DriverHandle) ID ¶
func (h *DriverHandle) ID() string
func (*DriverHandle) Kill ¶
func (h *DriverHandle) Kill() error
func (*DriverHandle) Network ¶
func (h *DriverHandle) Network() *drivers.DriverNetwork
func (*DriverHandle) Signal ¶
func (h *DriverHandle) Signal(s string) error
func (*DriverHandle) Stats ¶
func (h *DriverHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
func (*DriverHandle) WaitCh ¶
func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)
type LazyHandle ¶
LazyHandle is used to front calls to a DriverHandle where it is expected the existing handle may no longer be valid because the backing plugin has shutdown. LazyHandle detects the plugin shutting down and retrieves a new handle so that the consumer does not need to worry whether the handle is to the latest driver instance.
func NewLazyHandle ¶
func NewLazyHandle(shutdownCtx context.Context, fn retrieveHandleFn, logger log.Logger) *LazyHandle
NewLazyHandle takes the function to receive the latest handle and a logger and returns a LazyHandle
func (*LazyHandle) Stats ¶
func (l *LazyHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
type StatsUpdater ¶
type StatsUpdater interface {
UpdateStats(*cstructs.TaskResourceUsage)
}
StatsUpdater is the interface required by the StatsHook to update stats. Satisfied by TaskRunner.
type TaskRunner ¶
type TaskRunner struct {
// contains filtered or unexported fields
}
func NewTaskRunner ¶
func NewTaskRunner(config *Config) (*TaskRunner, error)
func (*TaskRunner) Alloc ¶
func (tr *TaskRunner) Alloc() *structs.Allocation
func (*TaskRunner) AppendEvent ¶
func (tr *TaskRunner) AppendEvent(event *structs.TaskEvent)
AppendEvent appends a new TaskEvent to this task's TaskState. The actual TaskState.State (pending, running, dead) is not changed. Use UpdateState to transition states. Events are persisted locally and errors are simply logged. Use EmitEvent also update AllocRunner.
func (*TaskRunner) DriverCapabilities ¶ added in v0.9.2
func (tr *TaskRunner) DriverCapabilities() (*drivers.Capabilities, error)
func (*TaskRunner) EmitEvent ¶
func (tr *TaskRunner) EmitEvent(event *structs.TaskEvent)
EmitEvent appends a new TaskEvent to this task's TaskState. The actual TaskState.State (pending, running, dead) is not changed. Use UpdateState to transition states. Events are persisted locally and sent to the server, but errors are simply logged. Use AppendEvent to simply add a new event.
func (*TaskRunner) IsLeader ¶
func (tr *TaskRunner) IsLeader() bool
IsLeader returns true if this task is the leader of its task group.
func (*TaskRunner) Kill ¶
Kill a task. Blocks until task exits or context is canceled. State is set to dead.
func (*TaskRunner) LatestResourceUsage ¶
func (tr *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage
LatestResourceUsage returns the last resource utilization datapoint collected. May return nil if the task is not running or no resource utilization has been collected yet.
func (*TaskRunner) MarkFailedDead ¶ added in v0.9.4
func (tr *TaskRunner) MarkFailedDead(reason string)
Mark a task as failed and not to run. Aimed to be invoked when alloc runner prestart hooks failed. Should never be called with Run().
func (*TaskRunner) Restart ¶
Restart a task. Returns immediately if no task is running. Blocks until existing task exits or passed-in context is canceled.
func (*TaskRunner) Restore ¶
func (tr *TaskRunner) Restore() error
Restore task runner state. Called by AllocRunner.Restore after NewTaskRunner but before Run so no locks need to be acquired.
func (*TaskRunner) Run ¶
func (tr *TaskRunner) Run()
Run the TaskRunner. Starts the user's task or reattaches to a restored task. Run closes WaitCh when it exits. Should be started in a goroutine.
func (*TaskRunner) SetAllocHookResources ¶ added in v0.11.0
func (tr *TaskRunner) SetAllocHookResources(res *cstructs.AllocHookResources)
func (*TaskRunner) SetNetworkIsolation ¶ added in v0.10.0
func (tr *TaskRunner) SetNetworkIsolation(n *drivers.NetworkIsolationSpec)
SetNetworkIsolation is called by the PreRun allocation hook after configuring the network isolation for the allocation
func (*TaskRunner) Shutdown ¶
func (tr *TaskRunner) Shutdown()
Shutdown TaskRunner gracefully without affecting the state of the task. Shutdown blocks until the main Run loop exits.
func (*TaskRunner) Task ¶
func (tr *TaskRunner) Task() *structs.Task
func (*TaskRunner) TaskExecHandler ¶ added in v0.9.2
func (tr *TaskRunner) TaskExecHandler() drivermanager.TaskExecHandler
func (*TaskRunner) TaskState ¶
func (tr *TaskRunner) TaskState() *structs.TaskState
func (*TaskRunner) Update ¶
func (tr *TaskRunner) Update(update *structs.Allocation)
Update the running allocation with a new version received from the server. Calls Update hooks asynchronously with Run.
This method is safe for calling concurrently with Run and does not modify the passed in allocation.
func (*TaskRunner) UpdateState ¶
func (tr *TaskRunner) UpdateState(state string, event *structs.TaskEvent)
UpdateState sets the task runners allocation state and triggers a server update.
func (*TaskRunner) UpdateStats ¶
func (tr *TaskRunner) UpdateStats(ru *cstructs.TaskResourceUsage)
UpdateStats updates and emits the latest stats from the driver.
func (*TaskRunner) WaitCh ¶
func (tr *TaskRunner) WaitCh() <-chan struct{}
WaitCh is closed when TaskRunner.Run exits.
Source Files ¶
- artifact_hook.go
- device_hook.go
- dispatch_hook.go
- driver_handle.go
- envoybootstrap_hook.go
- errors.go
- lazy_handle.go
- lifecycle.go
- logmon_hook.go
- plugin_supervisor_hook.go
- script_check_hook.go
- service_hook.go
- sids_hook.go
- stats_hook.go
- task_dir_hook.go
- task_runner.go
- task_runner_getters.go
- task_runner_hooks.go
- tasklet.go
- template_hook.go
- validate_hook.go
- vault_hook.go
- volume_hook.go