daemon

package
v0.23.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (

	// DeferredExitCode is returned when the daemon has no work because an
	// installation owns the host. It is not a failure, and the daemon unit
	// names it in both SuccessExitStatus and RestartPreventExitStatus so
	// systemd leaves the unit inactive instead of restarting it, exhausting the
	// start limit, and running OnFailure recovery. Those two directives and this
	// constant have to agree; TestDaemonUnitDeclaresDeferredExitCode pins that.
	//
	// 69 is EX_UNAVAILABLE: the service is correct but cannot run yet.
	DeferredExitCode = 69
)

Variables

View Source
var ErrDeferred = errors.New("daemon deferred until installation completes")

ErrDeferred reports that the daemon cannot run because an installation owns the host, and that this is expected rather than a fault. The command layer turns it into DeferredExitCode without printing an error.

Run wraps it with context, so callers must test with errors.Is.

View Source
var ErrRestartRequested = errors.New("daemon stopping to be restarted")

ErrRestartRequested reports that the daemon stopped so it can be started again: it staged an AgentUpgrade, or moved its files to the host root, and the unit now runs a different binary or a different path. The command layer re-executes the binary the unit runs in the same process. If it cannot, it exits 0, and the unit's Restart=always starts the daemon again after RestartSec.

The daemon does not ask systemd to restart it. A systemctl it runs is in the daemon's cgroup, and stopping the daemon kills everything in that cgroup. When the kill lands before systemctl exits, the daemon sees a failed command for a restart already under way. Re-executing or exiting leaves nothing to kill.

Functions

func EnableDaemon added in v0.1.1

func EnableDaemon(log *slog.Logger) phases.Task

EnableDaemon returns a task that installs, enables, and starts the unbounded-agent-daemon systemd unit on the host. The unit runs "unbounded-agent daemon" which watches the Machine CR for this node and reconciles the local state to match.

func InstallBootstrapBinary added in v0.9.0

func InstallBootstrapBinary() error

InstallBootstrapBinary installs the staged bootstrap executable unless the host already has a usable daemon binary. The caller holds installation ownership; existing binary layouts are retained and upgrades use their normal activation path.

The binary path comes from the resolved upgrade paths, so an environment override lands the binary where VerifyDaemonInstalled will look for it.

func MigrateHostRoot added in v0.13.0

func MigrateHostRoot(log *slog.Logger) error

MigrateHostRoot links the host root to the legacy root on a host installed by an agent released before the host root. Commands that change the host call it before resolving any path; see hostroot.Migrate.

func PersistAppliedConfig added in v0.1.1

func PersistAppliedConfig(log *slog.Logger, machineName string, cfg *config.AgentConfig) phases.Task

PersistAppliedConfig returns a task that writes the agent config to the applied config file for the nspawn machine. The daemon reads this file on startup to detect configuration drift.

func RecordAgentUpgradeFailureSignal added in v0.1.4

func RecordAgentUpgradeFailureSignal(message string) error

RecordAgentUpgradeFailureSignal records that the daemon failed after an AgentUpgrade.

func RemoveAgentArtifacts added in v0.1.1

func RemoveAgentArtifacts(log *slog.Logger) phases.Task

RemoveAgentArtifacts returns a task that removes the agent binary, install script, legacy uninstall script, config directory, and temp files, and then the host root itself once it is empty, or the link to the legacy root on a migrated host.

func RemoveAppliedConfig added in v0.1.1

func RemoveAppliedConfig(log *slog.Logger, machineName string) phases.Task

RemoveAppliedConfig returns a task that removes the applied agent config file and its checksum sidecar for the named machine. Errors are logged but do not fail the task.

func RemoveDaemonUnit added in v0.1.4

func RemoveDaemonUnit(log *slog.Logger) phases.Task

RemoveDaemonUnit returns a task that disables and removes the unbounded-agent-daemon systemd unit without stopping the running service.

func RemoveFirstBootBootstrapUnit added in v0.13.0

func RemoveFirstBootBootstrapUnit(log *slog.Logger) phases.Task

RemoveFirstBootBootstrapUnit returns a task that stops, disables and removes the unit an Ignition config installs to bootstrap the agent.

The unit runs on every boot and relies on the ownership record, which reset removes, to decide there is nothing to do. Left behind, it would bootstrap the reset host again on the next boot.

func RepairDaemon added in v0.9.0

func RepairDaemon(ctx context.Context, log *slog.Logger) error

RepairDaemon requires the caller's installation lock. It uses current applied configuration, never the original bootstrap input that may name a retired slot.

func ResetAgent added in v0.9.0

func ResetAgent(log *slog.Logger) phases.Task

ResetAgent removes the unbounded-agent and all associated resources, stopping the daemon first. The daemon's own operation path stops it last instead, so that ordering stays with the caller.

func Run

func Run(ctx context.Context, log *slog.Logger, modes ModeOperators) error

Run is the main daemon entry point. It discovers the active node, builds a Kubernetes client, registers the Machine CR if needed, and blocks until the context is canceled. modes is the operator of every isolation mode this agent can operate, from the agent's mode composition table.

func StopDaemon added in v0.1.1

func StopDaemon(log *slog.Logger) phases.Task

StopDaemon returns a task that stops, disables, and removes the unbounded-agent-daemon systemd unit. Only an absent unit permits a failed stop; substantive service errors must retain reset ownership.

func VerifyDaemonInstalled added in v0.9.0

func VerifyDaemonInstalled(ctx context.Context, log *slog.Logger) error

VerifyDaemonInstalled checks installed daemon assets and service state. An active daemon already proves it resolved an applied config at startup, so the applied-config check belongs to RepairDaemon rather than here.

Types

type ActiveMachine

type ActiveMachine struct {
	Name   string
	Config *provision.AgentConfig
	// Mode is the isolation mode the machine was applied with. The empty mode
	// is the default mode.
	Mode isolation.Mode
}

ActiveMachine holds the currently active node slot, its applied agent configuration and the isolation mode it runs in.

type BackendFactory added in v0.23.0

type BackendFactory func(log *slog.Logger, cfg *provision.AgentConfig) isolation.Backend

BackendFactory builds a mode's isolation backend bound to one agent configuration.

type BootstrapStatusReporter added in v0.1.20

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

BootstrapStatusReporter publishes the agent's initial bootstrap progress to the Machine status. It is best-effort so bootstrap can continue when the cluster is temporarily unavailable or RBAC has not been updated yet.

func NewBootstrapStatusReporter added in v0.1.20

func NewBootstrapStatusReporter(ctx context.Context, log *slog.Logger, cfg *provision.AgentConfig) *BootstrapStatusReporter

NewBootstrapStatusReporter builds a best-effort Machine status reporter from bootstrap credentials in cfg. When credentials are incomplete, the returned reporter logs and skips updates.

func (*BootstrapStatusReporter) Failed added in v0.1.20

func (r *BootstrapStatusReporter) Failed(ctx context.Context, reason string, err error)

Failed reports that initial bootstrap failed.

func (*BootstrapStatusReporter) Running added in v0.1.20

func (r *BootstrapStatusReporter) Running(ctx context.Context)

Running reports that initial bootstrap is in progress.

func (*BootstrapStatusReporter) Succeeded added in v0.1.20

func (r *BootstrapStatusReporter) Succeeded(ctx context.Context)

Succeeded reports that initial bootstrap completed successfully.

type HostDaemonActivationService added in v0.2.3

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

HostDaemonActivationService manages the Unbounded systemd units used by a host-driven agent binary activation.

func NewHostDaemonActivationService added in v0.2.3

func NewHostDaemonActivationService(log *slog.Logger, paths goalstates.AgentUpgradePaths) *HostDaemonActivationService

NewHostDaemonActivationService returns the Unbounded systemd adapter for host-driven agent activation.

func (*HostDaemonActivationService) Preflight added in v0.2.3

func (s *HostDaemonActivationService) Preflight(_ context.Context, currentBinaryPath string) (agentbinary.ServicePlan, error)

Preflight reports whether the installed daemon assets differ from the desired assets. It does not change the host.

func (*HostDaemonActivationService) Prepare added in v0.2.3

func (s *HostDaemonActivationService) Prepare(_ context.Context, currentBinaryPath string) error

Prepare installs the daemon service, recovery service, and recovery script. It does not reload systemd or restart the daemon.

func (*HostDaemonActivationService) Reload added in v0.2.3

Reload reloads systemd configuration.

func (*HostDaemonActivationService) Restart added in v0.2.3

Restart restarts the Unbounded daemon synchronously.

func (*HostDaemonActivationService) WaitHealthy added in v0.2.3

func (s *HostDaemonActivationService) WaitHealthy(ctx context.Context, expectedBinaryPath string) error

WaitHealthy waits until systemd reports a stable daemon process executing the expected binary target.

type ModeOperator added in v0.23.0

type ModeOperator interface {
	// EnsureLifecycleMigration installs lifecycle hooks for the active node
	// without restarting its currently running services.
	EnsureLifecycleMigration(context.Context, *slog.Logger, *ActiveMachine) error
	// RestartNode restarts the active node stack in place. It never restarts
	// the host.
	RestartNode(context.Context, *slog.Logger, *ActiveMachine) error
	// RepaveNode replaces the active node with one built from the desired
	// configuration. The caller triggers it only after the Kubernetes Node has
	// been cordoned, drained and deleted; it does not perform Kubernetes
	// eviction or CNI-specific dataplane cleanup itself.
	RepaveNode(context.Context, *slog.Logger, *ActiveMachine, *provision.UnboundedAgentConfig) error
}

ModeOperator is the node operations one isolation mode implements. Every mode implements all of them itself: a mode's operator never embeds another mode's, so a method added here is a compile error in every mode that does not implement it rather than a silent fallback to another mode's behavior.

type ModeOperators added in v0.23.0

type ModeOperators map[isolation.Mode]ModeOperator

ModeOperators holds the operator of every isolation mode this agent can operate. The agent's mode composition table builds it.

type NSpawnOperator added in v0.23.0

type NSpawnOperator struct {
	// NewBackend builds the nspawn backend for a configuration. It is the
	// backend of the mode composition table's nspawn entry.
	NewBackend BackendFactory
}

NSpawnOperator is the ModeOperator of the nspawn mode.

func NewNSpawnOperator added in v0.23.0

func NewNSpawnOperator(newBackend BackendFactory) NSpawnOperator

NewNSpawnOperator returns the nspawn ModeOperator, whose node restarts run through the backend newBackend builds.

func (NSpawnOperator) EnsureLifecycleMigration added in v0.23.0

func (NSpawnOperator) EnsureLifecycleMigration(ctx context.Context, log *slog.Logger, active *ActiveMachine) error

func (NSpawnOperator) RepaveNode added in v0.23.0

func (NSpawnOperator) RepaveNode(
	ctx context.Context,
	log *slog.Logger,
	active *ActiveMachine,
	newCfg *provision.UnboundedAgentConfig,
) error

RepaveNode performs the nspawn machine update:

  1. Provision a new rootfs on the alternate machine
  2. Stop the old machine (graceful service shutdown + nspawn teardown)
  3. Start the new machine (configure, boot nspawn, start services, persist config)
  4. Verify kubelet health
  5. Remove the old machine and its applied config

func (NSpawnOperator) RestartNode added in v0.23.0

func (op NSpawnOperator) RestartNode(ctx context.Context, log *slog.Logger, active *ActiveMachine) error

Jump to

Keyboard shortcuts

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