engine

package
v0.0.0-...-b702281 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 54 Imported by: 352

Documentation

Overview

Package engine contains code for interacting with container-running backends and handling events from them. It supports Docker as the sole task engine type.

Package engine contains the core logic for managing tasks

Index

Constants

View Source
const (
	//DockerEndpointEnvVariable is the environment variable that can override the Docker endpoint
	DockerEndpointEnvVariable = "DOCKER_HOST"
	// DockerDefaultEndpoint is the default value for the Docker endpoint
	DockerDefaultEndpoint = "unix:///var/run/docker.sock"

	FluentNetworkPortValue = "24224"
	FluentAWSVPCHostValue  = "127.0.0.1"
)
View Source
const (
	CPU      = "CPU"
	GPU      = "GPU"
	MEMORY   = "MEMORY"
	PORTSTCP = "PORTS_TCP"
	PORTSUDP = "PORTS_UDP"
)

Variables

View Source
var ImagePullDeleteLock sync.RWMutex

ImagePullDeleteLock ensures that pulls and deletes do not run at the same time and pulls can be run at the same time for docker >= 1.11.1 Pulls are serialized as a temporary workaround for a devicemapper issue. (see https://github.com/docker/docker/issues/9718) Deletes must not run at the same time as pulls to prevent deletion of images that are being used to launch new tasks.

Functions

This section is empty.

Types

type CannotGetDockerClientVersionError

type CannotGetDockerClientVersionError struct {
	// contains filtered or unexported fields
}

CannotGetDockerClientVersionError indicates error when trying to get docker client api version

func (CannotGetDockerClientVersionError) Error

func (CannotGetDockerClientVersionError) ErrorName

func (err CannotGetDockerClientVersionError) ErrorName() string

type ContainerNetworkingError

type ContainerNetworkingError struct {
	// contains filtered or unexported fields
}

ContainerNetworkingError indicates any error when dealing with the network namespace of container

func (ContainerNetworkingError) Error

func (err ContainerNetworkingError) Error() string

func (ContainerNetworkingError) ErrorName

func (err ContainerNetworkingError) ErrorName() string

type ContainerVanishedError

type ContainerVanishedError struct{}

ContainerVanishedError is a type for describing a container that does not exist

func (ContainerVanishedError) Error

func (err ContainerVanishedError) Error() string

func (ContainerVanishedError) ErrorName

func (err ContainerVanishedError) ErrorName() string

ErrorName returns the name of the error

type DockerTaskEngine

type DockerTaskEngine struct {
	// contains filtered or unexported fields
}

DockerTaskEngine is a state machine for managing a task and its containers in ECS.

DockerTaskEngine implements an abstraction over the DockerGoClient so that it does not have to know about tasks, only containers The DockerTaskEngine interacts with Docker to implement a TaskEngine

func NewDockerTaskEngine

func NewDockerTaskEngine(cfg *config.Config,
	client dockerapi.DockerClient,
	credentialsManager credentials.Manager,
	containerChangeEventStream *eventstream.EventStream,
	imageManager ImageManager,
	hostResourceManager *HostResourceManager,
	state dockerstate.TaskEngineState,
	metadataManager containermetadata.Manager,
	resourceFields *taskresource.ResourceFields,
	execCmdMgr execcmd.Manager,
	serviceConnectManager serviceconnect.Manager,
	daemonManagers map[string]dm.DaemonManager) *DockerTaskEngine

NewDockerTaskEngine returns a created, but uninitialized, DockerTaskEngine. The distinction between created and initialized is that when created it may be serialized/deserialized, but it will not communicate with docker until it is also initialized.

func (*DockerTaskEngine) AddTask

func (engine *DockerTaskEngine) AddTask(task *apitask.Task)

AddTask starts tracking a task

func (*DockerTaskEngine) Context

func (engine *DockerTaskEngine) Context() context.Context

func (*DockerTaskEngine) Disable

func (engine *DockerTaskEngine) Disable()

Disable prevents this engine from managing any additional tasks.

func (*DockerTaskEngine) EmitTaskEvent

func (engine *DockerTaskEngine) EmitTaskEvent(task *apitask.Task, reason string)

func (*DockerTaskEngine) GetDaemonManagers

func (engine *DockerTaskEngine) GetDaemonManagers() map[string]dm.DaemonManager

func (*DockerTaskEngine) GetDaemonTask

func (engine *DockerTaskEngine) GetDaemonTask(daemonName string) *apitask.Task

func (*DockerTaskEngine) GetTaskByArn

func (engine *DockerTaskEngine) GetTaskByArn(arn string) (*apitask.Task, bool)

GetTaskByArn returns the task identified by that ARN

func (*DockerTaskEngine) Init

func (engine *DockerTaskEngine) Init(ctx context.Context) error

Init initializes a DockerTaskEngine such that it may communicate with docker and operate normally. This function must be called before any other function, except serializing and deserializing, can succeed without error.

func (*DockerTaskEngine) ListTasks

func (engine *DockerTaskEngine) ListTasks() ([]*apitask.Task, error)

ListTasks returns the tasks currently managed by the DockerTaskEngine

func (*DockerTaskEngine) LoadState

func (engine *DockerTaskEngine) LoadState() error

LoadState populates the task engine state with data in db.

func (*DockerTaskEngine) MarshalJSON

func (engine *DockerTaskEngine) MarshalJSON() ([]byte, error)

MarshalJSON marshals into state directly

func (*DockerTaskEngine) MustInit

func (engine *DockerTaskEngine) MustInit(ctx context.Context)

MustInit blocks and retries until an engine can be initialized.

func (*DockerTaskEngine) SaveState

func (engine *DockerTaskEngine) SaveState() error

SaveState saves all the data in task engine state to db.

func (*DockerTaskEngine) SetDaemonTask

func (engine *DockerTaskEngine) SetDaemonTask(daemonName string, task *apitask.Task)

func (*DockerTaskEngine) SetDataClient

func (engine *DockerTaskEngine) SetDataClient(client data.Client)

SetDataClient sets the saver that is used by the DockerTaskEngine.

func (*DockerTaskEngine) Shutdown

func (engine *DockerTaskEngine) Shutdown()

Shutdown makes a best-effort attempt to cleanup after the task engine. This should not be relied on for anything more complicated than testing.

func (*DockerTaskEngine) State

State is a function primarily meant for testing usage; it is explicitly not part of the TaskEngine interface and should not be relied upon. It returns an internal representation of the state of this DockerTaskEngine.

func (*DockerTaskEngine) StateChangeEvents

func (engine *DockerTaskEngine) StateChangeEvents() chan statechange.Event

StateChangeEvents returns channels to read task and container state changes. These changes should be read as soon as possible as them not being read will block processing the task referenced by the event.

func (*DockerTaskEngine) UnmarshalJSON

func (engine *DockerTaskEngine) UnmarshalJSON(data []byte) error

UnmarshalJSON restores a previously marshaled task-engine state from json

func (*DockerTaskEngine) Version

func (engine *DockerTaskEngine) Version() (string, error)

Version returns the underlying docker version.

type HostResourceManager

type HostResourceManager struct {
	// contains filtered or unexported fields
}

HostResourceManager keeps account of host resources allocated for tasks set to be created/running tasks

func NewHostResourceManager

func NewHostResourceManager(resourceMap map[string]*ecs.Resource) HostResourceManager

NewHostResourceManager initialize host resource manager with available host resource values

type ImageManager

type ImageManager interface {
	RecordContainerReference(container *apicontainer.Container) error
	RemoveContainerReferenceFromImageState(container *apicontainer.Container) error
	AddAllImageStates(imageStates []*image.ImageState)
	GetImageStateFromImageName(containerImageName string) (*image.ImageState, bool)
	StartImageCleanupProcess(ctx context.Context)
	SetDataClient(dataClient data.Client)
	AddImageToCleanUpExclusionList(image string)
}

ImageManager is responsible for saving the Image states, adding and removing container references to ImageStates

func NewImageManager

func NewImageManager(cfg *config.Config, client dockerapi.DockerClient, state dockerstate.TaskEngineState) ImageManager

NewImageManager returns a new ImageManager

type ImageStatesForDeletion

type ImageStatesForDeletion []*image.ImageState

ImageStatesForDeletion is used for implementing the sort interface

func (ImageStatesForDeletion) Len

func (imageStates ImageStatesForDeletion) Len() int

Implementing sort interface based on last used times of the images

func (ImageStatesForDeletion) Less

func (imageStates ImageStatesForDeletion) Less(i, j int) bool

func (ImageStatesForDeletion) Swap

func (imageStates ImageStatesForDeletion) Swap(i, j int)

type ImageWithSizeID

type ImageWithSizeID struct {
	RepoTags []string
	ImageID  string
	Size     int64
	// contains filtered or unexported fields
}

type InvalidHostResource

type InvalidHostResource struct {
	// contains filtered or unexported fields
}

func (*InvalidHostResource) Error

func (e *InvalidHostResource) Error() string

type ResourceIsNilForTask

type ResourceIsNilForTask struct {
	// contains filtered or unexported fields
}

func (*ResourceIsNilForTask) Error

func (e *ResourceIsNilForTask) Error() string

type ResourceNotFoundForTask

type ResourceNotFoundForTask struct {
	// contains filtered or unexported fields
}

func (*ResourceNotFoundForTask) Error

func (e *ResourceNotFoundForTask) Error() string

type TaskDependencyError

type TaskDependencyError struct {
	// contains filtered or unexported fields
}

TaskDependencyError is the error for task that dependencies can't be resolved

func (TaskDependencyError) Error

func (err TaskDependencyError) Error() string

func (TaskDependencyError) ErrorName

func (err TaskDependencyError) ErrorName() string

ErrorName is the name of the error

type TaskEngine

type TaskEngine interface {
	Init(context.Context) error
	MustInit(context.Context)
	// Disable *must* only be called when this engine will no longer be used
	// (e.g. right before exiting down the process). It will irreversibly stop
	// this task engine from processing new tasks
	Disable()

	// StateChangeEvents will provide information about tasks that have been previously
	// executed. Specifically, it will provide information when they reach
	// running or stopped, as well as providing portbinding and other metadata
	StateChangeEvents() chan statechange.Event
	// SetDataClient sets the data client that is used by the task engine.
	SetDataClient(data.Client)

	// AddTask adds a new task to the task engine and manages its container's
	// lifecycle. If it returns an error, the task was not added.
	AddTask(*apitask.Task)

	// ListTasks lists all the tasks being managed by the TaskEngine.
	ListTasks() ([]*apitask.Task, error)

	// GetTaskByArn gets a managed task, given a task arn.
	GetTaskByArn(string) (*apitask.Task, bool)

	Version() (string, error)

	// LoadState loads the task engine state with data in db.
	LoadState() error
	// SaveState saves all the data in task engine state to db.
	SaveState() error

	GetDaemonManagers() map[string]dm.DaemonManager
	GetDaemonTask(string) *apitask.Task
	SetDaemonTask(string, *apitask.Task)

	json.Marshaler
	json.Unmarshaler
}

TaskEngine is an interface for the DockerTaskEngine

func NewTaskEngine

func NewTaskEngine(cfg *config.Config, client dockerapi.DockerClient,
	credentialsManager credentials.Manager,
	containerChangeEventStream *eventstream.EventStream,
	imageManager ImageManager, hostResources map[string]*ecs.Resource, state dockerstate.TaskEngineState,
	metadataManager containermetadata.Manager,
	resourceFields *taskresource.ResourceFields,
	execCmdMgr execcmd.Manager,
	serviceConnectManager serviceconnect.Manager,
	daemonManagers map[string]dm.DaemonManager) TaskEngine

NewTaskEngine returns a default TaskEngine

type TaskStoppedBeforePullBeginError

type TaskStoppedBeforePullBeginError struct {
	// contains filtered or unexported fields
}

TaskStoppedBeforePullBeginError is a type for task errors involving pull

func (TaskStoppedBeforePullBeginError) Error

func (TaskStoppedBeforePullBeginError) ErrorName

ErrorName returns the name of the error

Directories

Path Synopsis
mock
Package mock_daemonmanager is a generated GoMock package.
Package mock_daemonmanager is a generated GoMock package.
mocks
Package mock_dockerstate is a generated GoMock package.
Package mock_dockerstate is a generated GoMock package.
testutils
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.
mocks
Package mock_execcmd is a generated GoMock package.
Package mock_execcmd is a generated GoMock package.
Package mock_engine is a generated GoMock package.
Package mock_engine is a generated GoMock package.
mock
Package mock_serviceconnect is a generated GoMock package.
Package mock_serviceconnect is a generated GoMock package.
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.
Package testutils contains files that are used in tests but not elsewhere and thus can be excluded from the final executable.

Jump to

Keyboard shortcuts

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