container

package
v0.0.0-...-b8e83fa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2022 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CreatedContainerStatus indicates container has been created
	CreatedContainerStatus = "created"
	// RunningContainerStatus indicates container is in running state
	RunningContainerStatus = "running"
	// PausedContainerStatus indicates container is in paused state
	PausedContainerStatus = "paused"
	// RestartedContainerStatus indicates container has re-started
	RestartedContainerStatus = "restarted"
	// RemovingContainerStatus indicates container is being removed
	RemovingContainerStatus = "removing"
	// ExitedContainerStatus indicates container has exited
	ExitedContainerStatus = "exited"
	// DeadContainerStatus indicates container is dead
	DeadContainerStatus = "dead"
)
View Source
const (
	// DriverDocker indicates that docker driver should be used in container constructor
	DriverDocker = "docker"
)

Variables

This section is empty.

Functions

func ExpandSourceMounts

func ExpandSourceMounts(storageMounts []v1alpha1.StorageMount, targetPath string)

ExpandSourceMounts converts relative paths into absolute ones

Types

type ClientV1Alpha1

type ClientV1Alpha1 interface {
	Run() error
}

ClientV1Alpha1 provides airship generic container API TODO add generic mock for this client

func NewClientV1Alpha1

func NewClientV1Alpha1(
	resultsDir string,
	input io.Reader,
	output io.Writer,
	conf *v1alpha1.GenericContainer,
	targetPath string) ClientV1Alpha1

NewClientV1Alpha1 constructor for ClientV1Alpha1

type ClientV1Alpha1FactoryFunc

type ClientV1Alpha1FactoryFunc func(
	resultsDir string,
	input io.Reader,
	output io.Writer,
	conf *v1alpha1.GenericContainer,
	targetPath string) ClientV1Alpha1

ClientV1Alpha1FactoryFunc used for tests

type Container

type Container interface {
	ImagePull() error
	RunCommand(RunCommandOptions) error
	GetContainerLogs(GetLogOptions) (io.ReadCloser, error)
	InspectContainer() (State, error)
	WaitUntilFinished() error
	RmContainer() error
	GetID() string
}

Container interface abstraction for container. Particular implementation depends on container runtime environment (CRE). Interface defines methods that must be implemented for CRE (e.g. docker, containerd or CRI-O)

func NewContainer

func NewContainer(ctx context.Context, driver string, url string) (Container, error)

NewContainer returns instance of Container interface implemented by particular driver Returned instance type (i.e. implementation) depends on driver specified via function arguments (e.g. "docker"). Supported drivers:

  • docker

type DockerClient

type DockerClient interface {
	// ImageInspectWithRaw returns the image information and its raw
	// representation.
	ImageInspectWithRaw(
		context.Context,
		string,
	) (types.ImageInspect, []byte, error)
	// ImageList returns a list of images in the docker host.
	ImageList(
		context.Context,
		types.ImageListOptions,
	) ([]types.ImageSummary, error)
	// ImagePull requests the docker host to pull an image from a remote registry.
	ImagePull(
		context.Context,
		string,
		types.ImagePullOptions,
	) (io.ReadCloser, error)
	// ContainerCreate creates a new container based in the given configuration.
	ContainerCreate(
		context.Context,
		*container.Config,
		*container.HostConfig,
		*network.NetworkingConfig,
		*specs.Platform,
		string,
	) (container.ContainerCreateCreatedBody, error)
	// ContainerAttach attaches a connection to a container in the server.
	ContainerAttach(
		context.Context,
		string,
		types.ContainerAttachOptions,
	) (types.HijackedResponse, error)
	//ContainerStart sends a request to the docker daemon to start a container.
	ContainerStart(context.Context, string, types.ContainerStartOptions) error
	// ContainerWait waits until the specified container is in a certain state
	// indicated by the given condition, either "not-running" (default),
	// "next-exit", or "removed".
	ContainerWait(
		context.Context,
		string,
		container.WaitCondition,
	) (<-chan container.ContainerWaitOKBody, <-chan error)
	// ContainerLogs returns the logs generated by a container in an
	// io.ReadCloser.
	ContainerLogs(
		context.Context,
		string,
		types.ContainerLogsOptions,
	) (io.ReadCloser, error)
	// ContainerRemove kills and removes a container from the docker host.
	ContainerRemove(
		context.Context,
		string,
		types.ContainerRemoveOptions,
	) error
	// ContainerInspect returns the container state
	ContainerInspect(
		ctx context.Context,
		containerID string,
	) (types.ContainerJSON, error)
}

DockerClient interface that represents abstract Docker client object Interface used as a wrapper for upstream docker client object

func NewDockerClient

func NewDockerClient(ctx context.Context) (DockerClient, error)

NewDockerClient returns instance of DockerClient. Function essentially returns new Docker API client with default values

type DockerContainer

type DockerContainer struct {
	Tag          string
	ImageURL     string
	ID           string
	DockerClient DockerClient
	Ctx          context.Context
}

DockerContainer docker container object wrapper

func NewDockerContainer

func NewDockerContainer(ctx context.Context, url string, cli DockerClient) (*DockerContainer, error)

NewDockerContainer returns instance of DockerContainer object wrapper. Function gets container image url, pointer to execution context and DockerClient instance.

url format: <image_path>:<tag>. If tag is not specified "latest" is used as default value

func (*DockerContainer) GetCmd

func (c *DockerContainer) GetCmd(cmd []string) ([]string, error)

GetCmd identifies container command. Accepts list of strings each element represents command part (e.g "sample cmd --key" should be transformed to []string{"sample", "command", "--key"})

If input parameter is NOT empty list method returns input parameter immediately

If input parameter is empty list method identifies container image and tries to extract Cmd option from this image description (i.e. tries to identify default command specified in Dockerfile)

func (*DockerContainer) GetContainerLogs

func (c *DockerContainer) GetContainerLogs(opts GetLogOptions) (io.ReadCloser, error)

GetContainerLogs returns logs from the container as io.ReadCloser

func (*DockerContainer) GetID

func (c *DockerContainer) GetID() string

GetID returns ID of the container

func (*DockerContainer) GetImageID

func (c *DockerContainer) GetImageID(url string) (string, error)

GetImageID return ID of container image specified by URL. Method executes ImageList function supplied with "reference" filter

func (*DockerContainer) ImagePull

func (c *DockerContainer) ImagePull() error

ImagePull downloads image for container

func (*DockerContainer) InspectContainer

func (c *DockerContainer) InspectContainer() (State, error)

InspectContainer inspect the running container

func (*DockerContainer) RmContainer

func (c *DockerContainer) RmContainer() error

RmContainer kills and removes a container from the docker host.

func (*DockerContainer) RunCommand

func (c *DockerContainer) RunCommand(opts RunCommandOptions) (err error)

RunCommand executes specified command in Docker container. Method handles container STDIN and volume binds

func (*DockerContainer) WaitUntilFinished

func (c *DockerContainer) WaitUntilFinished() error

WaitUntilFinished waits unit container command is finished, return an error if failed

type ErrContainerDrvNotSupported

type ErrContainerDrvNotSupported struct {
	Driver string
}

ErrContainerDrvNotSupported returned if desired CRI is not supported

func (ErrContainerDrvNotSupported) Error

type ErrEmptyImageList

type ErrEmptyImageList struct {
}

ErrEmptyImageList returned if no image defined in filter found

func (ErrEmptyImageList) Error

func (e ErrEmptyImageList) Error() string

type ErrNoContainerDriver

type ErrNoContainerDriver struct {
}

ErrNoContainerDriver returned if no runtime defined in config

func (ErrNoContainerDriver) Error

func (e ErrNoContainerDriver) Error() string

type ErrRunContainerCommand

type ErrRunContainerCommand struct {
	Cmd string
}

ErrRunContainerCommand returned if container command exited with non-zero code

func (ErrRunContainerCommand) Error

func (e ErrRunContainerCommand) Error() string

type Func

type Func func(ctx context.Context, driver string, url string) (Container, error)

Func is type of function which returns Container object

type GetLogOptions

type GetLogOptions struct {
	Stderr bool
	Stdout bool
	Follow bool
}

GetLogOptions options for getting logs If both Stderr and Stdout are specified the logs will contain both stderr and stdout

type Mount

type Mount struct {
	ReadOnly bool
	Type     string
	Dst      string
	Src      string
}

Mount describes mount settings

type RunCommandOptions

type RunCommandOptions struct {
	Privileged  bool
	HostNetwork bool

	Cmd     []string
	EnvVars []string
	Binds   []string

	Mounts []Mount
	Input  io.Reader
}

RunCommandOptions options for RunCommand

type State

type State struct {
	// ExitCode: returns the container's exit code. Zero means exited normally, otherwise errored
	ExitCode int
	// Status: String representation of the container state.
	Status Status
}

State provides information about the Container

type Status

type Status string

Status type provides container status

type V1Alpha1

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

V1Alpha1 reflects inner struct of ClientV1Alpha1 Interface

func NewV1Alpha1

func NewV1Alpha1(resultsDir string,
	input io.Reader,
	output io.Writer,
	conf *v1alpha1.GenericContainer,
	targetPath string,
	containerFunc Func) V1Alpha1

NewV1Alpha1 returns V1Alpha1 struct with desired parameters

func (*V1Alpha1) Run

func (c *V1Alpha1) Run() error

Run will perform container run action based on the configuration

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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