containerd

package
v0.0.0-...-445c0ad Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 44 Imported by: 0

README

Notes on developing with containerd

Snapshotters

Performance of containerd filesystem operations depends a great deal on the choice of a snapshotter. Currently we're using the default overlayfs one, but the choice is vast and constantly evolving. There are a few benchmarks available here and here but the recommendations are constantly changing based on improvements in the underlying filesystem implementations. Case in point here is ZFS: it used to be great for snapshotters back in 2014, then it got really bad and then it got fixed again around 2020.

At the time of this writeup it is unclear whether we can leverage Docker's overlayfs2 implementation and whether it would give us any real benefits over default overlayfs.

Tools

containerd structures most of its state in pretty simple formats. The only exception to that rule is how it keeps its metadata around. That state is stored in an embedded bolt DB and using boltbrowser on meta.db is highly recommended when debugging containerd issues.

Documentation

Index

Constants

View Source
const (

	// EVEOCIVNCPasswordLabel is OCI runtime spec label that tracks VNC password in OCI Image config
	EVEOCIVNCPasswordLabel = "org.lfedge.eve.vnc_password"
)

Variables

This section is empty.

Functions

func GetServicesNamespace

func GetServicesNamespace() string

GetServicesNamespace returns defaultServicesNamespace The value is used to define the cgroups path of the EVE services

func GetSnapshotID

func GetSnapshotID(rootpath string) string

GetSnapshotID handles the upgrade scenario when the snapshotID needs to be extracted from a file created by upgradeconverter Assumes that rootpath is a complete pathname

func SaveSnapshotID

func SaveSnapshotID(oldRootpath, newRootpath string) error

SaveSnapshotID stores snapshotID under newRootpath to handle upgrade scenario

func StartUserContainerdInstance

func StartUserContainerdInstance() error

StartUserContainerdInstance execute user containerd instance in goroutine

Types

type Client

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

Client is the handle we return to the caller

func NewContainerdClient

func NewContainerdClient(user bool) (*Client, error)

NewContainerdClient returns a *Client Callable from multiple go-routines.

func (*Client) CloseClient

func (client *Client) CloseClient() error

CloseClient closes containerd client

func (*Client) CtrContainerInfo

func (client *Client) CtrContainerInfo(ctx context.Context, name string) (int, int, string, error)

CtrContainerInfo returns PID, exit code and status of a container's main task Status can be one of the: created, running, pausing, paused, stopped, unknown For tasks that are in the running, pausing or paused state the PID is also provided and the exit code is set to 0. For tasks in the stopped state, exit code is provided and the PID is set to 0.

func (*Client) CtrCreateImage

func (client *Client) CtrCreateImage(ctx context.Context, image images.Image) (images.Image, error)

CtrCreateImage create an image in containerd's image store

func (*Client) CtrCreateTask

func (client *Client) CtrCreateTask(ctx context.Context, domainName string) (int, error)

CtrCreateTask creates (but doesn't start) the default task in a pre-existing container and attaches its logging to memlogd

func (*Client) CtrDeleteBlob

func (client *Client) CtrDeleteBlob(ctx context.Context, blobHash string) error

CtrDeleteBlob deletes blob with the given blobHash

func (*Client) CtrDeleteContainer

func (client *Client) CtrDeleteContainer(ctx context.Context, containerID string) error

CtrDeleteContainer is a simple wrapper around container.Delete()

func (*Client) CtrDeleteImage

func (client *Client) CtrDeleteImage(ctx context.Context, reference string) error

CtrDeleteImage deletes an image with the given reference

func (*Client) CtrExec

func (client *Client) CtrExec(ctx context.Context, domainName string, args []string) (string, string, error)

CtrExec starts the executable in a running user container

func (*Client) CtrGetAnnotations

func (client *Client) CtrGetAnnotations(ctx context.Context, containerID string) (map[string]string, error)

CtrGetAnnotations gets annotations for defined containerID

func (*Client) CtrGetBlobInfo

func (client *Client) CtrGetBlobInfo(ctx context.Context, blobHash string) (content.Info, error)

CtrGetBlobInfo returns a bolb's info as content.Info

func (*Client) CtrGetContainerMetrics

func (client *Client) CtrGetContainerMetrics(ctx context.Context, containerID string) (*v1stat.Metrics, error)

CtrGetContainerMetrics returns all runtime metrics associated with a container ID

func (*Client) CtrGetImage

func (client *Client) CtrGetImage(ctx context.Context, reference string) (containerd.Image, error)

CtrGetImage returns image object for the reference. Returns error if no image is found for the reference.

func (*Client) CtrGetSnapshotUsage

func (client *Client) CtrGetSnapshotUsage(ctx context.Context, snapshotID string) (*snapshots.Usage, error)

CtrGetSnapshotUsage returns snapshot's usage for snapshotID present in containerd's snapshot store

func (*Client) CtrListBlobInfo

func (client *Client) CtrListBlobInfo(ctx context.Context) ([]content.Info, error)

CtrListBlobInfo returns a list of blob infos as []content.Info

func (*Client) CtrListContainer

func (client *Client) CtrListContainer(ctx context.Context) ([]containerd.Container, error)

CtrListContainer returns a list of containerd.Container objects

func (*Client) CtrListContainerIds

func (client *Client) CtrListContainerIds(ctx context.Context) ([]string, error)

CtrListContainerIds returns a list of all known container IDs

func (*Client) CtrListImages

func (client *Client) CtrListImages(ctx context.Context) ([]images.Image, error)

CtrListImages returns a list of images object from ontainerd's image store

func (*Client) CtrListSnapshotInfo

func (client *Client) CtrListSnapshotInfo(ctx context.Context) ([]snapshots.Info, error)

CtrListSnapshotInfo returns a list of all snapshot's info present in containerd's snapshot store.

func (*Client) CtrListTaskIds

func (client *Client) CtrListTaskIds(ctx context.Context) ([]string, error)

CtrListTaskIds returns a list of all known tasks

func (*Client) CtrLoadContainer

func (client *Client) CtrLoadContainer(ctx context.Context, containerID string) (containerd.Container, error)

CtrLoadContainer returns container with the given `containerID`. Error is returned if there no container is found.

func (*Client) CtrLoadImage

func (client *Client) CtrLoadImage(ctx context.Context, reader *os.File) ([]images.Image, error)

CtrLoadImage reads image as raw data from `reader` and loads it into containerd

func (*Client) CtrMountSnapshot

func (client *Client) CtrMountSnapshot(ctx context.Context, snapshotID, targetPath string) error

CtrMountSnapshot mounts the snapshot with snapshotID on the given targetPath.

func (*Client) CtrNewSystemServicesCtx

func (client *Client) CtrNewSystemServicesCtx() (context.Context, context.CancelFunc)

CtrNewSystemServicesCtx returns a new system service containerd context and a done func to cancel the context after use.

func (*Client) CtrNewSystemServicesCtxWithLease

func (client *Client) CtrNewSystemServicesCtxWithLease() (context.Context, context.CancelFunc, error)

CtrNewSystemServicesCtxWithLease returns a new system service containerd context with a 24 hrs lease and a done func to delete the lease and cancel the context after use.

func (*Client) CtrNewUserServicesCtx

func (client *Client) CtrNewUserServicesCtx() (context.Context, context.CancelFunc)

CtrNewUserServicesCtx returns a new user service containerd context and a done func to cancel the context after use.

func (*Client) CtrNewUserServicesCtxWithLease

func (client *Client) CtrNewUserServicesCtxWithLease() (context.Context, context.CancelFunc, error)

CtrNewUserServicesCtxWithLease returns a new user service containerd context with a 24 hrs lease and a done func to delete the lease and cancel the context after use.

func (*Client) CtrPrepareSnapshot

func (client *Client) CtrPrepareSnapshot(ctx context.Context, snapshotID string, image containerd.Image) ([]mount.Mount, error)

CtrPrepareSnapshot creates snapshot for the given image

func (*Client) CtrReadBlob

func (client *Client) CtrReadBlob(ctx context.Context, blobHash string) (io.Reader, error)

CtrReadBlob return a reader for the blob with given blobHash. Error is returned if no blob is found for the blobHash

func (*Client) CtrRemoveSnapshot

func (client *Client) CtrRemoveSnapshot(ctx context.Context, snapshotID string) error

CtrRemoveSnapshot removed snapshot by ID from containerd

func (*Client) CtrStartTask

func (client *Client) CtrStartTask(ctx context.Context, domainName string) error

CtrStartTask starts the default task in a pre-existing container that was prepared by CtrCreateTask

func (*Client) CtrStopContainer

func (client *Client) CtrStopContainer(ctx context.Context, containerID string, force bool) error

CtrStopContainer stops (kills) the main task in the container

func (*Client) CtrSystemExec

func (client *Client) CtrSystemExec(ctx context.Context, domainName string, args []string) (string, string, error)

CtrSystemExec starts the executable in a running system (EVE's) container

func (*Client) CtrUpdateBlobInfo

func (client *Client) CtrUpdateBlobInfo(ctx context.Context, updatedContentInfo content.Info, updatedFields []string) error

CtrUpdateBlobInfo updates blobs info

func (*Client) CtrUpdateImage

func (client *Client) CtrUpdateImage(ctx context.Context, image images.Image, fieldpaths ...string) (images.Image, error)

CtrUpdateImage updates the files provided in fieldpaths of the image in containerd'd image store

func (*Client) CtrWriteBlob

func (client *Client) CtrWriteBlob(ctx context.Context, blobHash string, expectedSize uint64, reader io.Reader) error

CtrWriteBlob reads the blob as raw data from `reader` and writes it into containerd. Accepts a custom context. If ctx is nil, then default context will be used.

func (*Client) NewOciSpec

func (client *Client) NewOciSpec(name string, service bool) (OCISpec, error)

NewOciSpec returns a default oci spec from the containerd point of view

func (*Client) Resolver

func (client *Client) Resolver(ctx context.Context) (resolver.ResolverCloser, error)

Resolver return a resolver.ResolverCloser that can read from containerd

func (*Client) UnpackClientImage

func (client *Client) UnpackClientImage(clientImage containerd.Image) error

UnpackClientImage unpacks given client image into containerd.

type Log

type Log interface {
	Path(string) string                  // Path of the log file (may be a FIFO)
	Open(string) (io.WriteCloser, error) // Opens a log stream
	Dump(string)                         // Copies logs to the console
}

Log provides access to a log by path or io.WriteCloser

func GetLog

func GetLog() Log

GetLog returns the log destination we should use.

type OCISpec

type OCISpec interface {
	Get() *specs.Spec
	Save(*os.File) error
	Load(*os.File) error
	CreateContainer(bool) error
	AddLoader(string) error
	AdjustMemLimit(types.DomainConfig, int64)
	UpdateVifList([]types.VifConfig)
	UpdateFromDomain(dom *types.DomainConfig, status *types.DomainStatus)
	UpdateFromVolume(string) error
	UpdateMounts([]types.DiskStatus) error
	UpdateEnvVar(map[string]string)
}

OCISpec provides methods to manipulate OCI runtime specifications and create containers based on them

Jump to

Keyboard shortcuts

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