containerd

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2026 License: AGPL-3.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSocketPath = "/run/containerd/containerd.sock"
	DefaultNamespace  = "default"

	BackendContainerd = "containerd"
	BackendApple      = "apple"
)

Variables

View Source
var (
	ErrInvalidArgument = errors.New("invalid argument")
	ErrTaskStopTimeout = errors.New("timeout waiting for task to stop")
)
View Source
var ErrNotSupported = errors.New("operation not supported on this backend")

Functions

func MountSnapshot

func MountSnapshot(ctx context.Context, service Service, snapshotter, key string) (string, func() error, error)

MountSnapshot mounts a snapshot by snapshotter/key without a container.

func ResolveConfSource

func ResolveConfSource(dataDir string) (string, error)

ResolveConfSource returns a host path to mount as /etc/resolv.conf. If systemd-resolved config is available, use it. Otherwise write a fallback resolv.conf under dataDir and return that path.

Types

type AppleService

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

func NewAppleService

func NewAppleService(ctx context.Context, log *slog.Logger, cfg AppleServiceConfig) (*AppleService, error)

func (*AppleService) Close

func (s *AppleService) Close() error

func (*AppleService) CommitSnapshot

func (s *AppleService) CommitSnapshot(context.Context, string, string, string) error

func (*AppleService) CreateContainer

func (s *AppleService) CreateContainer(ctx context.Context, req CreateContainerRequest) (ContainerInfo, error)

func (*AppleService) CreateContainerFromSnapshot

func (s *AppleService) CreateContainerFromSnapshot(context.Context, CreateContainerRequest) (ContainerInfo, error)

func (*AppleService) DeleteContainer

func (s *AppleService) DeleteContainer(ctx context.Context, id string, opts *DeleteContainerOptions) error

func (*AppleService) DeleteImage

func (s *AppleService) DeleteImage(ctx context.Context, ref string, opts *DeleteImageOptions) error

func (*AppleService) DeleteTask

func (*AppleService) ExecTask

func (s *AppleService) ExecTask(ctx context.Context, containerID string, req ExecTaskRequest) (ExecTaskResult, error)

ExecTask executes a command inside the container.

Limitations compared to the containerd backend:

  • WorkDir: the Apple Container exec API (ExecCreateRequest) has no working-directory field; req.WorkDir is silently ignored.
  • Env: similarly, environment variables cannot be injected at exec time via this API; req.Env is silently ignored.
  • Stdin: the acgo exec interface does not expose a write channel, so req.Stdin is not connected and the process receives no stdin input.
  • Stderr: the Apple Container API returns stdout and stderr as a single combined stream; they cannot be routed to separate writers. The combined output is sent to req.Stdout when set, otherwise to req.Stderr when set, otherwise discarded.
  • FIFODir: a containerd-specific concept; not applicable here.

func (*AppleService) ExecTaskStreaming

func (*AppleService) GetContainer

func (s *AppleService) GetContainer(ctx context.Context, id string) (ContainerInfo, error)

func (*AppleService) GetImage

func (s *AppleService) GetImage(ctx context.Context, ref string) (ImageInfo, error)

func (*AppleService) GetTaskInfo

func (s *AppleService) GetTaskInfo(ctx context.Context, containerID string) (TaskInfo, error)

func (*AppleService) ListContainers

func (s *AppleService) ListContainers(ctx context.Context) ([]ContainerInfo, error)

func (*AppleService) ListContainersByLabel

func (s *AppleService) ListContainersByLabel(ctx context.Context, key, value string) ([]ContainerInfo, error)

func (*AppleService) ListImages

func (s *AppleService) ListImages(ctx context.Context) ([]ImageInfo, error)

func (*AppleService) ListSnapshots

func (s *AppleService) ListSnapshots(context.Context, string) ([]SnapshotInfo, error)

func (*AppleService) ListTasks

func (s *AppleService) ListTasks(ctx context.Context, opts *ListTasksOptions) ([]TaskInfo, error)

func (*AppleService) PrepareSnapshot

func (s *AppleService) PrepareSnapshot(context.Context, string, string, string) error

func (*AppleService) PullImage

func (s *AppleService) PullImage(ctx context.Context, ref string, opts *PullImageOptions) (ImageInfo, error)

func (*AppleService) RemoveNetwork

func (*AppleService) SetupNetwork

func (*AppleService) SnapshotMounts

func (s *AppleService) SnapshotMounts(context.Context, string, string) ([]MountInfo, error)

func (*AppleService) StartContainer

func (s *AppleService) StartContainer(ctx context.Context, containerID string, opts *StartTaskOptions) error

func (*AppleService) StopContainer

func (s *AppleService) StopContainer(ctx context.Context, containerID string, opts *StopTaskOptions) error

type AppleServiceConfig

type AppleServiceConfig struct {
	SocketPath string
	BinaryPath string
}

type ClientFactory

type ClientFactory interface {
	New(ctx context.Context) (*containerd.Client, error)
}

type ContainerInfo

type ContainerInfo struct {
	ID          string
	Image       string
	Labels      map[string]string
	Snapshotter string
	SnapshotKey string
	Runtime     RuntimeInfo
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type ContainerSpec

type ContainerSpec struct {
	Cmd     []string
	Env     []string
	WorkDir string
	User    string
	Mounts  []MountSpec
	DNS     []string
	TTY     bool
}

type CreateContainerRequest

type CreateContainerRequest struct {
	ID          string
	ImageRef    string
	SnapshotID  string
	Snapshotter string
	Labels      map[string]string
	Spec        ContainerSpec
}

type DefaultClientFactory

type DefaultClientFactory struct {
	SocketPath string
}

func (DefaultClientFactory) New

type DefaultService

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

func NewDefaultService

func NewDefaultService(log *slog.Logger, client *containerd.Client, cfg config.Config) *DefaultService

func (*DefaultService) CommitSnapshot

func (s *DefaultService) CommitSnapshot(ctx context.Context, snapshotter, name, key string) error

func (*DefaultService) CreateContainer

func (s *DefaultService) CreateContainer(ctx context.Context, req CreateContainerRequest) (ContainerInfo, error)

func (*DefaultService) CreateContainerFromSnapshot

func (s *DefaultService) CreateContainerFromSnapshot(ctx context.Context, req CreateContainerRequest) (ContainerInfo, error)

func (*DefaultService) DeleteContainer

func (s *DefaultService) DeleteContainer(ctx context.Context, id string, opts *DeleteContainerOptions) error

func (*DefaultService) DeleteImage

func (s *DefaultService) DeleteImage(ctx context.Context, ref string, opts *DeleteImageOptions) error

func (*DefaultService) DeleteTask

func (s *DefaultService) DeleteTask(ctx context.Context, containerID string, opts *DeleteTaskOptions) error

func (*DefaultService) ExecTask

func (s *DefaultService) ExecTask(ctx context.Context, containerID string, req ExecTaskRequest) (ExecTaskResult, error)

func (*DefaultService) ExecTaskStreaming

func (s *DefaultService) ExecTaskStreaming(ctx context.Context, containerID string, req ExecTaskRequest) (*ExecTaskSession, error)

func (*DefaultService) GetContainer

func (s *DefaultService) GetContainer(ctx context.Context, id string) (ContainerInfo, error)

func (*DefaultService) GetImage

func (s *DefaultService) GetImage(ctx context.Context, ref string) (ImageInfo, error)

func (*DefaultService) GetTaskInfo

func (s *DefaultService) GetTaskInfo(ctx context.Context, containerID string) (TaskInfo, error)

func (*DefaultService) ListContainers

func (s *DefaultService) ListContainers(ctx context.Context) ([]ContainerInfo, error)

func (*DefaultService) ListContainersByLabel

func (s *DefaultService) ListContainersByLabel(ctx context.Context, key, value string) ([]ContainerInfo, error)

func (*DefaultService) ListImages

func (s *DefaultService) ListImages(ctx context.Context) ([]ImageInfo, error)

func (*DefaultService) ListSnapshots

func (s *DefaultService) ListSnapshots(ctx context.Context, snapshotter string) ([]SnapshotInfo, error)

func (*DefaultService) ListTasks

func (s *DefaultService) ListTasks(ctx context.Context, opts *ListTasksOptions) ([]TaskInfo, error)

func (*DefaultService) PrepareSnapshot

func (s *DefaultService) PrepareSnapshot(ctx context.Context, snapshotter, key, parent string) error

func (*DefaultService) PullImage

func (s *DefaultService) PullImage(ctx context.Context, ref string, opts *PullImageOptions) (ImageInfo, error)

func (*DefaultService) RemoveNetwork

func (s *DefaultService) RemoveNetwork(ctx context.Context, req NetworkSetupRequest) error

func (*DefaultService) SetupNetwork

func (s *DefaultService) SetupNetwork(ctx context.Context, req NetworkSetupRequest) error

func (*DefaultService) SnapshotMounts

func (s *DefaultService) SnapshotMounts(ctx context.Context, snapshotter, key string) ([]MountInfo, error)

func (*DefaultService) StartContainer

func (s *DefaultService) StartContainer(ctx context.Context, containerID string, opts *StartTaskOptions) error

func (*DefaultService) StopContainer

func (s *DefaultService) StopContainer(ctx context.Context, containerID string, opts *StopTaskOptions) error

type DeleteContainerOptions

type DeleteContainerOptions struct {
	CleanupSnapshot bool
}

type DeleteImageOptions

type DeleteImageOptions struct {
	Synchronous bool
}

type DeleteTaskOptions

type DeleteTaskOptions struct {
	Force bool
}

type ExecTaskRequest

type ExecTaskRequest struct {
	Args     []string
	Env      []string
	WorkDir  string
	Terminal bool
	UseStdio bool
	FIFODir  string
	Stdin    io.Reader
	Stdout   io.Writer
	Stderr   io.Writer
}

type ExecTaskResult

type ExecTaskResult struct {
	ExitCode uint32
}

type ExecTaskSession

type ExecTaskSession struct {
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
	Stderr io.ReadCloser
	Wait   func() (ExecTaskResult, error)
	Close  func() error
}

type ImageInfo

type ImageInfo struct {
	Name string
	ID   string
	Tags []string
}

type ListTasksOptions

type ListTasksOptions struct {
	Filter string
}

type MountInfo

type MountInfo struct {
	Type    string
	Source  string
	Target  string
	Options []string
}

type MountSpec

type MountSpec struct {
	Destination string
	Type        string
	Source      string
	Options     []string
}

func TimezoneSpec

func TimezoneSpec() ([]MountSpec, []string)

TimezoneSpec returns mount specs and environment variables that propagate the host timezone into the container via /etc/localtime bind-mount and TZ environment variable.

type MountedSnapshot

type MountedSnapshot struct {
	Dir     string
	Info    ContainerInfo
	Unmount func() error
}

func MountContainerSnapshot

func MountContainerSnapshot(ctx context.Context, service Service, containerID string) (*MountedSnapshot, error)

MountContainerSnapshot mounts the active snapshot for a container.

type NetworkSetupRequest

type NetworkSetupRequest struct {
	ContainerID string
	PID         uint32
	CNIBinDir   string
	CNIConfDir  string
}

type PullImageOptions

type PullImageOptions struct {
	Unpack      bool
	Snapshotter string
}

type RuntimeInfo

type RuntimeInfo struct {
	Name string
}

type Service

type Service interface {
	PullImage(ctx context.Context, ref string, opts *PullImageOptions) (ImageInfo, error)
	GetImage(ctx context.Context, ref string) (ImageInfo, error)
	ListImages(ctx context.Context) ([]ImageInfo, error)
	DeleteImage(ctx context.Context, ref string, opts *DeleteImageOptions) error

	CreateContainer(ctx context.Context, req CreateContainerRequest) (ContainerInfo, error)
	GetContainer(ctx context.Context, id string) (ContainerInfo, error)
	ListContainers(ctx context.Context) ([]ContainerInfo, error)
	DeleteContainer(ctx context.Context, id string, opts *DeleteContainerOptions) error
	ListContainersByLabel(ctx context.Context, key, value string) ([]ContainerInfo, error)

	StartContainer(ctx context.Context, containerID string, opts *StartTaskOptions) error
	StopContainer(ctx context.Context, containerID string, opts *StopTaskOptions) error
	DeleteTask(ctx context.Context, containerID string, opts *DeleteTaskOptions) error
	GetTaskInfo(ctx context.Context, containerID string) (TaskInfo, error)
	ListTasks(ctx context.Context, opts *ListTasksOptions) ([]TaskInfo, error)
	ExecTask(ctx context.Context, containerID string, req ExecTaskRequest) (ExecTaskResult, error)
	ExecTaskStreaming(ctx context.Context, containerID string, req ExecTaskRequest) (*ExecTaskSession, error)

	SetupNetwork(ctx context.Context, req NetworkSetupRequest) error
	RemoveNetwork(ctx context.Context, req NetworkSetupRequest) error

	CommitSnapshot(ctx context.Context, snapshotter, name, key string) error
	ListSnapshots(ctx context.Context, snapshotter string) ([]SnapshotInfo, error)
	PrepareSnapshot(ctx context.Context, snapshotter, key, parent string) error
	CreateContainerFromSnapshot(ctx context.Context, req CreateContainerRequest) (ContainerInfo, error)
	SnapshotMounts(ctx context.Context, snapshotter, key string) ([]MountInfo, error)
}

func ProvideService

func ProvideService(ctx context.Context, log *slog.Logger, cfg config.Config, backend string) (Service, func(), error)

ProvideService creates the appropriate Service based on the backend type.

type SnapshotCommitResult

type SnapshotCommitResult struct {
	VersionSnapshotName string
	ActiveSnapshotName  string
}

type SnapshotInfo

type SnapshotInfo struct {
	Name    string
	Parent  string
	Kind    string
	Created time.Time
	Updated time.Time
	Labels  map[string]string
}

type StartTaskOptions

type StartTaskOptions struct {
	UseStdio bool
	Terminal bool
	FIFODir  string
}

type StopTaskOptions

type StopTaskOptions struct {
	Signal  syscall.Signal
	Timeout time.Duration
	Force   bool
}

type TaskInfo

type TaskInfo struct {
	ContainerID string
	ID          string
	PID         uint32
	Status      TaskStatus
	ExitCode    uint32
}

type TaskStatus

type TaskStatus int
const (
	TaskStatusUnknown TaskStatus = iota
	TaskStatusCreated
	TaskStatusRunning
	TaskStatusStopped
	TaskStatusPaused
)

func (TaskStatus) String

func (s TaskStatus) String() string

Jump to

Keyboard shortcuts

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