cr

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BundleBuilder

func BundleBuilder(ctx context.Context, result PullResult, spec workload.Spec) (*configs.Config, error)

BundleBuilder produces a libcontainer Config from a pulled image.

Invariants:

  • The caller is responsible for constructing the libcontainer Process (Args, Env, Cwd, User) from the image config and workload Spec.
  • All containers get standard isolation namespaces and pseudo-fs mounts.
  • Resources (CPU, memory) from the spec are mapped to cgroup limits. MemoryMB is converted from megabytes to bytes for the kernel. CPUShares of 0 means no limit is set (kernel default applies).

func CheckHealth

func CheckHealth(ctx context.Context, logger *zap.Logger, spec workload.Spec, ctr *libcontainer.Container) bool

CheckHealth runs the spec's configured probe and returns true when the workload looks healthy. Empty probe means HTTP, preserving every old spec's behavior. Unknown probes, TCP without a mapped host port, and exec without a command are unhealthy, loudly: silent skips hide misconfiguration. The container handle serves exec probes only and may be nil for the others.

func StateDirPath

func StateDirPath() (string, error)

stateDirPath returns the directory libcontainer uses to store container state. It lives under the user config directory at ~/.config/concord/cr/.

Types

type AdoptedProcess

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

AdoptedProcess implements ProcessHandle for containers that survived a Concord daemon restart or crash recovery.

Background: When Concord launches a fresh container, libcontainer constructs an in-memory *libcontainer.Process struct containing internal pipes, FIFOs, and synchronization state. cr.Process wraps that struct to route Wait() and Signal() through libcontainer's process manager.

However, when the Concord daemon restarts, containers created in previous runs may still be actively running in their Linux cgroups and network namespaces. Calling libcontainer.Load(stateDir, id) deserializes the container metadata from disk, but does NOT restore the original in-memory *libcontainer.Process handle or its launch FIFOs. Instead, ctr.State() provides only the host OS PID (InitProcessPid).

AdoptedProcess bridges this gap: it implements ProcessHandle directly against the host OS process primitives (os.FindProcess, os.Process.Signal, os.Process.Wait) without requiring an in-memory *libcontainer.Process. This allows the reconciler and monitoring loops to treat freshly started and adopted containers uniformly through the ProcessHandle interface.

func (*AdoptedProcess) Exited

func (p *AdoptedProcess) Exited() <-chan ExitStatus

Exited returns a channel that receives the process exit status when terminated.

func (*AdoptedProcess) NamespacePID

func (p *AdoptedProcess) NamespacePID() int

NamespacePID returns the host PID of the adopted container process.

func (*AdoptedProcess) Signal

func (p *AdoptedProcess) Signal(signal os.Signal) error

Signal sends an OS signal directly to the host process using os.FindProcess.

type ContainerRuntime

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

ContainerRuntime manages the lifecycle of libcontainer-backed workloads. Each container gets a subdirectory under stateDir where libcontainer stores its checkpoint data, FIFOs, and config state.

func NewRuntime

func NewRuntime() (*ContainerRuntime, error)

NewRuntime creates a ContainerRuntime with its state directory under ~/.config/concord/cr/. Multiple containers share this state directory; each is keyed by its unique ID.

func (*ContainerRuntime) Create

Create sets up a new container with the given configs.Config but does not start any process inside it. Call Start to run the init process.

func (*ContainerRuntime) Start

Start runs the init process inside the container and returns once it is running (non-blocking). The container must have been created with Create first. Use ProcessHandle.Exited() to wait for the process to exit. It returns a ProcessHandle containing the process execution state and namespace PID.

type ExitStatus

type ExitStatus struct {
	Err  error
	Code int
}

ExitStatus represents the outcome of process execution.

type ImagePuller

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

ImagePuller pulls OCI container images from the local zot registry at localhost:8444 and extracts them into rootfs directories.

func NewImagePuller

func NewImagePuller() *ImagePuller

NewImagePuller creates an ImagePuller targeting the local zot instance.

func (*ImagePuller) Pull

func (p *ImagePuller) Pull(ctx context.Context, ref, bundleDir string) (*PullResult, error)

Pull fetches the image, resolves the platform, and extracts layers into the rootfs directory under bundleDir. A stale rootfs from a previous attempt is removed first so a failed start retries cleanly instead of wedging every later tick on an already-exists error. A failed extraction also removes the partial rootfs for the same reason.

type Process

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

Process implements ProcessHandle for libcontainer process management.

func NewProcess

func NewProcess(process *libcontainer.Process, namespacePID int) *Process

NewProcess creates a Process handle and starts monitoring process exit asynchronously.

func (*Process) Exited

func (p *Process) Exited() <-chan ExitStatus

Exited returns a channel that receives process exit notification.

func (*Process) NamespacePID

func (p *Process) NamespacePID() int

NamespacePID returns the host PID of the container process.

func (*Process) Signal

func (p *Process) Signal(signal os.Signal) error

Signal sends an OS signal to the container process.

type ProcessHandle

type ProcessHandle interface {
	NamespacePID() int
	Signal(os.Signal) error
	Exited() <-chan ExitStatus
}

ProcessHandle defines the interface for interacting with a running container process.

func AdoptProcess

func AdoptProcess(pid int) ProcessHandle

AdoptProcess wraps an existing host OS process PID in an AdoptedProcess handle that monitors its exit state in the background.

type PullResult

type PullResult struct {
	Config *v1.ConfigFile
	RootFS string
}

PullResult contains the extracted rootfs path and the image configuration for use by the bundle builder.

type Puller

type Puller interface {
	Pull(ctx context.Context, image, bundleDir string) (*PullResult, error)
}

Puller a definition of an interface that is required to be a puller.

type Runner

type Runner interface {
	Create(id string, cfg *configs.Config) (*libcontainer.Container, error)
	Start(ctr *libcontainer.Container, proc *libcontainer.Process) (ProcessHandle, error)
}

Runner a definition of an interface that is required to be a runner.

Jump to

Keyboard shortcuts

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