Documentation ¶
Index ¶
- Constants
- Variables
- func NewDefaultSpec(ctx context.Context, id string) (*specs.Spec, error)
- func SetImageProxy(p string)
- type APIClient
- type Client
- func (c *Client) Cleanup() error
- func (c *Client) Close() 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) Events(ctx context.Context, ef ...string) (eventsapi.Events_SubscribeClient, error)
- func (c *Client) ExecContainer(ctx context.Context, process *Process) 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, importer ctrdmetaimages.Importer, reader io.Reader) ([]containerd.Image, 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) ProbeContainer(ctx context.Context, id string, timeout time.Duration) *Message
- func (c *Client) PullImage(ctx context.Context, ref string, authConfig *types.AuthConfig, ...) (containerd.Image, 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) 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) 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, fn func(context.Context, snapshots.Info) error) error
- type ClientOpt
- func WithContainerdBinary(containerdBinary string) ClientOpt
- func WithDebugLog(debugLog bool) ClientOpt
- func WithDefaultNamespace(ns string) ClientOpt
- func WithGrpcClientPoolCapacity(grpcClientPoolCapacity int) ClientOpt
- func WithHomeDir(homeDir string) ClientOpt
- func WithMaxStreamsClient(maxStreamsClient int) ClientOpt
- func WithOOMScoreAdjust(oomScore int) ClientOpt
- func WithRPCAddr(rpcAddr string) ClientOpt
- func WithStartDaemon(startDaemon bool) ClientOpt
- type Container
- type ContainerAPIClient
- type ImageAPIClient
- type Message
- type Process
- type SnapshotAPIClient
- type WrapperClient
Constants ¶
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 )
Variables ¶
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 NewDefaultSpec ¶
NewDefaultSpec new a template spec with default.
Types ¶
type APIClient ¶
type APIClient interface { ContainerAPIClient ImageAPIClient SnapshotAPIClient Version(ctx context.Context) (containerd.Version, error) Cleanup() 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) 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) Events ¶
func (c *Client) Events(ctx context.Context, ef ...string) (eventsapi.Events_SubscribeClient, error)
Events subscribe containerd events through an event subscribe client.
func (*Client) ExecContainer ¶
ExecContainer executes a process in container.
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, importer ctrdmetaimages.Importer, reader io.Reader) ([]containerd.Image, error)
ImportImage creates a set of images by tarstream.
NOTE: One tar may have several manifests.
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) PullImage ¶
func (c *Client) PullImage(ctx context.Context, ref string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, error)
PullImage downloads an image from the remote repository.
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) 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.
type ClientOpt ¶
type ClientOpt func(c *clientOpts) error
ClientOpt allows caller to set options for containerd client.
func WithContainerdBinary ¶
WithContainerdBinary specifies the containerd binary path.
func WithDebugLog ¶
WithDebugLog set debugLog flag for containerd client. debugLog decides containerd log level.
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 WithHomeDir ¶
WithHomeDir set home dir for containerd.
func WithMaxStreamsClient ¶
WithMaxStreamsClient sets one containerd grpc client can hold max streams client.
func WithOOMScoreAdjust ¶
WithOOMScoreAdjust sets oom-score for containerd instance.
func WithRPCAddr ¶
WithRPCAddr set containerd listen address.
func WithStartDaemon ¶
WithStartDaemon set startDaemon flag for containerd client. startDaemon is a flag to decide whether start a new containerd instance when create a containerd client.
type Container ¶
type Container struct { ID string Image string Runtime string Labels map[string]string IO *containerio.IO Spec *specs.Spec // BaseFS is rootfs used by containerd container BaseFS string // RootFSProvided is a flag to point the container is created by specifying rootfs RootFSProvided 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 // 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) 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) error) // SetExecExitHooks specified the handlers of exec process exit. SetExecExitHooks(hooks ...func(string, *Message) error) // Events subscribe containerd events through an event subscribe client. Events(ctx context.Context, ef ...string) (eventsapi.Events_SubscribeClient, 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) // PullImage pulls image by the given reference. PullImage(ctx context.Context, ref string, authConfig *types.AuthConfig, stream *jsonstream.JSONStream) (containerd.Image, 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, importer ctrdmetaimages.Importer, reader io.Reader) ([]containerd.Image, error) // SaveImage saves image to tarstream SaveImage(ctx context.Context, exporter ctrdmetaimages.Exporter, ref string) (io.ReadCloser, 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 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. For each snapshot, the function will be called. WalkSnapshot(ctx context.Context, 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 ???