container

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2020 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package container allows to run and manage multiple containers across multiple hosts, by talking directly to the container runtime on local or remote hosts.

Index

Constants

View Source
const (
	// ConfigMountpoint is where host file-system is mounted in the -config container.
	ConfigMountpoint = "/mnt/host"
)
View Source
const (
	// StatusMissing is a value, which is set to ContainerStatus.Status field,
	// if stored container ID is not found.
	StatusMissing = "gone"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

type Container struct {
	// Stores runtime configuration of the container.
	Config types.ContainerConfig `json:"config"`
	// Status of the container.
	Status *types.ContainerStatus `json:"status,omitempty"`
	// Runtime stores configuration for various container runtimes.
	Runtime RuntimeConfig `json:"runtime,omitempty"`
}

Container represents public, serializable version of the container object.

It should be used for persisting and restoring container state with combination with New(), which make sure that the configuration is actually correct.

func (*Container) New added in v0.2.0

func (c *Container) New() (Interface, error)

New creates new instance of container from Container and validates it's configuration It also validates container runtime configuration.

func (*Container) Validate

func (c *Container) Validate() error

Validate validates container configuration.

type Containers

type Containers struct {
	// PreviousState stores previous state of the containers, which should be obtained and persisted
	// after containers modifications.
	PreviousState ContainersState `json:"previousState,omitempty"`
	// DesiredState is a user-defined desired containers configuration.
	DesiredState ContainersState `json:"desiredState,omitempty"`
}

Containers allow to orchestrate and update multiple containers spread across multiple hosts and update their configurations.

func (*Containers) CheckCurrentState

func (c *Containers) CheckCurrentState() error

CheckCurrentState checks the state of existing containers and updates their state.

func (*Containers) Deploy

func (c *Containers) Deploy() error

Deploy deploys defined containers.

func (*Containers) New

func (c *Containers) New() (ContainersInterface, error)

New validates Containers configuration and returns "executable" containers object.

func (*Containers) Validate

func (c *Containers) Validate() error

Validate validates Containers struct and all structs used underneath.

type ContainersInterface

type ContainersInterface interface {
	CheckCurrentState() error
	Deploy() error
	StateToYaml() ([]byte, error)
	ToExported() *Containers
	DesiredState() ContainersState
	Containers() ContainersInterface
}

ContainersInterface represents capabilities of containers struct.

func FromYaml

func FromYaml(c []byte) (ContainersInterface, error)

FromYaml allows to restore containers state from YAML.

type ContainersState

type ContainersState map[string]*HostConfiguredContainer

ContainersState represents states of multiple containers.

func (ContainersState) New

New validates ContainersState struct and returns operational containerState.

type ContainersStateInterface

type ContainersStateInterface interface {
	CheckState() error
	RemoveContainer(containerName string) error
	CreateAndStart(containerName string) error
	Export() ContainersState
}

ContainersStateInterface exports constainersState capabilities.

type Hook

type Hook func() error

Hook is an action, which may be called before or after certain container operation, like starting or creating.

type Hooks

type Hooks struct {
	PostStart *Hook
}

Hooks defines type of hooks HostConfiguredContainer supports.

type HostConfiguredContainer

type HostConfiguredContainer struct {
	Container   Container         `json:"container"`
	Host        host.Host         `json:"host"`
	ConfigFiles map[string]string `json:"configFiles,omitempty"`

	Hooks *Hooks `json:"-"`
}

HostConfiguredContainer represents single container, running on remote host with it's configuration files.

func (*HostConfiguredContainer) New

New validates HostConfiguredContainer struct and return it's executable version.

func (*HostConfiguredContainer) Validate

func (m *HostConfiguredContainer) Validate() error

Validate validates HostConfiguredContainer struct. All validation rules should be placed here.

type HostConfiguredContainerInterface

type HostConfiguredContainerInterface interface {
	ConfigurationStatus() error
	Configure(paths []string) error
	Create() error
	Status() error
	Start() error
	Stop() error
	Delete() error
}

HostConfiguredContainerInterface exports hostConfiguredContainer capabilities.

type InstanceInterface

type InstanceInterface interface {
	Status() (types.ContainerStatus, error)
	Read(srcPath []string) ([]*types.File, error)
	Copy(files []*types.File) error
	Stat(paths []string) (map[string]os.FileMode, error)
	Start() error
	Stop() error
	Delete() error
}

InstanceInterface represents containerInstance capabilities.

type Interface

type Interface interface {
	// Methods to instantiate Instance.
	Create() (InstanceInterface, error)
	FromStatus() (InstanceInterface, error)

	// Helpers.
	UpdateStatus() error
	Start() error
	Stop() error
	Delete() error
	Status() *types.ContainerStatus

	// Getters.
	Config() types.ContainerConfig
	RuntimeConfig() runtime.Config
	Runtime() runtime.Runtime

	// Setters.
	SetRuntime(runtime.Runtime)
	SetStatus(types.ContainerStatus)
}

Interface represents container capabilities.

type ResourceInstance

type ResourceInstance interface {
	ToHostConfiguredContainer() (*HostConfiguredContainer, error)
}

ResourceInstance interface represents struct, which can be converted to HostConfiguredContainer.

type RuntimeConfig

type RuntimeConfig struct {
	Docker *docker.Config `json:"docker,omitempty"`
}

RuntimeConfig is a collection of various runtime configurations which can be defined by user.

Directories

Path Synopsis
Package resource stores a wrapper over container.Containers, which implements types.Resource interface.
Package resource stores a wrapper over container.Containers, which implements types.Resource interface.
Package runtime provides interfaces describing container runtimes in generic way and their functionality.
Package runtime provides interfaces describing container runtimes in generic way and their functionality.
docker
Package docker implements runtime.Interface and runtime.Config interfaces by talking to Docker API.
Package docker implements runtime.Interface and runtime.Config interfaces by talking to Docker API.
Package types contains types used for managing the containers.
Package types contains types used for managing the containers.

Jump to

Keyboard shortcuts

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