container

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2020 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// ConfigMountpoint is where host file-system is mounted in the -config container.
	ConfigMountpoint = "/mnt/host"
)

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" yaml:"config"`
	// Status of the container
	Status *types.ContainerStatus `json:"status" yaml:"status"`
	// Runtime stores configuration for various container runtimes
	Runtime RuntimeConfig `json:"runtime,omitempty" yaml:"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) Copy

func (c *Container) Copy(files []*types.File) error

Copy creates a file in desired path in the container

func (*Container) Create

func (c *Container) Create() error

Create creates container and gets it's status

func (*Container) Delete

func (c *Container) Delete() error

Delete removes container and removes it's status

func (*Container) Exists

func (c *Container) Exists() bool

Exists returns true, if the container has been created.

func (*Container) IsRunning

func (c *Container) IsRunning() bool

IsRunning returns true, if container exists and it's running.

func (*Container) Read

func (c *Container) Read(srcPath []string) ([]*types.File, error)

Read takes file path as an argument and reads this file from the container

func (*Container) Start

func (c *Container) Start() error

Start starts existing Container and updates it's status

func (*Container) Stat

func (c *Container) Stat(paths []string) (map[string]*os.FileMode, error)

Stat checks if files exist in the container. It returns map of files mode for each requested file.

func (*Container) Stop

func (c *Container) Stop() error

Stop stops existing Container and updates it's status

func (*Container) ToInstance

func (c *Container) ToInstance() (InstanceInterface, error)

ToInstance returns containerInstance directly from Container

func (*Container) UpdateStatus

func (c *Container) UpdateStatus() error

UpdateStatus reads container existing status and updates it by communicating with container daemon This is a helper function, which simplifies calling containerInstance.Status() from Container.

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" yaml:"previousState"`
	// DesiredState is a user-defined desired containers configuration.
	DesiredState ContainersState `json:"desiredState" yaml:"desiredState"`
}

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
	Execute() error
	CurrentStateToYaml() ([]byte, error)
	ToExported() *Containers
}

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" yaml:"container"`
	Host        host.Host         `json:"host" yaml:"host"`
	ConfigFiles map[string]string `json:"configFiles,omitempty" yaml:"configFiles,omitempty"`

	Hooks *Hooks `json:"-" yaml:"-"`
}

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 {
	GetRuntimeAddress() string
	SetRuntimeAddress(string)
	Create() (InstanceInterface, error)
	FromStatus() (InstanceInterface, error)
}

Interface represents container capabilities.

func New

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

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

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" yaml:"docker,omitempty"`
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳