supervisor

package
v0.1.0-alpha.41 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Overview

Package supervisor is the container runtime of ADR 0046: images and container records kept by the agent itself, containers supervised by armada-shim. Work in progress; nothing uses it yet.

Index

Constants

View Source
const GroupAnnotation = "io.containerd.runc.v2.group"

GroupAnnotation names the shim a container shares; the driver sets it in the spec. A container without it gets a shim of its own.

Variables

This section is empty.

Functions

func NotFound

func NotFound(err error) bool

NotFound reports whether err says the shim does not know the container.

Types

type Bundles

type Bundles struct{ Dir string }

Bundles keeps containers' OCI bundles under Dir/<id>: config.json, the root filesystem mounted at rootfs, and record.json.

func (Bundles) Create

func (b Bundles) Create(rec Record, spec *specs.Spec, rootfs []mount.Mount) (string, error)

Create mounts the root filesystem, writes spec (its root set to the mounted rootfs), then the record last, so a bundle without a record is one that was never finished.

func (Bundles) Path

func (b Bundles) Path(id string) string

Path is the bundle directory of id.

func (Bundles) Records

func (b Bundles) Records() ([]Record, error)

Records lists every finished bundle's record.

func (Bundles) Remove

func (b Bundles) Remove(id string) error

Remove unmounts the root filesystem and removes the bundle.

func (Bundles) Spec

func (b Bundles) Spec(id string) (*specs.Spec, error)

Spec reads a bundle's OCI spec.

type Image

type Image struct {
	Name    string             `json:"name"`
	Target  ocispec.Descriptor `json:"target"`
	Config  ocispec.Descriptor `json:"config"`
	ChainID digest.Digest      `json:"chainID"`
	// Platforms the image offers, as "os/arch".
	Platforms []string          `json:"platforms,omitempty"`
	Labels    map[string]string `json:"labels,omitempty"`
	Created   time.Time         `json:"created"`
	Updated   time.Time         `json:"updated"`
}

Image is what the store records about a pulled image name.

type Images

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

Images keeps a node's images without a daemon: blobs in a content store under <root>/content, unpacked layers as overlay snapshots under <root>/snapshots, and one record per image name in <root>/images.json.

func OpenImages

func OpenImages(root string) (*Images, error)

OpenImages opens (creating) the store under root for this node's platform.

func (*Images) Close

func (s *Images) Close() error

Close releases the snapshotter's metadata.

func (*Images) Delete

func (s *Images) Delete(ctx context.Context, name string) error

Delete forgets an image, then removes layers and blobs no remaining image needs. Layers under a container's root filesystem stay: the snapshotter refuses to remove a parent.

func (*Images) Get

func (s *Images) Get(name string) (Image, bool)

Get returns the record of an image name.

func (*Images) List

func (s *Images) List() []Image

List returns every image record.

func (*Images) OCI

func (s *Images) OCI(img Image) (oci.Image, oci.Client)

OCI returns what containerd's spec options read of an image and its snapshots (the image's configuration, its users and groups).

func (*Images) Prepare

func (s *Images) Prepare(ctx context.Context, key string, img Image) ([]mount.Mount, error)

Prepare makes a writable root filesystem for container key on top of img's layers and returns its mounts.

func (*Images) Pull

func (s *Images) Pull(ctx context.Context, ref string, resolver remotes.Resolver, wrap func(images.Handler) images.Handler) (Image, error)

Pull resolves ref with resolver, fetches the manifest for this node's platform with its config and layers, unpacks the layers, and records the image under ref. The record keeps the labels of the record it replaces only when both name the same target. wrap, when set, wraps the handler that fetches each descriptor and finds its children.

func (*Images) Release

func (s *Images) Release(ctx context.Context, key string) error

Release removes container key's root filesystem.

func (*Images) SetLabel

func (s *Images) SetLabel(name, key, value string) error

SetLabel sets one label of an image record.

type Record

type Record struct {
	ID      string            `json:"id"`
	Image   string            `json:"image"`
	Labels  map[string]string `json:"labels,omitempty"`
	Group   string            `json:"group"`
	Created time.Time         `json:"created"`
}

Record is what the agent keeps about a container it created, next to its OCI bundle: enough to list, adopt, and remove it after a restart.

type Shim

type Shim struct {
	Group  string
	Socket string
	// Root is runc's state directory for the shim's containers.
	Root string
}

Shim is one running armada-shim.

func (*Shim) Create

func (sh *Shim) Create(ctx context.Context, id, bundle, logDir string) (int, error)

Create creates container id from bundle (not started); its output goes to armada-log in logDir. It returns the container's process ID.

func (*Shim) Delete

func (sh *Shim) Delete(ctx context.Context, id string) error

Delete removes the container, killing it first if it runs.

func (*Shim) Kill

func (sh *Shim) Kill(ctx context.Context, id string, sig int) error

Kill sends sig to the container's process.

func (*Shim) KillAll

func (sh *Shim) KillAll(ctx context.Context, id string, sig int) error

KillAll sends sig to every process in the container.

func (*Shim) List

func (sh *Shim) List(ctx context.Context) (map[string]TaskState, error)

List reports every container of the shim.

func (*Shim) Start

func (sh *Shim) Start(ctx context.Context, id string) error

Start starts a created container.

func (*Shim) State

func (sh *Shim) State(ctx context.Context, id string) (TaskState, error)

State reports one container.

func (*Shim) Wait

func (sh *Shim) Wait(ctx context.Context, id string) (int, error)

Wait blocks until the container exits and returns its exit code.

type Shims

type Shims struct {
	// Dir holds each shim's socket and state (tmpfs: nothing in it
	// outlives a reboot, like the containers).
	Dir string
	// Bin, Runc, and Logger are the programs a shim runs.
	Bin, Runc, Logger string
	// Launch starts a shim; nil runs it with systemd-run.
	Launch func(ctx context.Context, unit string, argv []string) error
	// Active reports whether a shim's unit still runs; nil asks systemd.
	Active func(ctx context.Context, unit string) (bool, error)
	// contains filtered or unexported fields
}

Shims starts and reaches armada-shim processes, one per group (an app and runtime pack on this node, ADR 0046). Each runs as a transient systemd service of its own, so restarting the agent's service leaves it, and the containers it supervises, alone.

func (*Shims) Abandon

func (s *Shims) Abandon(ctx context.Context, sh *Shim) (bool, error)

Abandon ends the containers a shim left behind once it is really gone, and reports whether it was. A shim that is slow or busy is not gone: its containers keep running, and the caller tries again later.

func (*Shims) For

func (s *Shims) For(ctx context.Context, group string) (*Shim, error)

For returns group's shim, starting it when none runs. A shim that runs but does not answer is an error, never replaced.

func (*Shims) Get

func (s *Shims) Get(group string) *Shim

Get returns group's shim without starting it; its calls fail when it does not run.

type Store

type Store struct {
	Images  *Images
	Bundles Bundles
	Shims   *Shims
	// Logs is the directory armada-log writes container output to.
	Logs string
	// contains filtered or unexported fields
}

Store is the agent's own container runtime (ADR 0046): images, bundles, and armada-shim processes. It offers containers, tasks, and images through containerd's client interfaces, so the driver's logic is the same on either runtime.

func (*Store) CheckLayers

func (s *Store) CheckLayers(context.Context, client.Image) error

CheckLayers reports nil: Images.Pull records an image only once its layers were checked.

func (*Store) Close

func (s *Store) Close() error

Close releases the image store.

func (*Store) Containers

func (s *Store) Containers(_ context.Context, filters ...string) ([]client.Container, error)

Containers returns recorded containers matching every filter.

func (*Store) ContentStore

func (s *Store) ContentStore() content.Store

ContentStore holds the images' blobs.

func (*Store) DeleteImage

func (s *Store) DeleteImage(ctx context.Context, name string, _ bool) error

DeleteImage forgets an image and removes what no other image or container uses, always at once.

func (*Store) GetImage

func (s *Store) GetImage(_ context.Context, name string) (client.Image, error)

GetImage returns a pulled image by name.

func (*Store) ListImages

func (s *Store) ListImages(context.Context) ([]images.Image, error)

ListImages lists pulled images.

func (*Store) LoadContainer

func (s *Store) LoadContainer(_ context.Context, id string) (client.Container, error)

LoadContainer returns a recorded container.

func (*Store) NewContainer

func (s *Store) NewContainer(ctx context.Context, id string, img client.Image, labels map[string]string, opts []oci.SpecOpts) (client.Container, error)

NewContainer records a container from img with labels and the spec opts make, and prepares its root filesystem. Its task is created by NewTask.

func (*Store) Ping

func (s *Store) Ping(context.Context) error

Ping checks the store is usable.

func (*Store) Pull

func (s *Store) Pull(ctx context.Context, ref string, resolver remotes.Resolver, wrap func(images.Handler) images.Handler) (client.Image, error)

Pull pulls and unpacks ref; wrap, when set, wraps the handler that fetches each descriptor.

func (*Store) SetImageLabel

func (s *Store) SetImageLabel(_ context.Context, name, key, value string) error

SetImageLabel sets one label of a pulled image.

func (*Store) Tasks

func (s *Store) Tasks(ctx context.Context) (map[string]*task.Process, error)

Tasks returns the state of every container's task by container ID, asking each shim once. Containers of a shim that does not answer are left out.

type TaskState

type TaskState struct {
	Status string // "created", "running", or "exited"
	Pid    int
	Exit   int
}

TaskState is what a shim reports about a container.

Jump to

Keyboard shortcuts

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