container

package
v1.5.2 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2021 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const DockerNamePrefix = "mesos-"

Prefix used to name Docker containers in order to distinguish those created by Mesos from those created manually.

View Source
const (
	// How many times a docker image pull will be retried on error
	PullImageNumRetries = 5
)

Variables

This section is empty.

Functions

func AppendTaskEnv added in v0.9.2

func AppendTaskEnv(envVars []string, taskInfo *mesos.TaskInfo) []string

Map Task Env to Docker Env

func BindsForTask

func BindsForTask(taskInfo *mesos.TaskInfo) []string

BindsForTask turns Mesos volume information to Docker volume binds at runtime (equivalent to -v)

func CapAddForTask

func CapAddForTask(taskInfo *mesos.TaskInfo) []string

CapAddForTask scans for cap-adds and generate string slice

func CapDropForTask

func CapDropForTask(taskInfo *mesos.TaskInfo) []string

CapDropForTask scans for cap-drops and generate string slice

func CheckImage

func CheckImage(client DockerClient, taskInfo *mesos.TaskInfo) bool

Loop through all the images and see if we have one with a match on this repo image:tag combination.

func ConfigForTask

func ConfigForTask(taskInfo *mesos.TaskInfo, forceCpuLimit bool, forceMemoryLimit bool, useCpuShares bool, envVars []string) *docker.CreateContainerOptions

Generate a complete config with both Config and HostConfig. Does not attempt to be exhaustive in support for Docker options. Supports the most commonly used options. Others are not complex to add.

func EnvForTask

func EnvForTask(taskInfo *mesos.TaskInfo, labels map[string]string,
	addEnvVars []string) []string

Map Mesos environment settings to Docker environment (-e FOO=BAR). Adds a few environment variables derived from the labels we were passed, as well. Useful for services in containers to know more about their environment.

func FollowLogs added in v0.10.0

func FollowLogs(client DockerClient, containerId string, since int64, stdout io.Writer, stderr io.Writer)

FollowLogs will fetch the Docker logs since "since", and start pumping logs into the two writers that are passed in.

func GetContainerName added in v0.6.1

func GetContainerName(taskId *mesos.TaskID) string

GetContainerName constructs a Mesos-friendly container name. This lets Mesos properly handle agent/master resolution without us.

func GetExitCode added in v0.6.3

func GetExitCode(client DockerClient, containerId string) (int, error)

GetExitCode returns the exit code for a container so that we can try to see how it exited and map that to a Mesos status.

func GetLogs

func GetLogs(client DockerClient, containerId string, since int64, stdout io.Writer, stderr io.Writer)

GetLogs will fetch the Docker logs from a task and return two Readers that let us fetch the contents.

func LabelsForTask

func LabelsForTask(taskInfo *mesos.TaskInfo) map[string]string

LabelsForTask maps Mesos parameter lables to Docker labels

func NetworkForTask

func NetworkForTask(taskInfo *mesos.TaskInfo) string

NetworkForTask maps Mesos enum to strings for Docker

func PortBindingsForTask

func PortBindingsForTask(taskInfo *mesos.TaskInfo) map[docker.Port][]docker.PortBinding

PortBindingsForTask returns the actual ports bound to this container, not just EXPOSEd (equivalent to -P)

func PortsForTask

func PortsForTask(taskInfo *mesos.TaskInfo) map[docker.Port]struct{}

Translate Mesos TaskInfo port records in Docker ports map. These show up as EXPOSE

func PullImage

func PullImage(client DockerClient, taskInfo *mesos.TaskInfo, authConfig *docker.AuthConfiguration) error

PullImage will pull the Docker image refered to in the taskInfo. Uses the Docker credentials passed in.

func StopContainer

func StopContainer(client DockerClient, containerId string, timeout uint) error

Tries very hard to stop a container. Has to take a containerId instead of a mesos.TaskInfo because we don't have the TaskInfo in the KillTask callback from the executor driver.

func VolumeDriverForTask added in v0.9.3

func VolumeDriverForTask(taskInfo *mesos.TaskInfo) string

VolumeDriverForTask scans for volume-driver

Types

type DockerClient

type DockerClient interface {
	CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error)
	InspectContainer(id string) (*docker.Container, error)
	ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)
	ListImages(docker.ListImagesOptions) ([]docker.APIImages, error)
	Logs(opts docker.LogsOptions) error
	PullImage(docker.PullImageOptions, docker.AuthConfiguration) error
	StartContainer(id string, hostConfig *docker.HostConfig) error
	StopContainer(id string, timeout uint) error
}

Our own narrowly-scoped interface for Docker client

type MockDockerClient

type MockDockerClient struct {
	ValidOptions                    bool
	PullImageShouldError            bool // Set either this or PullImageSuccessAfterNumRetries
	PullImageSuccessAfterNumRetries int  // but not both
	PullImageRetries                int
	Images                          []docker.APIImages
	ListImagesShouldError           bool
	StopContainerShouldError        bool

	StopContainerMaxFails       int
	InspectContainerShouldError bool

	Container                 *docker.Container
	LogOutputString           string
	LogErrorString            string
	ListContainersShouldError bool
	ListContainersContainers  []docker.APIContainers
	ContainerStarted          bool
	// contains filtered or unexported fields
}

func (*MockDockerClient) CreateContainer

func (m *MockDockerClient) CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error)

func (*MockDockerClient) InspectContainer

func (m *MockDockerClient) InspectContainer(id string) (*docker.Container, error)

func (*MockDockerClient) ListContainers

func (m *MockDockerClient) ListContainers(opts docker.ListContainersOptions) ([]docker.APIContainers, error)

func (*MockDockerClient) ListImages

func (m *MockDockerClient) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error)

func (*MockDockerClient) Logs

func (m *MockDockerClient) Logs(opts docker.LogsOptions) error

func (*MockDockerClient) PullImage

func (m *MockDockerClient) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error

func (*MockDockerClient) StartContainer

func (m *MockDockerClient) StartContainer(id string, hostConfig *docker.HostConfig) error

func (*MockDockerClient) StopContainer

func (m *MockDockerClient) StopContainer(id string, timeout uint) error

Jump to

Keyboard shortcuts

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