agentruntime

package
v0.4.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 34 Imported by: 0

Documentation

Overview

Package agentruntime executes worker operations without owning daemon state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckMachinesTarget

func CheckMachinesTarget(log *slog.Logger, failForMissing bool) preflight.Checker

CheckMachinesTarget checks that systemd can start nspawn workers at boot. TODO: Move this check to Unbounded's host preflight checks.

func PreflightGoalState

PreflightGoalState supplies the SDK root and executor used by the selected worker.

func RewriteContainerHostRoot

func RewriteContainerHostRoot(ctx context.Context, log *slog.Logger, input Node) error

RewriteContainerHostRoot updates the network helper and supervisor after a host-root move.

func RewriteHostRoot

func RewriteHostRoot(ctx context.Context, log *slog.Logger, cfg *agentconfig.AgentConfig, machine string) (*goalstates.RootFS, error)

RewriteHostRoot updates worker assets after a host-root move without starting the network unit.

func RunContainerLifecycle

func RunContainerLifecycle(ctx context.Context, log *slog.Logger, phase, slot string) error

RunContainerLifecycle handles the OCI supervisor's SDK lifecycle hooks.

Types

type Inputs

type Inputs struct {
	Config   *config.Config
	Node     Node
	Previous *Node
	Archives *goalstates.ContainerImageArchiveStaging
}

Inputs carry execution inputs resolved by the daemon. Previous is set for a repave.

type NSpawn

type NSpawn struct{}

NSpawn executes worker actions using resolved machine configuration.

func (NSpawn) PlanReset

func (NSpawn) PlanReset(log *slog.Logger) ResetPlan

PlanReset discovers all installed runtimes independently of applied state.

func (NSpawn) PrepareUpgrade

func (NSpawn) PrepareUpgrade(log *slog.Logger, input Inputs) phases.Task

func (NSpawn) Recover

func (NSpawn) Recover(log *slog.Logger, _ Inputs) phases.Task

func (NSpawn) Restart

func (NSpawn) Restart(log *slog.Logger, input Inputs) phases.Task

func (NSpawn) Retire

func (NSpawn) Retire(log *slog.Logger, input Inputs) phases.Task

func (NSpawn) Start

func (NSpawn) Start(log *slog.Logger, input Inputs) phases.Task

func (NSpawn) Worker

func (NSpawn) Worker(log *slog.Logger, node Node) (WorkerContext, error)

type Node

type Node struct {
	Slot      string
	Config    *agentconfig.AgentConfig
	GoalState *goalstates.MachineGoalState
}

Node contains a resolved worker configuration and placement.

type ResetPlan

type ResetPlan interface {
	// HasHostNativeState reports whether SDK discovery selected native teardown.
	HasHostNativeState() bool
	// Stop stops every discovered worker before any teardown runs.
	Stop() phases.Task
	// Finish destroys the discovered workers, then cleans shared host resources.
	Finish() phases.Task
}

ResetPlan captures runtime ownership before cleanup removes its evidence. The daemon runs Stop, cleans host components, then runs Finish.

type Runtime

type Runtime interface {
	// Worker resolves the selected worker's filesystem, executor, and service
	// context for components without loading or updating daemon State.
	Worker(*slog.Logger, Node) (WorkerContext, error)

	// Start provisions the first worker or applies a replacement when Previous
	// is supplied, then starts the worker and converges its NPD service.
	Start(*slog.Logger, Inputs) phases.Task

	// Restart restarts the installed worker in place without provisioning a
	// replacement, replacing kubelet identity, or advancing applied State.
	Restart(*slog.Logger, Inputs) phases.Task

	// PrepareUpgrade stops/cleans nspawn or recovers none SDK state before
	// replacement. OCI preparation is handled inside the SDK upgrade itself.
	PrepareUpgrade(*slog.Logger, Inputs) phases.Task

	// Recover reconciles the applied worker before startup or reapply using the
	// SDK's recovery support. OCI only rewrites its unit; it does not provide
	// durable recovery for interrupted upgrades.
	Recover(*slog.Logger, Inputs) phases.Task

	// Retire removes the superseded slot or commits/prunes a none SDK upgrade.
	// The daemon must successfully save the target as applied before invoking it.
	Retire(*slog.Logger, Inputs) phases.Task

	// PlanReset discovers owned worker runtimes at execution time, independently
	// of applied State. Callers stop workers before component cleanup and Finish;
	// State deletion, status publication and uninstall stay outside the plan.
	PlanReset(*slog.Logger) ResetPlan
}

Runtime constructs worker execution tasks. The daemon owns lifecycle decisions, applied State, and remote status publication; the SDK owns runtime recovery.

The daemon drives these transitions:

Bootstrap: Start -> save applied State
Reapply:   Recover(applied) -> Restart, without advancing applied State
Repave:    PrepareUpgrade(previous) -> agent hooks or host Hub cleanup
           -> Start(target) -> save applied State -> Retire(previous)
Reset:     stop workers -> host Hub cleanup if needed -> teardown -> clear configuration/State

An error stops the sequence without implying that earlier actions rolled back. Start must succeed before persistence, and persistence must succeed before Retire. Recovery guarantees are backend-specific; this interface adds no journal.

func New

func New(mode isolation.Mode) (Runtime, error)

New selects an already validated worker mode.

type WorkerContext

type WorkerContext struct {
	Root        isolation.NodeRoot
	Exec        func(context.Context, ...string) (string, error)
	KubeletUnit string
	Mode        isolation.Mode
}

WorkerContext describes the SDK filesystem and executor for the active worker.

Jump to

Keyboard shortcuts

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