box

package
v0.0.35-0...-fad7822 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CgroupNSEnabled

func CgroupNSEnabled() (bool, error)

CgroupNSEnabled checks whether the system has cgroup namespaces enabled Based on internal function from runc https://github.com/opencontainers/runc/blob/029124da7af7360afa781a0234d1b083550f797c/libcontainer/configs/validate/validator.go#L122-L129

func CombinedOutput

func CombinedOutput(config EnterConfig) ([]byte, error)

CombinedOutput runs a process within planet, returning the output as a byte buffer

func Enter

func Enter(config EnterConfig) error

Enter is used to exec a process within the running container

func Init

func Init() error

Init is implicitly called by the libcontainer logic and is used to start a process in the new namespaces and cgroups

func MountCgroups

func MountCgroups(root string) error

func NewSignalForwarder

func NewSignalForwarder() signalForwarder

NewsignalForwarder creates a default signalForwarder

func WriteEnvironment

func WriteEnvironment(path string, env EnvVars) error

WriteEnvironment writes provided environment variables to a file at the specified path.

Types

type Box

type Box struct {
	*libcontainer.Process
	libcontainer.Container
	// contains filtered or unexported fields
}

Box defines a running planet container.

A box manages a number of resources including an init process and an API server that exposes a unix socket endpoint. Once started, the box can be shut down with Close.

func Start

func Start(cfg Config) (*Box, error)

Starts the container described by cfg. Returns a Box instance or an error.

func (*Box) Close

func (b *Box) Close() error

Close shuts down the box. It is written to be safe to call multiple times in a row for extra robustness.

func (*Box) CombinedOutput

func (b *Box) CombinedOutput(config ProcessConfig) ([]byte, error)

CombinedOutput runs a process within planet, returning the output as a byte buffer

func (*Box) Wait

func (b *Box) Wait() (*os.ProcessState, error)

Wait blocks waiting the init process to finish. Returns the state of the init process.

type Config

type Config struct {
	// InitArgs lists the command to execute and any arguments
	InitArgs []string
	// InitEnv lists the environment variables to pass to the process
	InitEnv []string
	// InitUser is a user running the init process
	InitUser string
	// EnvFiles has a list of files that will generated when process starts
	EnvFiles []EnvFile
	// Files is an optional list of files that will be placed
	// in the container when started
	Files []File
	// Rootfs is a root filesystem of the container
	Rootfs string
	// Mounts is a list of device/directory/file mounts passed to the server
	Mounts Mounts
	// Devices is a list of devices to create inside the container
	Devices Devices
	// Capabilities is a list of capabilities of this container
	Capabilities []string
	// DataDir is a directory where libcontainer stores the container state
	DataDir string
	// ProcessLabel specifies the SELinux process label
	ProcessLabel string
	// SELinux turns on SELinux support
	SELinux bool
	// FieldLogger specifies the logger
	log.FieldLogger
}

Config defines the configuration of the planet container

type ContainerServer

type ContainerServer interface {
	Enter(cfg ProcessConfig) error
}

type DNSOverrides

type DNSOverrides map[string][]string

DNSOverrides is a command-line flag parser for DNS host/zone overrides

func (*DNSOverrides) Set

func (d *DNSOverrides) Set(v string) error

Set sets the overrides value from a CLI flag

func (*DNSOverrides) String

func (d *DNSOverrides) String() string

String formats overrides to a string

type Device

type Device struct {
	// Path is the device path, treated as a glob
	Path string
	// Permissions is the device permissions
	Permissions string
	// FileMode is the device file mode
	FileMode os.FileMode
	// UID is the device user ID
	UID uint32
	// GID is the device group ID
	GID uint32
}

Device represents a device that should be created in planet

func (Device) Format

func (d Device) Format() string

Format formats the device to a string

type Devices

type Devices []Device

Devices represents a list of devices

func (*Devices) Set

func (d *Devices) Set(v string) error

Set sets the devices from CLI flags

func (*Devices) String

func (d *Devices) String() string

String converts devices to a string

type EnterConfig

type EnterConfig struct {
	// Process specifies the process configuration to execute
	Process ProcessConfig
	// DataDir specifies the runc-specific data directory
	DataDir string
	// SELinux specifies whether SELinux support is on
	SELinux bool
}

EnterConfig specifies the configuration to execute a command inside the container

type EnvFile

type EnvFile struct {
	Path string
	Env  EnvVars
}

environment file to write when container starts

type EnvPair

type EnvPair struct {
	// Name is the name of the environment variable
	Name string `json:"name"`
	// Val defines the value of the environment variable
	Val string `json:"val"`
}

EnvPair defines an environment variable

type EnvVars

type EnvVars []EnvPair

EnvVars is a list of environment variables

func ReadEnvironment

func ReadEnvironment(path string) (vars EnvVars, err error)

ReadEnvironment returns a list of all environment variables read from the file at the specified path.

func (*EnvVars) Append

func (vars *EnvVars) Append(k, v string)

Append adds a new environment variable given with k, v and delimiter delim

func (*EnvVars) Delete

func (vars *EnvVars) Delete(v string) string

Delete removes the environment variable named v from the list and returns its value

func (*EnvVars) Environ

func (vars *EnvVars) Environ() (environ []string)

Environ returns this EnvVars as a list of name=value pairs

func (*EnvVars) Get

func (vars *EnvVars) Get(v string) string

Get returns the value of the environment variable named v

func (*EnvVars) Set

func (vars *EnvVars) Set(v string) error

Set parses v as a comma-separated list of name=value pairs. If a value contains a comma, it must be quoted.

func (*EnvVars) String

func (vars *EnvVars) String() string

String formats this object as a string with comma-separated list of name=value pairs

func (*EnvVars) Upsert

func (vars *EnvVars) Upsert(k, v string)

Upsert adds a new environment variable given with k and v. If the environment variable with the name k already exists, it is updated

type ErrConnect

type ErrConnect struct {
	Err error // Original error
}

func (*ErrConnect) Error

func (e *ErrConnect) Error() string

type ExitError

type ExitError struct {
	// Code specifies the process exit code
	Code int
}

ExitError is an error that describes the event of a process exiting with a non-zero value.

func (ExitError) Error

func (err ExitError) Error() string

Error formats the ExitError as a string with the status code

type File

type File struct {
	Path     string
	Contents io.Reader
	Mode     os.FileMode
	Owners   *FileOwner
}

File is a file that will be placed in the container before start

type FileOwner

type FileOwner struct {
	UID int
	GID int
}

type Mount

type Mount struct {
	// Src defines the source for the mount on host
	Src string
	// Dst defines the mount point inside the container
	Dst string
	// Readonly specifies that the mount is created readonly
	Readonly bool
	// SkipIfMissing instructs to skip the mount if the Src is non-existent
	SkipIfMissing bool
	// Recursive indicates that all mount points inside this mount should also be mounted
	Recursive bool
}

Mount defines a mapping from a host location to some location inside the container

type Mounts

type Mounts []Mount

func (*Mounts) Set

func (m *Mounts) Set(v string) error

func (*Mounts) String

func (m *Mounts) String() string

type ProcessConfig

type ProcessConfig struct {
	In           io.Reader `json:"-"`
	Out          io.Writer `json:"-"`
	TTY          *TTY      `json:"tty,omitempty"`
	Args         []string  `json:"args"`
	User         string    `json:"user"`
	Env          EnvVars   `json:"env,omitempty"`
	ProcessLabel string    `json:"process_label,omitempty"`
}

ProcessConfig is a configuration passed to the process started in the namespace of the container

func (*ProcessConfig) Environment

func (e *ProcessConfig) Environment() []string

Environment returns a slice of environment variables in key=value format as required by libcontainer

func (*ProcessConfig) String

func (e *ProcessConfig) String() string

String returns human-readable description of this configuration

type TTY

type TTY struct {
	W int
	H int
}

TTY is a tty settings passed to the device when allocating terminal

type Winsize

type Winsize struct {
	Height uint16
	Width  uint16
	// contains filtered or unexported fields
}

Winsize represents the size of the terminal window.

func GetWinsize

func GetWinsize(fd uintptr) (*Winsize, error)

GetWinsize returns the window size based on the specified file descriptor.

Jump to

Keyboard shortcuts

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