runtime

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package runtime is the function worker port (ADR-0011): create, start, stop, observe, and harvest logs from a worker instance (one replica of a function).

The port is driver-independent and imports no container library. Two drivers implement it: a cross-platform process driver (internal/runtime/process — the dev/e2e/CI driver) and a Linux-only containerd/runc driver (internal/runtime/containerd). The controller maps Function/Revision/RuntimeClass (ADR-0003) into a WorkerSpec; this port does not read resources, and functions never call it (internal-plane only).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

type Instance struct {
	ID        InstanceID
	Namespace v1alpha1.NamespaceName
	Name      v1alpha1.ObjectName
	Revision  v1alpha1.ObjectName // as created (ADR-0143)
	Replica   int
	PID       int
	State     State
	IP        string // worker endpoint host: netns IP (containerd) or 127.0.0.1 (process driver, ADR-0030)
	Port      int    // worker HTTP port: the shim's listening port (ADR-0030); 0 until resolved
	CreatedAt time.Time
}

Instance is the observed state of one worker.

type InstanceID

type InstanceID string

InstanceID identifies one worker instance (a function replica).

func NewInstanceID

func NewInstanceID(ns v1alpha1.NamespaceName, name, revision v1alpha1.ObjectName, replica int) InstanceID

NewInstanceID builds the canonical id "<ns>/<name>/r<replica>", or "<ns>/<name>/<revision>/r<replica>" for a worker of a Revision, so two revisions of one replica can run at once (ADR-0143).

type Limits

type Limits struct {
	MemoryBytes int64
	CPUs        float64
}

Limits bounds a worker's resources (0 = unlimited).

type LogCaptureFunc

type LogCaptureFunc func(spec WorkerSpec, r io.ReadCloser)

LogCaptureFunc receives one instance's structured telemetry channel (ADR-0081 Path B): r yields the NDJSON records the runtime shim writes to its log channel. The composition root supplies it (wiring a funclog Pump); the implementation owns reading and closing r. spec identifies the instance whose logs these are.

type LogCapturer

type LogCapturer interface {
	// SetLogCapture installs (or clears, with nil) the per-instance log-channel hook.
	SetLogCapture(LogCaptureFunc)
}

LogCapturer is the OPTIONAL capability a runtime driver implements to deliver per-instance structured logs (ADR-0081). funcd sets the hook after building the funclog sink; a driver that does not implement it simply captures no Path B telemetry. Keeping it off the Runtime port keeps the port free of the observability concern (the port imports no observability package).

type Mount

type Mount struct {
	Source   string // host path
	Target   string // container path
	ReadOnly bool
}

Mount is a host→container bind mount (ADR-0032). Container drivers (containerd) honor it; the process driver ignores it (no container filesystem). Used to deliver the function artifact read-only into the curated-image worker.

type Runtime

type Runtime interface {
	// Create makes a worker from spec without starting it.
	Create(ctx context.Context, spec WorkerSpec) (Instance, error)
	// Start runs the worker's process.
	Start(ctx context.Context, id InstanceID) error
	// Stop terminates the process (SIGTERM, then SIGKILL); it is idempotent.
	Stop(ctx context.Context, id InstanceID) error
	// Status returns the observed instance; fault.NotFound if unknown.
	Status(ctx context.Context, id InstanceID) (Instance, error)
	// Logs returns a reader over the instance's captured stdout+stderr.
	Logs(ctx context.Context, id InstanceID) (io.ReadCloser, error)
	// Exec runs a command in the instance's context (best-effort in V1).
	Exec(ctx context.Context, id InstanceID, cmd []string) error
	// List returns the instances in a namespace.
	List(ctx context.Context, ns v1alpha1.NamespaceName) ([]Instance, error)
	// Remove forgets an instance after Stop has released it, with its per-instance files: Status then reports
	// fault.NotFound and List omits it. An instance Stop has not released — running, created, or exited on its own —
	// is fault.Conflict; an unknown one is a no-op (ADR-0143).
	Remove(ctx context.Context, id InstanceID) error
	// Close releases the driver's resources.
	Close() error
}

Runtime is the worker port: create/start/stop/observe one function replica. Errors are api/fault; every method is ctx-first; the port imports no container library. Implementations are internal-plane only — functions never call them.

type State

type State string

State is the lifecycle state of a worker instance.

const (
	// StateCreated means the worker exists but its process is not started.
	StateCreated State = "created"
	// StateRunning means the worker process is running.
	StateRunning State = "running"
	// StateStopped means the worker process exited or was stopped.
	StateStopped State = "stopped"
	// StateFailed means the worker process exited abnormally.
	StateFailed State = "failed"
)

func (State) Terminal added in v0.1.3

func (s State) Terminal() bool

Terminal reports whether an instance in this state has exited (Stopped or Failed).

type WorkerSpec

type WorkerSpec struct {
	Namespace v1alpha1.NamespaceName
	Name      v1alpha1.ObjectName
	Revision  v1alpha1.ObjectName // the Revision this worker runs (ADR-0143); "" outside the Function lifecycle
	Replica   int
	Image     string            // runtime image (containerd driver)
	Command   []string          // launch command / container args
	Env       map[string]string // typed-flat; no any
	Mounts    []Mount           // host→container bind mounts (container drivers; ADR-0032)
	Limits    Limits
	LogPath   string // file for captured stdout+stderr ("" → driver picks a temp file)
}

WorkerSpec is the driver-independent request to run one function replica. The controller assembles it from Function/Revision/RuntimeClass (ADR-0003).

Directories

Path Synopsis
Package containerd implements the runtime.Runtime port over containerd + runc on Linux (ADR-0011): pull a curated runtime image, run it as a runc container with conservative OCI defaults (no added caps, no_new_privileges, optional limits), attach a per-worker netns with default-deny lateral (go-cni bridge + firewall), and harvest logs via cio.LogFile.
Package containerd implements the runtime.Runtime port over containerd + runc on Linux (ADR-0011): pull a curated runtime image, run it as a runc container with conservative OCI defaults (no added caps, no_new_privileges, optional limits), attach a per-worker netns with default-deny lateral (go-cni bridge + firewall), and harvest logs via cio.LogFile.
Package ctrmanager brings up the container runtime funcd will drive (ADR-0054).
Package ctrmanager brings up the container runtime funcd will drive (ADR-0054).
Package embedimg carries funcd's curated runtime images baked into the binary (ADR-0054).
Package embedimg carries funcd's curated runtime images baked into the binary (ADR-0054).
Package process implements the runtime.Runtime port by supervising functions as plain OS child processes (ADR-0011).
Package process implements the runtime.Runtime port by supervising functions as plain OS child processes (ADR-0011).
Package provision is funcd's TEMPORARY container-runtime self-provisioning (ADR-0056): `funcd install` downloads the pinned, SHA-256-verified static binaries the managed-containerd path needs — crun (the OCI runtime the runc-v2 shim execs), containerd (+ its runc-v2 shim + ctr), and the CNI plugins — laying crun/containerd into funcd's bin dir and the CNI plugins into /opt/cni/bin.
Package provision is funcd's TEMPORARY container-runtime self-provisioning (ADR-0056): `funcd install` downloads the pinned, SHA-256-verified static binaries the managed-containerd path needs — crun (the OCI runtime the runc-v2 shim execs), containerd (+ its runc-v2 shim + ctr), and the CNI plugins — laying crun/containerd into funcd's bin dir and the CNI plugins into /opt/cni/bin.
Package runtimecontract is the shared conformance suite for the runtime.Runtime port (ADR-0011).
Package runtimecontract is the shared conformance suite for the runtime.Runtime port (ADR-0011).

Jump to

Keyboard shortcuts

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