Documentation ¶
Index ¶
- Constants
- Variables
- func CleanSnapshotter(ctx context.Context) context.Context
- func CurrentSnapshotterName(ctx context.Context) string
- func GetSnapshotter(ctx context.Context) string
- func GetThrottleDevice(devs []*types.ThrottleDevice) ([]specs.LinuxThrottleDevice, error)
- func GetWeightDevice(devs []*types.WeightDevice) ([]specs.LinuxWeightDevice, error)
- func SetImageProxy(p string)
- func SetSnapshotterName(name string)
- func WithImageUnpack(ctx context.Context) context.Context
- func WithSnapshotter(ctx context.Context, snapshotter string) context.Context
- type APIClient
- type Client
- func (c *Client) CheckSnapshotterValid(snapshotter string, allowMultiSnapshotter bool) error
- func (c *Client) Cleanup() error
- func (c *Client) Close() error
- func (c *Client) Commit(ctx context.Context, config *CommitConfig) (_ digest.Digest, err0 error)
- func (c *Client) ContainerPID(ctx context.Context, id string) (int, error)
- func (c *Client) ContainerPIDs(ctx context.Context, id string) ([]int, error)
- func (c *Client) ContainerStats(ctx context.Context, id string) (*containerdtypes.Metric, error)
- func (c *Client) CreateCheckpoint(ctx context.Context, id string, checkpointDir string, exit bool) error
- func (c *Client) CreateContainer(ctx context.Context, container *Container, checkpointDir string) error
- func (c *Client) CreateImageReference(ctx context.Context, img ctrdmetaimages.Image) (ctrdmetaimages.Image, error)
- func (c *Client) CreateSnapshot(ctx context.Context, id, ref string) error
- func (c *Client) DestroyContainer(ctx context.Context, id string, timeout int64) (*Message, error)
- func (c *Client) ExecContainer(ctx context.Context, process *Process, timeout int) error
- func (c *Client) FetchImage(ctx context.Context, resolver remotes.Resolver, availableRef string, ...) (containerd.Image, error)
- func (c *Client) Get(ctx context.Context) (*WrapperClient, error)
- func (c *Client) GetImage(ctx context.Context, ref string) (containerd.Image, error)
- func (c *Client) GetMounts(ctx context.Context, id string) ([]mount.Mount, error)
- func (c *Client) GetSnapshot(ctx context.Context, id string) (snapshots.Info, error)
- func (c *Client) GetSnapshotUsage(ctx context.Context, id string) (snapshots.Usage, error)
- func (c *Client) ImportImage(ctx context.Context, reader io.Reader, opts ...containerd.ImportOpt) ([]containerd.Image, error)
- func (c *Client) KillContainer(ctx context.Context, id string, signal int) error
- func (c *Client) ListImages(ctx context.Context, filter ...string) ([]containerd.Image, error)
- func (c *Client) PauseContainer(ctx context.Context, id string) error
- func (c *Client) Plugins(ctx context.Context, filters []string) ([]Plugin, error)
- func (c *Client) ProbeContainer(ctx context.Context, id string, timeout time.Duration) *Message
- func (c *Client) PushImage(ctx context.Context, ref string, authConfig *types.AuthConfig, out io.Writer) error
- func (c *Client) RecoverContainer(ctx context.Context, id string, io *containerio.IO) error
- func (c *Client) RemoveImage(ctx context.Context, ref string) error
- func (c *Client) RemoveSnapshot(ctx context.Context, id string) error
- func (c *Client) ResizeContainer(ctx context.Context, id string, opts types.ResizeOptions) error
- func (c *Client) ResizeExec(ctx context.Context, id string, execid string, opts types.ResizeOptions) error
- func (c *Client) ResolveImage(ctx context.Context, nameRef string, refs []string, ...) (remotes.Resolver, string, error)
- func (c *Client) SaveImage(ctx context.Context, exporter ctrdmetaimages.Exporter, ref string) (io.ReadCloser, error)
- func (c *Client) SetEventsHooks(hooks ...func(context.Context, string, string, map[string]string) error)
- func (c *Client) SetExecExitHooks(hooks ...func(string, *Message) error)
- func (c *Client) SetExitHooks(hooks ...func(string, *Message, func() error) error)
- func (c *Client) UnpauseContainer(ctx context.Context, id string) error
- func (c *Client) UpdateResources(ctx context.Context, id string, resources types.Resources) error
- func (c *Client) Version(ctx context.Context) (containerd.Version, error)
- func (c *Client) WaitContainer(ctx context.Context, id string) (types.ContainerWaitOKBody, error)
- func (c *Client) WalkSnapshot(ctx context.Context, snapshotter string, ...) error
- type ClientOpt
- type CommitConfig
- type Container
- type ContainerAPIClient
- type ImageAPIClient
- type InitStdio
- type Message
- type Plugin
- type Process
- type SnapshotAPIClient
- type WrapperClient
Constants ¶
const ( // PluginStatusOk means plugin status is ok PluginStatusOk = "ok" // PluginStatusError means plugin status is error PluginStatusError = "error" )
const ( // ContainersCreateEventTopic for container create ContainersCreateEventTopic = "/containers/create" // ContainersDeleteEventTopic for container delete ContainersDeleteEventTopic = "/containers/delete" // TaskCreateEventTopic for task create TaskCreateEventTopic = runtime.TaskCreateEventTopic // TaskDeleteEventTopic for task delete TaskDeleteEventTopic = runtime.TaskDeleteEventTopic // TaskExitEventTopic for task exit TaskExitEventTopic = runtime.TaskExitEventTopic // TaskOOMEventTopic for task oom TaskOOMEventTopic = runtime.TaskOOMEventTopic )
const ( // TypeLabelKey is the key of label type=image in Snapshotter metadata Info.Labels, with which indicates the snapshot for image. TypeLabelKey = "type" // ImageType is the label value ImageType = "image" // SnapshotLabelContextKey is the key which is stored in context to transfer to containerd snapshotter SnapshotLabelContextKey = "containerd.io.snapshot.labels" )
Variables ¶
var ( // RuntimeRoot is the base directory path for each runtime. RuntimeRoot = "/run" // RuntimeTypeV1 is the runtime type name for containerd shim interface v1 version. RuntimeTypeV1 = fmt.Sprintf("io.containerd.runtime.v1.%s", runtime.GOOS) // RuntimeTypeV2runscV1 is the runtime type name for gVisor containerd shim implement the shim v2 api. RuntimeTypeV2runscV1 = "io.containerd.runsc.v1" // RuntimeTypeV2kataV2 is the runtime type name for kata-runtime containerd shim implement the shim v2 api. RuntimeTypeV2kataV2 = "io.containerd.kata.v2" // RuntimeTypeV2runcV1 is the runtime type name for runc containerd shim implement the shim v2 api. RuntimeTypeV2runcV1 = "io.containerd.runc.v1" )
var ErrGetCtrdClient = errors.New("failed to get a containerd grpc client")
ErrGetCtrdClient is an error returned when failed to get a containerd grpc client from clients pool.
Functions ¶
func CleanSnapshotter ¶
CleanSnapshotter cleans snapshotter key for context
func CurrentSnapshotterName ¶
CurrentSnapshotterName returns current snapshotter driver
func GetSnapshotter ¶
GetSnapshotter get snapshotter from context
func GetThrottleDevice ¶
func GetThrottleDevice(devs []*types.ThrottleDevice) ([]specs.LinuxThrottleDevice, error)
GetThrottleDevice Convert throttle device from []*types.ThrottleDevice to []specs.LinuxThrottleDevice
func GetWeightDevice ¶
func GetWeightDevice(devs []*types.WeightDevice) ([]specs.LinuxWeightDevice, error)
GetWeightDevice Convert weight device from []*types.WeightDevice to []specs.LinuxWeightDevice
func SetSnapshotterName ¶
func SetSnapshotterName(name string)
SetSnapshotterName sets current snapshotter driver, it should be called only when daemon starts
func WithImageUnpack ¶
WithImageUnpack adds SnapshotLabelContextKey in context before creation of image snapshot. it should be called when image snapshot is on creation, such as pullImage, loadImage and commitImage.
Types ¶
type APIClient ¶
type APIClient interface { ContainerAPIClient ImageAPIClient SnapshotAPIClient Version(ctx context.Context) (containerd.Version, error) Cleanup() error Plugins(ctx context.Context, filters []string) ([]Plugin, error) CheckSnapshotterValid(snapshotter string, allowMultiSnapshotter bool) error }
APIClient defines common methods of containerd api client
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the client side the daemon holds to communicate with containerd.
func (*Client) CheckSnapshotterValid ¶
CheckSnapshotterValid checks whether the given snapshotter is valid
func (*Client) ContainerPID ¶
ContainerPID returns the container's init process id.
func (*Client) ContainerPIDs ¶
ContainerPIDs returns the all processes's ids inside the container.
func (*Client) ContainerStats ¶
ContainerStats returns stats of the container.
func (*Client) CreateCheckpoint ¶
func (c *Client) CreateCheckpoint(ctx context.Context, id string, checkpointDir string, exit bool) error
CreateCheckpoint create a checkpoint from a running container
func (*Client) CreateContainer ¶
func (c *Client) CreateContainer(ctx context.Context, container *Container, checkpointDir string) error
CreateContainer create container and start process.
func (*Client) CreateImageReference ¶
func (c *Client) CreateImageReference(ctx context.Context, img ctrdmetaimages.Image) (ctrdmetaimages.Image, error)
CreateImageReference creates the image in the meta data in the containerd.
func (*Client) CreateSnapshot ¶
CreateSnapshot creates a active snapshot with image's name and id.
func (*Client) DestroyContainer ¶
DestroyContainer kill container and delete it.
func (*Client) ExecContainer ¶
ExecContainer executes a process in container.
func (*Client) FetchImage ¶
func (c *Client) FetchImage(ctx context.Context, resolver remotes.Resolver, availableRef string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, error)
FetchImage fetches image content from the remote repository.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context) (*WrapperClient, error)
Get will reture an available containerd grpc client, Or occurred an error
func (*Client) GetMounts ¶
GetMounts returns the mounts for the active snapshot transaction identified by key.
func (*Client) GetSnapshot ¶
GetSnapshot returns the snapshot's info by id.
func (*Client) GetSnapshotUsage ¶
GetSnapshotUsage returns the resource usage of an active or committed snapshot excluding the usage of parent snapshots.
func (*Client) ImportImage ¶
func (c *Client) ImportImage(ctx context.Context, reader io.Reader, opts ...containerd.ImportOpt) ([]containerd.Image, error)
ImportImage creates a set of images by tarstream.
NOTE: One tar may have several manifests.
func (*Client) KillContainer ¶
KillContainer kills a container's all processes by signal.
func (*Client) ListImages ¶
ListImages lists all images.
func (*Client) PauseContainer ¶
PauseContainer pauses container.
func (*Client) ProbeContainer ¶
ProbeContainer probe the container's status, if timeout <= 0, will block to receive message.
func (*Client) PushImage ¶
func (c *Client) PushImage(ctx context.Context, ref string, authConfig *types.AuthConfig, out io.Writer) error
PushImage pushes image to registry
func (*Client) RecoverContainer ¶
RecoverContainer reload the container from metadata and watch it, if program be restarted.
func (*Client) RemoveImage ¶
RemoveImage deletes an image.
func (*Client) RemoveSnapshot ¶
RemoveSnapshot removes the snapshot by id.
func (*Client) ResizeContainer ¶
ResizeContainer changes the size of the TTY of the init process running in the container to the given height and width.
func (*Client) ResizeExec ¶
func (c *Client) ResizeExec(ctx context.Context, id string, execid string, opts types.ResizeOptions) error
ResizeExec changes the size of the TTY of the exec process running in the container to the given height and width.
func (*Client) ResolveImage ¶
func (c *Client) ResolveImage(ctx context.Context, nameRef string, refs []string, authConfig *types.AuthConfig, opts docker.ResolverOptions) (remotes.Resolver, string, error)
ResolveImage attempts to resolve the image reference into a available reference and resolver.
func (*Client) SaveImage ¶
func (c *Client) SaveImage(ctx context.Context, exporter ctrdmetaimages.Exporter, ref string) (io.ReadCloser, error)
SaveImage saves image to tarstream
func (*Client) SetEventsHooks ¶
func (c *Client) SetEventsHooks(hooks ...func(context.Context, string, string, map[string]string) error)
SetEventsHooks specified the methods to handle the containerd events.
func (*Client) SetExecExitHooks ¶
SetExecExitHooks specified the handlers of exec process exit.
func (*Client) SetExitHooks ¶
SetExitHooks specified the handlers of container exit.
func (*Client) UnpauseContainer ¶
UnpauseContainer unpauses container.
func (*Client) UpdateResources ¶
UpdateResources updates the configurations of a container.
func (*Client) WaitContainer ¶
WaitContainer waits until container's status is stopped.
func (*Client) WalkSnapshot ¶
func (c *Client) WalkSnapshot(ctx context.Context, snapshotter string, fn func(context.Context, snapshots.Info) error) error
WalkSnapshot walk all snapshots in specific snapshotter. If not set specific snapshotter, it will be set to current snapshotter. For each snapshot, the function will be called.
type ClientOpt ¶
type ClientOpt func(c *clientOpts) error
ClientOpt allows caller to set options for containerd client.
func WithDefaultNamespace ¶
WithDefaultNamespace sets the default namespace on the client
Any operation that does not have a namespace set on the context will be provided the default namespace
func WithGrpcClientPoolCapacity ¶
WithGrpcClientPoolCapacity sets containerd clients pool capacity.
func WithInsecureRegistries ¶
WithInsecureRegistries sets the insecure registries to allow http request and skip secure verify.
func WithMaxStreamsClient ¶
WithMaxStreamsClient sets one containerd grpc client can hold max streams client.
func WithRPCAddr ¶
WithRPCAddr set containerd listen address.
type CommitConfig ¶
type CommitConfig struct { // author Author string // comment Comment string // container config ContainerConfig *types.ContainerConfig // container ID ContainerID string // parent reference ParentReference string // reference Reference string // repository Repository string // containerd format image CImage containerd.Image // image-spec format image Image ocispec.Image }
CommitConfig defines options for committing a container image
type Container ¶
type Container struct { ID string Image string RuntimeType string RuntimeOptions interface{} Labels map[string]string IO *containerio.IO Spec *specs.Spec SnapshotID string // BaseFS is rootfs used by containerd container BaseFS string // RootFSProvided is a flag to point the container is created by specifying rootfs RootFSProvided bool // UseSystemd tells whether container use systemd cgroup driver UseSystemd bool }
Container wraps container's info. there have two kind of containers now: One is created by pouch: first using image to create snapshot, then create container by specifying the snapshot; The other is create container by specify container rootfs, we use `RootFSProvided` flag to mark it,
type ContainerAPIClient ¶
type ContainerAPIClient interface { // CreateContainer creates a containerd container and start process. CreateContainer(ctx context.Context, container *Container, checkpointDir string) error // KillContainer kills a container's all processes by signal. KillContainer(ctx context.Context, id string, signal int) error // DestroyContainer kill container and delete it. DestroyContainer(ctx context.Context, id string, timeout int64) (*Message, error) // ProbeContainer probe the container's status, if timeout <= 0, will block to receive message. ProbeContainer(ctx context.Context, id string, timeout time.Duration) *Message // ContainerPIDs returns the all processes's ids inside the container. ContainerPIDs(ctx context.Context, id string) ([]int, error) // ContainerPID returns the container's init process id. ContainerPID(ctx context.Context, id string) (int, error) // ContainerStats returns stats of the container. ContainerStats(ctx context.Context, id string) (*containerdtypes.Metric, error) // ExecContainer executes a process in container. ExecContainer(ctx context.Context, process *Process, timeout int) error // ResizeContainer changes the size of the TTY of the exec process running // in the container to the given height and width. ResizeExec(ctx context.Context, id string, execid string, opts types.ResizeOptions) error // RecoverContainer reload the container from metadata and watch it, if program be restarted. RecoverContainer(ctx context.Context, id string, io *containerio.IO) error // PauseContainer pause container. PauseContainer(ctx context.Context, id string) error // UnpauseContainer unpauses a container. UnpauseContainer(ctx context.Context, id string) error // ResizeContainer changes the size of the TTY of the init process running // in the container to the given height and width. ResizeContainer(ctx context.Context, id string, opts types.ResizeOptions) error // WaitContainer waits until container's status is stopped. WaitContainer(ctx context.Context, id string) (types.ContainerWaitOKBody, error) // UpdateResources updates the configurations of a container. UpdateResources(ctx context.Context, id string, resources types.Resources) error // SetExitHooks specified the handlers of container exit. SetExitHooks(hooks ...func(string, *Message, func() error) error) // SetExecExitHooks specified the handlers of exec process exit. SetExecExitHooks(hooks ...func(string, *Message) error) // SetEventsHooks specified the methods to handle the containerd events. SetEventsHooks(hooks ...func(context.Context, string, string, map[string]string) error) }
ContainerAPIClient provides access to containerd container features.
type ImageAPIClient ¶
type ImageAPIClient interface { // CreateImageReference creates the image data into meta data in the containerd. CreateImageReference(ctx context.Context, img ctrdmetaimages.Image) (ctrdmetaimages.Image, error) // GetImage returns containerd.Image by the given reference. GetImage(ctx context.Context, ref string) (containerd.Image, error) // ListImages returns the list of containerd.Image filtered by the given conditions. ListImages(ctx context.Context, filter ...string) ([]containerd.Image, error) // FetchImage fetches image content by the given reference. FetchImage(ctx context.Context, resolver remotes.Resolver, ref string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, error) // ResolveImage attempts to resolve the image reference into a available reference and resolver. ResolveImage(ctx context.Context, nameRef string, refs []string, authConfig *types.AuthConfig, opts docker.ResolverOptions) (remotes.Resolver, string, error) // RemoveImage removes the image by the given reference. RemoveImage(ctx context.Context, ref string) error // ImportImage creates a set of images by tarstream. ImportImage(ctx context.Context, reader io.Reader, opts ...containerd.ImportOpt) ([]containerd.Image, error) // SaveImage saves image to tarstream SaveImage(ctx context.Context, exporter ctrdmetaimages.Exporter, ref string) (io.ReadCloser, error) // Commit commits an image from a container. Commit(ctx context.Context, config *CommitConfig) (digest.Digest, error) // PushImage pushes a image to registry PushImage(ctx context.Context, ref string, authConfig *types.AuthConfig, out io.Writer) error }
ImageAPIClient provides access to containerd image features.
type Message ¶
type Message struct {
// contains filtered or unexported fields
}
Message is used to watch containerd.
type Process ¶
type Process struct { ContainerID string ExecID string IO *containerio.IO P *specs.Process Detach bool }
Process wraps exec process's info.
type SnapshotAPIClient ¶
type SnapshotAPIClient interface { // CreateSnapshot creates a active snapshot with image's name and id. CreateSnapshot(ctx context.Context, id, ref string) error // GetSnapshot returns the snapshot's info by id. GetSnapshot(ctx context.Context, id string) (snapshots.Info, error) // RemoveSnapshot removes the snapshot by id. RemoveSnapshot(ctx context.Context, id string) error // GetMounts returns the mounts for the active snapshot transaction identified // by key. GetMounts(ctx context.Context, id string) ([]mount.Mount, error) // GetSnapshotUsage returns the resource usage of an active or committed snapshot // excluding the usage of parent snapshots. GetSnapshotUsage(ctx context.Context, id string) (snapshots.Usage, error) // WalkSnapshot walk all snapshots in specific snapshotter. If not set specific snapshotter, // it will be set to current snapshotter. For each snapshot, the function will be called. WalkSnapshot(ctx context.Context, snapshotter string, fn func(context.Context, snapshots.Info) error) error // CreateCheckpoint creates a checkpoint from a running container CreateCheckpoint(ctx context.Context, id string, checkpointDir string, exit bool) error }
SnapshotAPIClient provides access to containerd snapshot features
type WrapperClient ¶
type WrapperClient struct {
// contains filtered or unexported fields
}
WrapperClient wrappers containerd grpc client, so that pouch daemon can holds a grpc client pool to improve grpc client performance.
func (*WrapperClient) Consume ¶
func (w *WrapperClient) Consume(v int) error
Consume is to acquire specified numbers of grpc stream client
func (*WrapperClient) Produce ¶
func (w *WrapperClient) Produce(v int)
Produce is to release specified numbers of grpc stream client FIXME(ziren): if streamQuota greater than defaultMaxStreamsClient what to do ???