Documentation ¶
Overview ¶
nolint: nestif
Index ¶
- Constants
- Variables
- func AppendIfSet(s *map[string]string, key, value string)
- func GetContainerIDFromSelflink(path string) string
- func IsNotFoundError(err error) bool
- func IsSchemaCurrent(i interface{}) bool
- func SetIfSet(s *map[string]string, key, value string)
- type CRIObject
- type Client
- type ConfigStore
- func (c *ConfigStore) IsReserved(key string) bool
- func (c *ConfigStore) StrippedPrefixMap(m map[string]string, prefix string) map[string]string
- func (c *ConfigStore) UnreservedMap(m map[string]string) map[string]string
- func (c *ConfigStore) WithReserved(keys ...string) *ConfigStore
- func (c *ConfigStore) WithReservedPrefixes(keys ...string) *ConfigStore
- type Container
- func (c *Container) Apply() error
- func (c *Container) CreateID() string
- func (c *Container) Delete() error
- func (c *Container) GetInetAddress(ifs []string) string
- func (c *Container) Sandbox() (*Sandbox, error)
- func (c *Container) SandboxID() string
- func (c *Container) Start() error
- func (c *Container) State() (*ContainerState, error)
- func (c *Container) Stop(timeout int) error
- type ContainerMetadata
- type ContainerState
- type ContainerStateName
- type ContainerStats
- type EventHandler
- type FSPoolUsage
- type Image
- type LXDObject
- type MigrationWorkspace
- type NetworkConfig
- type NetworkMode
- type RuntimeInfo
- type Sandbox
- type SandboxMetadata
- type SandboxState
- type TestImageList
Constants ¶
const ( WindowHeightDefault = 24 WindowWidthDefault = 80 )
const ( SchemaVersionProfile = zeroThree SchemaVersionContainer = zeroFive )
Schema Version this package is currently expecting
const ContainerSelflinkMatch = 2
ContainerSelflinkMatch-es which index of the match contains the containername
Variables ¶
var ( ErrMissingETag = errors.New("missing ETag") ErrConvert = errors.New("convert error") ErrParse = errors.New("parse error") ErrUsage = errors.New("usage error") )
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 )
nolint: revive
var ContainerSelflinkRegex = regexp.MustCompile(`^/[\d.]+/(instances|containers)/(.*)(\?.*)?$`)
ContainerSelflinkRegex to extract the containername in selflinks.
var ErrNotFound = errors.New("not found")
ErrNotFound for CRI related checks
Functions ¶
func AppendIfSet ¶
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 GetContainerIDFromSelflink ¶ added in v0.4.1
Returns the containername from a selflink address. Returns empty if not found
func IsNotFoundError ¶ added in v0.4.1
Whether err is a not found error from lxd api response or this package
func IsSchemaCurrent ¶
func IsSchemaCurrent(i interface{}) bool
IsSchemaCurrent checks if a object is in the current schema
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) // SetCRITestMode enables the critest mode SetCRITestMode() // PullImage copies the given image from the remote server PullImage(image string) (string, error) // RemoveImage will remove a pulled image RemoveImage(image string) error // ListImages will list all pulled images ListImages(filter string) ([]*Image, error) // GetImage will fetch information about a pulled image GetImage(image 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.
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) StrippedPrefixMap ¶ added in v0.4.1
StrippedPrefixMap 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 // The image fingerprint to use 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 ¶
Apply will save the changes of a container if validation was successful, refreshes ETag after save
func (*Container) Delete ¶
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 ¶
GetInetAddress returns the IPv4 address of the first matching interface in the parameter list empty string if nothing was found
func (*Container) Sandbox ¶
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 ¶
SandboxID returns the last profile name which is the sandbox profile name
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
type ContainerMetadata ¶
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 ¶
ContainerStats relevant for cri
type EventHandler ¶
type FSPoolUsage ¶
FSPoolUsage contains fields to describe the usage of a filesystem / storagepool
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) Containers ¶
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
type SandboxMetadata ¶
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
type TestImageList ¶ added in v0.4.1
type TestImageList struct { DefaultTestContainerImage string `yaml:"defaultTestContainerImage"` WebServerTestImage string `yaml:"webServerTestImage"` }
TestImageList aggregates references to the images used in tests. Borrowed from github.com/kubernetes-sigs/cri-tools/pkg/framework/test_context.go