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 ¶
ErrImageUnavailable is wrapped, with kind fault.NotFound, by a driver's Create when the worker image is absent: a ref the driver may not pull, or a pull that finds no such image (ADR-0149 Decision 3).
Functions ¶
This section is empty.
Types ¶
type Exit ¶ added in v0.4.0
Exit is how an instance ended; zero until it ends. Code 3 is a shim that cannot load its handler (ADR-0037).
type ExitCause ¶ added in v0.4.0
type ExitCause string
ExitCause is how a worker instance ended (ADR-0160).
const ( // ExitUnknown means the instance has not ended, or its end could not be read. ExitUnknown ExitCause = "" // ExitByStop means Stop ended the instance, or ran after it ended. ExitByStop ExitCause = "stop" // ExitByCode means the process exited on its own with Exit.Code. ExitByCode ExitCause = "code" // ExitBySignal means a signal Stop did not send, Exit.Signal, ended the process. ExitBySignal ExitCause = "signal" )
type Instance ¶
type Instance struct {
ID InstanceID
Namespace v1alpha1.NamespaceName
Name v1alpha1.ObjectName
OwnerKind v1alpha1.Kind // as created (ADR-0152)
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
Listened bool // wrote its port to FUNCD_PORTFILE since its last Start; stays true after it ends (ADR-0160)
Exit Exit
}
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 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 ¶
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. An empty spec.OwnerKind is fault.Invalid; an ID held by an
// instance of another OwnerKind, even when that instance has exited, or on containerd by a leftover container
// labelled with another kind, is fault.Conflict (ADR-0152).
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" )
type WorkerSpec ¶
type WorkerSpec struct {
Namespace v1alpha1.NamespaceName
Name v1alpha1.ObjectName
OwnerKind v1alpha1.Kind // the kind whose reconciler created the worker; required (ADR-0152)
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). |