lxf

package
Version: v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2020 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Overview

nolint: nestif

Index

Constants

View Source
const (
	WindowHeightDefault = 24
	WindowWidthDefault  = 80
)
View Source
const (
	SchemaVersionProfile   = zeroThree
	SchemaVersionContainer = zeroFive
)

Schema Version this package is currently expecting

Variables

View Source
var (
	ErrMissingETag = errors.New("missing ETag")
	ErrConvert     = errors.New("convert error")
	ErrParse       = errors.New("parse error")
	ErrUsage       = errors.New("usage error")
)
View Source
var (
	ErrExecTimeout     = errors.New("timeout reached")
	ErrNoControlSocket = errors.New("no control socket found")

	CodeExecOk      int32 = 0
	CodeExecError   int32 = 128
	CodeExecTimeout int32 = CodeExecError + int32(cancelSignal) // 128+15=143
)

Functions

func AppendIfSet

func AppendIfSet(s *map[string]string, key, value string)

AppendIfSet sets a key in a map[string]string with the value, if the value is not empty. And if there was already a value, append it after a newline

func IsCRI

func IsCRI(i interface{}) bool

IsCRI checks if a object is a cri object

func IsSchemaCurrent

func IsSchemaCurrent(i interface{}) bool

IsSchemaCurrent checks if a object is in the current schema

func SetIfSet

func SetIfSet(s *map[string]string, key, value string)

SetIfSet sets a key in a map[string]string with the value, if the value is not empty

Types

type CRIObject

type CRIObject struct {
	// Labels and Annotations to be saved provided by CRI
	Labels      map[string]string
	Annotations map[string]string
	// CreatedAt is when the resource was created
	CreatedAt time.Time
}

CRIObject contains common properties of containers and sandboxes

type Client

type Client interface {
	// GetServer returns the lxd ContainerServer. TODO: since it created it and others want to access lxd too (lxdbridge
	// network plugin) either return it here, or extract creation of the connection outside and pass server into
	// NewClient(), but that makes the initialisation NewClient() pretty unnecessary
	GetServer() lxd.ContainerServer
	// GetRuntimeInfo returns informations about the runtime
	GetRuntimeInfo() (*RuntimeInfo, error)
	// SetEventHandler for container's starting and stopping events
	SetEventHandler(eh EventHandler)

	// PullImage copies the given image from the remote server
	PullImage(name string) (string, error)
	// RemoveImage will remove the given image
	RemoveImage(name string) error
	// ListImages will list all local images from the lxd server
	ListImages(filter string) ([]Image, error)
	// GetImage will fetch information about the already downloaded image identified by name
	GetImage(name string) (*Image, error)
	// GetFSPoolUsage returns a list of usage information about the used storage pools
	GetFSPoolUsage() ([]FSPoolUsage, error)

	// NewSandbox creates a local representation of a sandbox
	NewSandbox() *Sandbox
	// GetSandbox will find a sandbox by id and return it.
	GetSandbox(id string) (*Sandbox, error)
	// ListSandboxes will return a list with all the available sandboxes
	ListSandboxes() ([]*Sandbox, error)

	// NewContainer creates a local representation of a container
	NewContainer(sandboxID string, additionalProfiles ...string) *Container
	// GetContainer returns the container identified by id
	GetContainer(id string) (*Container, error)
	// ListContainers returns a list of all available containers
	ListContainers() ([]*Container, error)

	// Exec will start a command on the server and attach the provided streams. It will block till the command terminated
	// AND all data was written to stdout/stdin. The caller is responsible to provide a sink which doesn't block.
	Exec(cid string, cmd []string, stdin io.ReadCloser, stdout, stderr io.WriteCloser, interactive, tty bool, timeout int64, resize <-chan remotecommand.TerminalSize) (int32, error)
}

Client is a facade to thin the interface to map the cri logic to lxd.

func NewClient

func NewClient(socket string, configPath string) (Client, error)

NewClient will set up a connection and return the client

type ConfigStore

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

ConfigStore contains the rules to split a config into different maps.

func NewConfigStore

func NewConfigStore() *ConfigStore

NewConfigStore initialises a new ConfigStore

func (*ConfigStore) IsReserved

func (c *ConfigStore) IsReserved(key string) bool

IsReserved checks if the key is either reserved or has a reserved prefix

func (*ConfigStore) StripedPrefixMap

func (c *ConfigStore) StripedPrefixMap(m map[string]string, prefix string) map[string]string

StripedPrefixMap filters out all the keys with given prefix and returns them whereas the keys are striped from the prefix. The . is added implicitly.

func (*ConfigStore) UnreservedMap

func (c *ConfigStore) UnreservedMap(m map[string]string) map[string]string

UnreservedMap returns a map with all unresrved entries

func (*ConfigStore) WithReserved

func (c *ConfigStore) WithReserved(keys ...string) *ConfigStore

WithReserved creates a new configstore with given reserved keys added

func (*ConfigStore) WithReservedPrefixes

func (c *ConfigStore) WithReservedPrefixes(keys ...string) *ConfigStore

WithReservedPrefixes creates a new configstore with given reserved key prefixes added. A trailing dot will automatically be used to match only full namespaces.

type Container

type Container struct {
	// LXDObject inherits common CRI fields
	LXDObject
	// Profiles of the container. First entry is always the sandbox profile
	// The default profile is always excluded and managed according to the settings automatically
	Profiles []string
	// Image defines the image to use, can be the hash or local alias
	Image string
	// Privileged defines if the container is run privileged
	Privileged bool
	// Environment specifies to the container exported environment variables
	Environment map[string]string

	// CRIObject inherits common CRI fields
	CRIObject
	// Metadata contains user defined data
	Metadata ContainerMetadata
	// StartedAt is when the container was started
	StartedAt time.Time
	// FinishedAt is when the container was exited
	FinishedAt time.Time
	// StateName of the current container
	StateName ContainerStateName
	// LogPath TODO, to be implemented?
	LogPath string
	// CloudInit fields
	CloudInitUserData      string
	CloudInitMetaData      string
	CloudInitNetworkConfig string
	// Resources contain cgroup information for handling resource constraints for the container
	Resources *opencontainers.LinuxResources
	// contains filtered or unexported fields
}

Container represents a LXD container including CRI specific configuration

func (*Container) Apply

func (c *Container) Apply() error

Apply will save the changes of a container if validation was successful, refreshes ETag after save

func (*Container) CreateID

func (c *Container) CreateID() string

CreateID creates a unique container id

func (*Container) Delete

func (c *Container) Delete() error

Delete the container, returns nil when container is already deleted or got deleted in the meantime, otherwise it will return an error.

func (*Container) GetInetAddress

func (c *Container) GetInetAddress(ifs []string) string

GetInetAddress returns the IPv4 address of the first matching interface in the parameter list empty string if nothing was found

func (*Container) Sandbox

func (c *Container) Sandbox() (*Sandbox, error)

Sandbox looks up the parent sandbox Implemented as lazy loading, and returns same result if already looked up Not thread safe! But it's expected the pointers stay in the same routine

func (*Container) SandboxID

func (c *Container) SandboxID() string

SandboxID returns the last profile name which is the sandbox profile name

func (*Container) Start

func (c *Container) Start() error

Start the container

func (*Container) State

func (c *Container) State() (*ContainerState, error)

State looks up additional state info Implemented as lazy loading, and returns same result if already looked up Not thread safe! But it's expected the pointers stay in the same routine

func (*Container) Stop

func (c *Container) Stop(timeout int) error

Stop will try to stop the container, returns nil when container is already stopped or got stopped in the meantime, otherwise it will return an error.

type ContainerMetadata

type ContainerMetadata struct {
	Name    string
	Attempt uint32
}

ContainerMetadata has the metadata neede by a container

type ContainerState

type ContainerState struct {
	// Pid of the container
	// +readonly
	Pid int64
	// Stats usage of the current container
	// +readonly
	Stats ContainerStats
	// Network represents the network information section of a LXD container's state
	// +readonly
	Network map[string]api.ContainerStateNetwork
}

ContainerState holds information about the container state

type ContainerStateName

type ContainerStateName string

ContainerStateName represents the state name of the container

const (
	// ContainerStateCreated it's there but not started yet
	ContainerStateCreated ContainerStateName = "created"
	// ContainerStateRunning it's there and running
	ContainerStateRunning ContainerStateName = "running"
	// ContainerStateExited it's there but terminated
	ContainerStateExited ContainerStateName = "exited"
	// ContainerStateUnknown it's there but we don't know what it's doing
	ContainerStateUnknown ContainerStateName = "unknown"
)

func (ContainerStateName) String

func (s ContainerStateName) String() string

type ContainerStats

type ContainerStats struct {
	MemoryUsage     uint64
	CPUUsage        uint64
	FilesystemUsage uint64
}

ContainerStats relevant for cri

type EventHandler

type EventHandler interface {
	ContainerStarted(ctx context.Context, c *Container) error
	ContainerStopped(ctx context.Context, c *Container) error
}

type FSPoolUsage

type FSPoolUsage struct {
	Timestamp  int64
	FsID       string
	UsedBytes  uint64
	InodesUsed uint64
}

FSPoolUsage contains fields to describe the usage of a filesystem / storagepool

type Image

type Image struct {
	Hash    string
	Aliases []string
	Size    int64
}

Image is here to translate the relevant data from lxd image to cri image

type ImageID

type ImageID struct {
	Remote string
	Alias  string
}

ImageID contains the remote and alias of an image identifier.

func (ImageID) Hash

func (i ImageID) Hash(l *client) (string, bool, error)

Hash returns the hash from the combined local tag or if it's already a hash this one. It it's not found second return will be false and error will be zero.

func (ImageID) Tag

func (i ImageID) Tag() string

Tag builds from remote and alias an alias for local

type LXDObject

type LXDObject struct {

	// ID is a unique generated ID and is read-only
	ID string
	// ETag uniquely identifies user modifiable content of this resource, prevents race conditions when saving
	// see: https://lxd.readthedocs.io/en/latest/api-extensions/#etag
	ETag string
	// ETag uniquely identifies user modifiable content of the state of this resource, prevents race conditions when
	// trying to modify the state
	//Stateetag string
	// Devices
	Devices device.Devices
	// Config contains options not provided by a own property
	Config map[string]string
	// contains filtered or unexported fields
}

LXDObject contains common properties of containers and sandboxes without CRI influence

type MigrationWorkspace

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

MigrationWorkspace manages schema of lxd objects

func NewMigrationWorkspace added in v0.2.1

func NewMigrationWorkspace(l Client) *MigrationWorkspace

Migration initializes the migration workspace

func (*MigrationWorkspace) Ensure

func (m *MigrationWorkspace) Ensure() error

Ensure applies all migration steps from detected schema to current schema

type NetworkConfig

type NetworkConfig struct {
	Nameservers []string
	Searches    []string
	// Mode describes the type of networking
	Mode NetworkMode
	// ModeData allows Mode-specific data to be persisted
	ModeData map[string]string
}

NetworkConfig contains the network config searches and nameservers must not be empty to be valid

type NetworkMode

type NetworkMode string

NetworkMode defines the type of the container network

const (
	NetworkHost    NetworkMode = "node"
	NetworkCNI     NetworkMode = "cni"
	NetworkBridged NetworkMode = "bridged"
	NetworkNone    NetworkMode = "none"
)

These are valid network modes. NetworkHost means the container to share the host's network namespace NetworkCNI means the CNI handles the interface, NetworkBridged means the container gets a interface from a predefined bridge, NetworkNone is used when the requested mode can't be used

func (NetworkMode) String

func (s NetworkMode) String() string

type RuntimeInfo added in v0.2.1

type RuntimeInfo struct {
	// API version of the container runtime. The string must be semver-compatible.
	Version string
}

type Sandbox

type Sandbox struct {
	// LXDObject inherits common CRI fields
	LXDObject
	// UsedBy contains the names of the containers using this profile
	// It is read only.
	UsedBy []string

	// CRIObject inherits common CRI fields
	CRIObject
	// Metadata contains user defined data
	Metadata SandboxMetadata
	// Hostname to be set for containers if defined
	Hostname string
	// NetworkConfig to be applied for the sandbox and it's containers
	NetworkConfig NetworkConfig
	// State contains the current state of this sandbox
	State SandboxState
	// LogDirectory TODO, to be implemented?
	LogDirectory string
	// CloudInitNetworkConfigEntries to set
	CloudInitNetworkConfigEntries []cloudinit.NetworkConfigEntryPhysical
	// contains filtered or unexported fields
}

Sandbox is an abstraction of a CRI PodSandbox saved as a LXD profile

func (*Sandbox) Apply

func (s *Sandbox) Apply() error

Apply will save the changes of a sandbox

func (*Sandbox) Containers

func (s *Sandbox) Containers() ([]*Container, error)

Containers looks up all assigned containers Implemented as lazy loading, and returns same result if already looked up Not thread safe! But it's expected the pointers stay in the same routine

func (*Sandbox) CreateID

func (s *Sandbox) CreateID() string

CreateID creates a unique profile id

func (*Sandbox) Delete

func (s *Sandbox) Delete() error

Delete will delete the given sandbox, returns nil when sandbox is already deleted

func (*Sandbox) Stop

func (s *Sandbox) Stop() error

Stop set the sandbox state to SandboxNotReady

type SandboxMetadata

type SandboxMetadata struct {
	Attempt   uint32
	Name      string
	Namespace string
	UID       string
}

SandboxMetadata contains common metadata values

type SandboxState

type SandboxState string

SandboxState defines the state of the sandbox

const (
	SandboxNotReady SandboxState = "notready"
	SandboxReady    SandboxState = "ready"
)

These are valid sandbox statuses. SandboxReady means a resource is in the condition. SandboxNotReady means a resource is not in the condition.

func (SandboxState) String

func (s SandboxState) String() string

Directories

Path Synopsis
nolint: dupl nolint: dupl
nolint: dupl nolint: dupl
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL