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) SetKillSignal(signal string)
- func (h *DriverHandle) Signal(s string) error
- func (h *DriverHandle) Stats(ctx context.Context, interval time.Duration) (<-chan *cstructs.TaskResourceUsage, error)
- func (h *DriverHandle) WaitCh(ctx context.Context) (<-chan *drivers.ExitResult, error)
- type LazyHandle
- type StatsUpdater
- type TTLUpdater
- 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) ForceRestart(ctx context.Context, event *structs.TaskEvent, failure bool) error
- func (tr *TaskRunner) IsLeader() bool
- func (tr *TaskRunner) IsPoststopTask() bool
- func (tr *TaskRunner) IsRunning() bool
- func (tr *TaskRunner) IsSidecarTask() bool
- func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error
- func (tr *TaskRunner) LatestResourceUsage() *cstructs.TaskResourceUsage
- func (tr *TaskRunner) MarkFailedKill(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) 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 serviceregistration.Handler // ConsulProxies is the client to use for looking up supported envoy versions // from Consul. ConsulProxies consul.SupportedProxiesAPI // 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 // CpusetCgroupPathGetter is used to lookup the cgroup path if supported by the platform CpusetCgroupPathGetter cgutil.CgroupPathGetter // 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{} // StartConditionMetCh signals the TaskRunner when it should start the task StartConditionMetCh <-chan struct{} // ShutdownDelayCtx is a context from the alloc runner which will // tell us to exit early from shutdown_delay ShutdownDelayCtx context.Context // ShutdownDelayCancelFn should only be used in testing. ShutdownDelayCancelFn context.CancelFunc // ServiceRegWrapper is the handler wrapper that is used by service hooks // to perform service and check registration and deregistration. ServiceRegWrapper *wrapper.HandlerWrapper // Getter is an interface for retrieving artifacts. Getter cinterfaces.ArtifactGetter // AllocHookResources is how taskrunner hooks can get state written by // allocrunner hooks AllocHookResources *cstructs.AllocHookResources }
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, maxKillTimeout time.Duration, 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) SetKillSignal ¶ added in v1.1.0
func (h *DriverHandle) SetKillSignal(signal string)
SetKillSignal allows overriding the signal sent to kill the task.
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 TTLUpdater ¶ added in v1.1.0
TTLUpdater is the subset of consul agent functionality needed by script checks to heartbeat
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) ForceRestart ¶ added in v1.3.4
func (tr *TaskRunner) ForceRestart(ctx context.Context, event *structs.TaskEvent, failure bool) error
ForceRestart restarts a task that is already running or reruns it if dead. Returns an error if the task is not able to rerun. Blocks until existing task exits or passed-in context is canceled.
Callers must restart the AllocRuner taskCoordinator beforehand to make sure the task will be able to run again.
func (*TaskRunner) IsLeader ¶
func (tr *TaskRunner) IsLeader() bool
IsLeader returns true if this task is the leader of its task group.
func (*TaskRunner) IsPoststopTask ¶ added in v1.0.0
func (tr *TaskRunner) IsPoststopTask() bool
IsPoststopTask returns true if this task is a poststop task in its task group.
func (*TaskRunner) IsRunning ¶ added in v1.0.2
func (tr *TaskRunner) IsRunning() bool
func (*TaskRunner) IsSidecarTask ¶ added in v1.1.15
func (tr *TaskRunner) IsSidecarTask() bool
IsSidecarTask returns true if this task is a sidecar task in 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) MarkFailedKill ¶ added in v1.3.15
func (tr *TaskRunner) MarkFailedKill(reason string)
MarkFailedKill marks a task as failed and should be killed. It should be invoked when alloc runner prestart hooks fail. Afterwards, Run() will perform any necessary cleanup.
func (*TaskRunner) Restart ¶
Restart restarts a task that is already running. Returns an error if the task is not 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) 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 ¶
- api_hook.go
- artifact_hook.go
- connect_native_hook.go
- device_hook.go
- dispatch_hook.go
- driver_handle.go
- envoy_bootstrap_hook.go
- envoy_version_hook.go
- errors.go
- identity_hook.go
- lazy_handle.go
- lifecycle.go
- logmon_hook.go
- plugin_supervisor_hook.go
- remotetask_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