ctrd

package
v0.0.0-...-e995b2c Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2017 License: Apache-2.0 Imports: 25 Imported by: 0

README

ctrd

ctrd is a package to interact with containerd using containerd's exposed API. Pouch will vendor package containerd in repo containerd/containerd and alibaba/containerd.

difference between containerds

First, we should said alibaba/containerd is definitely forked from upstream project containerd/containerd.

containerd/containerd definitely has the code base of the other one. Then what is the usage of alibaba/containerd. We say it is BACK PORTING.

Every time releasing Pouch to launch a new version, we vendor containerd/containerd. Since upstream containerd/containerd keeps its own way to evolve, when a serious bug is fixed in the upstream and Pouch needs this for backporting only, it is not proper to vendor the latest container/containerd which contains too many changes. As a result, we come up with a way to backport severe bugfix in alibaba/containerd. Then when backporting, we vendor alibaba/containerd, otherwise we still take advantages of upstream containerd/containerd.

To check if the package we use is containerd/containerd or alibaba/containerd, we can refer to vendor.json.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrContainerNotfound is returned when container is not found from containerd.
	ErrContainerNotfound = Error{containerNotfound, "Container not found"}
	// ErrTaskNotfound is returned when task is not found from containerd.
	ErrTaskNotfound = Error{taskNotfound, "Task not found"}
	// ErrImageNotfound is returned when image is not found from containerd.
	ErrImageNotfound = Error{imageNotfound, "Image not found"}
	// ErrTrylockFailed is returned when trylock failed.
	ErrTrylockFailed = Error{trylockFailed, "Trylock failed"}
	// ErrTimeout is returned when the connection time out.
	ErrTimeout = Error{timeoutFailed, "time out"}
)

Functions

func NewDefaultSpec

func NewDefaultSpec(ctx context.Context, id string) (*specs.Spec, error)

NewDefaultSpec new a template spec with default.

Types

type Client

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

Client is the client side the daemon holds to communicate with containerd.

func NewClient

func NewClient(cfg Config) (*Client, error)

NewClient connect to containerd.

func (*Client) Close

func (c *Client) Close() error

Close closes the client.

func (*Client) ContainerPID

func (c *Client) ContainerPID(ctx context.Context, id string) (int, error)

ContainerPID returns the container's init process id.

func (*Client) ContainerPIDs

func (c *Client) ContainerPIDs(ctx context.Context, id string) ([]int, error)

ContainerPIDs returns the all processes's ids inside the container.

func (*Client) CreateContainer

func (c *Client) CreateContainer(ctx context.Context, container *Container) error

CreateContainer create container and start process.

func (*Client) DestroyContainer

func (c *Client) DestroyContainer(ctx context.Context, id string) (*Message, error)

DestroyContainer kill container and delete it.

func (*Client) ExecContainer

func (c *Client) ExecContainer(ctx context.Context, process *Process) error

ExecContainer executes a process in container.

func (*Client) ListImages

func (c *Client) ListImages(ctx context.Context, filter ...string) ([]types.Image, error)

ListImages lists all images.

func (*Client) ProbeContainer

func (c *Client) ProbeContainer(ctx context.Context, id string, timeout time.Duration) *Message

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, stream *jsonstream.JSONStream) error

PullImage downloads an image from the remote repository.

func (*Client) RecoverContainer

func (c *Client) RecoverContainer(ctx context.Context, id string, io *containerio.IO) error

RecoverContainer reload the container from metadata and watch it, if program be restarted.

func (*Client) RemoveImage

func (c *Client) RemoveImage(ctx context.Context, ref string) error

RemoveImage removes an image.

func (*Client) SetExitHooks

func (c *Client) SetExitHooks(hooks ...func(string, *Message) error)

SetExitHooks specified the handlers of exec process exit.

func (*Client) SetStopHooks

func (c *Client) SetStopHooks(hooks ...func(string, *Message) error)

SetStopHooks specified the handlers of container exit.

func (*Client) Version

func (c *Client) Version() (string, error)

Version returns the version of containerd.

type Config

type Config struct {
	Address string
}

Config represents the config used to communicated with containerd.

type Container

type Container struct {
	Info *types.ContainerInfo
	IO   *containerio.IO
	Spec *specs.Spec
}

Container wraps container's info.

type Error

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

Error contains a code and a message. It implements the error interface.

func (Error) Error

func (e Error) Error() string

Error returns the error message.

func (Error) IsNotfound

func (e Error) IsNotfound() bool

IsNotfound return true if this is exactly something not found.

func (Error) IsTimeout

func (e Error) IsTimeout() bool

IsTimeout determines whether the error code is timeoutFailed.

func (Error) IsTrylockFailed

func (e Error) IsTrylockFailed() bool

IsTrylockFailed determines whether the error code is trylockFailed.

type Message

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

Message is used to watch containerd.

func (*Message) Error

func (m *Message) Error() error

Error returns the error contained in Message.

func (*Message) ExitCode

func (m *Message) ExitCode() uint32

ExitCode returns the exit code in Message.

func (*Message) ExitTime

func (m *Message) ExitTime() time.Time

ExitTime returns the exit time in Message.

func (*Message) HasError

func (m *Message) HasError() bool

HasError returns true if the error in message is not nil.

type Process

type Process struct {
	ContainerID string
	ExecID      string
	IO          *containerio.IO
	P           *specs.Process
}

Process wraps exec process's info.

type ProgressInfo

type ProgressInfo struct {
	Ref       string
	Status    string
	Offset    int64
	Total     int64
	StartedAt time.Time
	UpdatedAt time.Time

	// For Error handling
	Code         int    // http response code
	ErrorMessage string // detail error information
}

ProgressInfo represents the status of downloading image.

Jump to

Keyboard shortcuts

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