taskrunner

package
v1.5.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: MPL-2.0 Imports: 64 Imported by: 19

Documentation

Index

Constants

View Source
const (
	// HookNameDevices is the name of the devices hook
	HookNameDevices = "devices"
)
View Source
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

View Source
var (
	ErrTaskNotRunning = errors.New(errTaskNotRunning)
)

Functions

func NewHookError

func NewHookError(err error, taskEvent *structs.TaskEvent) error

NewHookError contains an underlying err and a pre-formatted task event.

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

func (h *DriverHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)

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

type LazyHandle struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Exec

func (l *LazyHandle) Exec(timeout time.Duration, cmd string, args []string) ([]byte, int, error)

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

type TTLUpdater interface {
	UpdateTTL(id, namespace, output, status string) error
}

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

func (tr *TaskRunner) Kill(ctx context.Context, event *structs.TaskEvent) error

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

func (tr *TaskRunner) Restart(ctx context.Context, event *structs.TaskEvent, failure bool) error

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) Signal

func (tr *TaskRunner) Signal(event *structs.TaskEvent, s string) error

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL