oci

package
v1.14.11 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AttachPipeStdin  = 1
	AttachPipeStdout = 2
	AttachPipeStderr = 3
)

Sync with stdpipe_t in conmon.c

View Source
const (
	// ContainerStateCreated represents the created state of a container
	ContainerStateCreated = "created"
	// ContainerStatePaused represents the paused state of a container
	ContainerStatePaused = "paused"
	// ContainerStateRunning represents the running state of a container
	ContainerStateRunning = "running"
	// ContainerStateStopped represents the stopped state of a container
	ContainerStateStopped = "stopped"
	// ContainerCreateTimeout represents the value of container creating timeout
	ContainerCreateTimeout = 240 * time.Second

	// CgroupfsCgroupsManager represents cgroupfs native cgroup manager
	CgroupfsCgroupsManager = "cgroupfs"
	// SystemdCgroupsManager represents systemd native cgroup manager
	SystemdCgroupsManager = "systemd"

	// BufSize is the size of buffers passed in to sockets
	BufSize = 8192
)
View Source
const (
	// ContainerExitsDir is the location of container exit dirs
	ContainerExitsDir = "/var/run/crio/exits"
	// ContainerAttachSocketDir is the location for container attach sockets
	ContainerAttachSocketDir = "/var/run/crio"
)
View Source
const (
	// RuntimeTypeOCI is the type representing the RuntimeOCI implementation.
	RuntimeTypeOCI = "oci"
)
View Source
const (

	// RuntimeTypeVM is the type representing the RuntimeVM implementation.
	RuntimeTypeVM = "vm"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Container

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

Container represents a runtime container.

func NewContainer

func NewContainer(id string, name string, bundlePath string, logPath string, netns string, labels map[string]string, crioAnnotations map[string]string, annotations map[string]string, image string, imageName string, imageRef string, metadata *pb.ContainerMetadata, sandbox string, terminal bool, stdin bool, stdinOnce bool, privileged bool, runtimeHandler string, dir string, created time.Time, stopSignal string) (*Container, error)

NewContainer creates a container object.

func (*Container) AddVolume added in v1.0.0

func (c *Container) AddVolume(v ContainerVolume)

AddVolume adds a volume to list of container volumes.

func (*Container) Annotations

func (c *Container) Annotations() map[string]string

Annotations returns the annotations of the container.

func (*Container) BundlePath

func (c *Container) BundlePath() string

BundlePath returns the bundlePath of the container.

func (*Container) CleanupConmonCgroup added in v1.14.8

func (c *Container) CleanupConmonCgroup()

CleanupConmonCgroup cleans up conmon's group when using cgroupfs.

func (*Container) ConmonCgroupfsPath added in v1.14.8

func (c *Container) ConmonCgroupfsPath() string

ConmonCgroupfsPath returns the path to conmon's cgroup. This is only set when cgroupfs is used as a cgroup manager.

func (*Container) Created added in v1.11.5

func (c *Container) Created() bool

Created returns whether the container was created successfully

func (*Container) CreatedAt added in v1.0.0

func (c *Container) CreatedAt() time.Time

CreatedAt returns the container creation time

func (*Container) CrioAnnotations added in v1.0.0

func (c *Container) CrioAnnotations() map[string]string

CrioAnnotations returns the crio annotations of the container.

func (*Container) Description added in v1.12.5

func (c *Container) Description() string

Description returns a description for the container

func (*Container) Dir added in v1.0.0

func (c *Container) Dir() string

Dir returns the dir of the container

func (*Container) FromDisk added in v1.0.0

func (c *Container) FromDisk() error

FromDisk restores container's state from disk

func (*Container) GetStopSignal added in v1.0.0

func (c *Container) GetStopSignal() string

GetStopSignal returns the container's own stop signal configured from the image configuration or the default one.

func (*Container) ID

func (c *Container) ID() string

ID returns the id of the container.

func (*Container) IDMappings added in v1.11.0

func (c *Container) IDMappings() *idtools.IDMappings

IDMappings returns the ID/GID mappings used for the container

func (*Container) Image

func (c *Container) Image() string

Image returns the image of the container.

func (*Container) ImageName added in v1.0.0

func (c *Container) ImageName() string

ImageName returns the image name of the container.

func (*Container) ImageRef added in v1.0.0

func (c *Container) ImageRef() string

ImageRef returns the image ref of the container.

func (*Container) IntermediateMountPoint added in v1.11.0

func (c *Container) IntermediateMountPoint() string

IntermediateMountPoint returns the container mount point

func (*Container) Labels

func (c *Container) Labels() map[string]string

Labels returns the labels of the container.

func (*Container) LogPath

func (c *Container) LogPath() string

LogPath returns the log path of the container.

func (*Container) Metadata

func (c *Container) Metadata() *pb.ContainerMetadata

Metadata returns the metadata of the container.

func (*Container) MountPoint added in v1.0.0

func (c *Container) MountPoint() string

MountPoint returns the container mount point

func (*Container) Name

func (c *Container) Name() string

Name returns the name of the container.

func (*Container) NetNsPath

func (c *Container) NetNsPath() (string, error)

NetNsPath returns the path to the network namespace of the container.

func (*Container) Sandbox

func (c *Container) Sandbox() string

Sandbox returns the sandbox name of the container.

func (*Container) SeccompProfilePath added in v1.8.0

func (c *Container) SeccompProfilePath() string

SeccompProfilePath returns the seccomp profile path

func (*Container) SetCreated added in v1.11.5

func (c *Container) SetCreated()

SetCreated sets the created flag to true once container is created

func (*Container) SetIDMappings added in v1.11.0

func (c *Container) SetIDMappings(mappings *idtools.IDMappings)

SetIDMappings sets the ID/GID mappings used for the container

func (*Container) SetIntermediateMountPoint added in v1.11.0

func (c *Container) SetIntermediateMountPoint(imp string)

SetIntermediateMountPoint sets the container intermediate mount point

func (*Container) SetMountPoint added in v1.0.0

func (c *Container) SetMountPoint(mp string)

SetMountPoint sets the container mount point

func (*Container) SetSeccompProfilePath added in v1.8.0

func (c *Container) SetSeccompProfilePath(pp string)

SetSeccompProfilePath sets the seccomp profile path

func (*Container) SetSpec added in v1.0.3

func (c *Container) SetSpec(s *specs.Spec)

SetSpec loads the OCI spec in the container struct

func (*Container) SetStartFailed added in v1.14.0

func (c *Container) SetStartFailed(err error)

SetStartFailed sets the container state appropriately after a start failure

func (*Container) SetState added in v1.0.0

func (c *Container) SetState(state *ContainerState)

SetState sets the container state

XXX: DO NOT EVER USE THIS, THIS IS JUST USEFUL FOR MOCKING!!!

func (*Container) Spec added in v1.0.3

func (c *Container) Spec() specs.Spec

Spec returns a copy of the spec for the container

func (*Container) State added in v1.0.0

func (c *Container) State() *ContainerState

State returns the state of the running container

func (*Container) StateNoLock added in v1.14.0

func (c *Container) StateNoLock() *ContainerState

StateNoLock returns the state of a container without using a lock.

func (*Container) StatePath added in v1.0.0

func (c *Container) StatePath() string

StatePath returns the containers state.json path

func (*Container) StdinOnce added in v1.12.9

func (c *Container) StdinOnce() bool

StdinOnce returns whether stdin once is set for the container.

func (*Container) StopSignal added in v1.14.0

func (c *Container) StopSignal() syscall.Signal

StopSignal returns the container's own stop signal configured from the image configuration or the default one.

func (*Container) Volumes added in v1.0.0

func (c *Container) Volumes() []ContainerVolume

Volumes returns the list of container volumes.

type ContainerState

type ContainerState struct {
	specs.State
	Created   time.Time `json:"created"`
	Started   time.Time `json:"started,omitempty"`
	Finished  time.Time `json:"finished,omitempty"`
	ExitCode  int32     `json:"exitCode,omitempty"`
	OOMKilled bool      `json:"oomKilled,omitempty"`
	Error     string    `json:"error,omitempty"`
}

ContainerState represents the status of a container.

type ContainerStats added in v1.14.0

type ContainerStats struct {
	Container   string
	CPU         float64
	CPUNano     uint64
	SystemNano  int64
	MemUsage    uint64
	MemLimit    uint64
	MemPerc     float64
	NetInput    uint64
	NetOutput   uint64
	BlockInput  uint64
	BlockOutput uint64
	PIDs        uint64
}

ContainerStats contains the statistics information for a running container

type ContainerStorer added in v1.0.0

type ContainerStorer interface {
	// Add appends a new container to the store.
	Add(string, *Container)
	// Get returns a container from the store by the identifier it was stored with.
	Get(string) *Container
	// Delete removes a container from the store by the identifier it was stored with.
	Delete(string)
	// List returns a list of containers from the store.
	List() []*Container
	// Size returns the number of containers in the store.
	Size() int
	// First returns the first container found in the store by a given filter.
	First(StoreFilter) *Container
	// ApplyAll calls the reducer function with every container in the store.
	ApplyAll(StoreReducer)
}

ContainerStorer defines an interface that any container store must implement.

func NewMemoryStore

func NewMemoryStore() ContainerStorer

NewMemoryStore initializes a new memory store.

type ContainerVolume added in v1.0.0

type ContainerVolume struct {
	ContainerPath string `json:"container_path"`
	HostPath      string `json:"host_path"`
	Readonly      bool   `json:"readonly"`
}

ContainerVolume is a bind mount for the container.

type ExecSyncError

type ExecSyncError struct {
	Stdout   bytes.Buffer
	Stderr   bytes.Buffer
	ExitCode int32
	Err      error
}

ExecSyncError wraps command's streams, exit code and error on ExecSync error.

func (ExecSyncError) Error

func (e ExecSyncError) Error() string

type ExecSyncResponse

type ExecSyncResponse struct {
	Stdout   []byte
	Stderr   []byte
	ExitCode int32
}

ExecSyncResponse is returned from ExecSync.

type History

type History []*Container

History is a convenience type for storing a list of containers, sorted by creation date in descendant order.

func (*History) Len

func (history *History) Len() int

Len returns the number of containers in the history.

func (*History) Less

func (history *History) Less(i, j int) bool

Less compares two containers and returns true if the second one was created before the first one.

func (*History) Swap

func (history *History) Swap(i, j int)

Swap switches containers i and j positions in the history.

type Runtime

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

Runtime is the generic structure holding both global and specific information about the runtime.

func New

func New(defaultRuntime string,
	runtimes map[string]RuntimeHandler,
	conmonPath string,
	conmonEnv []string,
	cgroupManager string,
	containerExitsDir string,
	containerAttachSocketDir string,
	logSizeMax int64,
	logToJournald bool,
	noPivot bool,
	ctrStopTimeout int64) (*Runtime, error)

New creates a new Runtime with options provided

func (*Runtime) AttachContainer added in v1.14.0

func (r *Runtime) AttachContainer(c *Container, inputStream io.Reader, outputStream, errorStream io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error

AttachContainer attaches IO to a running container.

func (*Runtime) ContainerStats added in v1.14.0

func (r *Runtime) ContainerStats(c *Container) (*ContainerStats, error)

ContainerStats provides statistics of a container.

func (*Runtime) CreateContainer

func (r *Runtime) CreateContainer(c *Container, cgroupParent string) error

CreateContainer creates a container.

func (*Runtime) DeleteContainer

func (r *Runtime) DeleteContainer(c *Container) error

DeleteContainer deletes a container.

func (*Runtime) ExecContainer added in v1.14.0

func (r *Runtime) ExecContainer(c *Container, cmd []string, stdin io.Reader, stdout, stderr io.WriteCloser, tty bool, resize <-chan remotecommand.TerminalSize) error

ExecContainer prepares a streaming endpoint to execute a command in the container.

func (*Runtime) ExecSyncContainer added in v1.14.0

func (r *Runtime) ExecSyncContainer(c *Container, command []string, timeout int64) (*ExecSyncResponse, error)

ExecSyncContainer execs a command in a container and returns it's stdout, stderr and return code.

func (*Runtime) PauseContainer added in v1.0.0

func (r *Runtime) PauseContainer(c *Container) error

PauseContainer pauses a container.

func (*Runtime) PortForwardContainer added in v1.14.0

func (r *Runtime) PortForwardContainer(c *Container, port int32, stream io.ReadWriter) error

PortForwardContainer forwards the specified port provides statistics of a container.

func (*Runtime) ReopenContainerLog added in v1.14.0

func (r *Runtime) ReopenContainerLog(c *Container) error

ReopenContainerLog reopens the log file of a container.

func (*Runtime) RuntimeImpl added in v1.14.0

func (r *Runtime) RuntimeImpl(c *Container) (RuntimeImpl, error)

RuntimeImpl returns the runtime implementation for a given container

func (*Runtime) Runtimes added in v1.12.0

func (r *Runtime) Runtimes() map[string]RuntimeHandler

Runtimes returns the map of OCI runtimes.

func (*Runtime) SignalContainer added in v1.14.0

func (r *Runtime) SignalContainer(c *Container, sig syscall.Signal) error

SignalContainer sends a signal to a container process.

func (*Runtime) StartContainer

func (r *Runtime) StartContainer(c *Container) error

StartContainer starts a container.

func (*Runtime) StopContainer

func (r *Runtime) StopContainer(ctx context.Context, c *Container, timeout int64) error

StopContainer stops a container. Timeout is given in seconds.

func (*Runtime) UnpauseContainer added in v1.0.0

func (r *Runtime) UnpauseContainer(c *Container) error

UnpauseContainer unpauses a container.

func (*Runtime) UpdateContainer added in v1.8.0

func (r *Runtime) UpdateContainer(c *Container, res *rspec.LinuxResources) error

UpdateContainer updates container resources

func (*Runtime) UpdateContainerStatus added in v1.14.0

func (r *Runtime) UpdateContainerStatus(c *Container) error

UpdateContainerStatus refreshes the status of the container.

func (*Runtime) ValidateRuntimeHandler added in v1.12.0

func (r *Runtime) ValidateRuntimeHandler(handler string) (RuntimeHandler, error)

ValidateRuntimeHandler returns an error if the runtime handler string provided does not match any valid use case.

func (*Runtime) WaitContainerStateStopped added in v1.10.0

func (r *Runtime) WaitContainerStateStopped(ctx context.Context, c *Container) (err error)

WaitContainerStateStopped runs a loop polling UpdateStatus(), seeking for the container status to be updated to 'stopped'. Either it gets the expected status and returns nil, or it reaches the timeout and returns an error.

type RuntimeHandler added in v1.12.0

type RuntimeHandler struct {
	RuntimePath string `toml:"runtime_path"`
	RuntimeType string `toml:"runtime_type"`
}

RuntimeHandler represents each item of the "crio.runtime.runtimes" TOML config table.

type RuntimeImpl added in v1.14.0

type RuntimeImpl interface {
	CreateContainer(*Container, string) error
	StartContainer(*Container) error
	ExecContainer(*Container, []string, io.Reader, io.WriteCloser, io.WriteCloser,
		bool, <-chan remotecommand.TerminalSize) error
	ExecSyncContainer(*Container, []string, int64) (*ExecSyncResponse, error)
	UpdateContainer(*Container, *rspec.LinuxResources) error
	StopContainer(context.Context, *Container, int64) error
	DeleteContainer(*Container) error
	UpdateContainerStatus(*Container) error
	PauseContainer(*Container) error
	UnpauseContainer(*Container) error
	ContainerStats(*Container) (*ContainerStats, error)
	SignalContainer(*Container, syscall.Signal) error
	AttachContainer(*Container, io.Reader, io.WriteCloser, io.WriteCloser,
		bool, <-chan remotecommand.TerminalSize) error
	PortForwardContainer(*Container, int32, io.ReadWriter) error
	ReopenContainerLog(*Container) error
	WaitContainerStateStopped(context.Context, *Container) error
}

RuntimeImpl is an interface used by the caller to interact with the container runtime. The purpose of this interface being to abstract implementations and their associated assumptions regarding the way to interact with containers. This will allow for new implementations of this interface, especially useful for the case of VM based container runtimes. Assumptions based on the fact that a container process runs on the host will be limited to the RuntimeOCI implementation.

type StoreFilter

type StoreFilter func(*Container) bool

StoreFilter defines a function to filter container in the store.

type StoreReducer

type StoreReducer func(*Container)

StoreReducer defines a function to manipulate containers in the store

Jump to

Keyboard shortcuts

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