hostnode

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Overview

Package hostnode holds what the composition roots of the isolation modes that run the node stack outside a systemd-nspawn machine (none today) share: resolving a goal state, the LocalDNS network steps, the restart of services whose configuration changed, the saved copy of the shared configuration, the reset of the kubelet identity and the unmounting of pod volumes. The modes differ in where commands run and in how the node is built and started; they do not differ in these.

Index

Constants

View Source
const CNIStateDir = "/var/lib/cni"

CNIStateDir is where the CNI plugins keep per-node state, host-local IPAM's address reservations among it.

View Source
const KubeletClientPKIDir = "/var/lib/kubelet/pki"

KubeletClientPKIDir holds kubelet's rotated client certificates. It is not goalstates.KubeletPKIDir, which is the cluster CA directory.

View Source
const KubeletDir = "/var/lib/kubelet"

KubeletDir is the kubelet state directory. Pod volume mounts propagate to it.

Variables

This section is empty.

Functions

func Func

func Func(name string, do func(context.Context) error) phases.Task

Func adapts a function to a phases.Task named name. The name is what a failed task carries into the error and the Machine condition reason is classified from.

func Logger

func Logger(l *slog.Logger) *slog.Logger

Logger returns l, or the default logger when l is nil.

func OrDefault

func OrDefault(v, def string) string

OrDefault returns v, or def when v is empty. Teardowns use it for the directories their zero value leaves to the real host.

func ResetCNIState

func ResetCNIState(hostRoot string) error

ResetCNIState removes the CNI network configuration and the CNI state a stopped stack left below hostRoot, as a repave to a new nspawn machine starts without them. The configuration directory itself stays, empty.

A repave deletes the Node, and the new one can be given a different pod CIDR. Left in place, the old configuration makes containerd report the network ready at once and starts pods with addresses from the old range until the CNI's own pod rewrites it, and host-local IPAM keeps reservations for pods that were ended. Every file in the directory goes, those of add-ons included: they are written by DaemonSet pods that write them again when they start, and a repave to a new nspawn machine loses them all the same.

func ResetKubeletIdentity

func ResetKubeletIdentity(ns *goalstates.NodeStart) error

ResetKubeletIdentity removes the previous kubelet client credentials when the node authenticates with a bootstrap token, so the next start requests new ones. Direct kubeconfig and exec credential modes are rewritten by Configure.

func RestartChanged

func RestartChanged(ctx context.Context, log *slog.Logger, wasRunning bool, units []ChangedUnit, restart func(ctx context.Context, unit string) error, logAttrs ...any) error

RestartChanged restarts, in order, the units whose configuration changed. It does nothing when the node was not already running, since a start reads the configuration written before it. restart runs one unit's restart and owns the wording of its error; logAttrs are added to the log line for each restart.

func RestoreSnapshot

func RestoreSnapshot(log *slog.Logger, dir, hostRoot string) error

RestoreSnapshot restores a snapshot saved in dir by an earlier process, such as one a crash interrupted, and reloads systemd for the real root.

func Running

func Running(ctx context.Context, b isolation.Backend, root isolation.SlotRef) (bool, error)

Running reports whether the node root's stack is up.

func UnmountBelow

func UnmountBelow(ctx context.Context, log *slog.Logger, run none.Runner, mountInfo string, prefixes ...string) error

UnmountBelow lazily unmounts every mount at or below the given prefixes, deepest first. Pod volumes (tmpfs secrets, projected volumes) are mounted under /var/lib/kubelet and can outlive the node stack; they would make removing the directory fail or, worse, delete through a bind mount.

mountInfo is the mount table (empty means /proc/self/mountinfo) and run executes host commands (nil uses the real host).

func UnmountBelowByPrefix

func UnmountBelowByPrefix(ctx context.Context, log *slog.Logger, run none.Runner, mountInfo string, prefixes ...string) (map[string]error, error)

UnmountBelowByPrefix is UnmountBelow with the failures attributed to the prefix whose mounts could not be unmounted, in one deepest-first pass over all prefixes. Callers use it to keep the directories that still have mounts below them and to remove the rest. The error is for an unreadable mount table, in which case no prefix can be trusted.

func UnmountStrictlyBelow

func UnmountStrictlyBelow(ctx context.Context, log *slog.Logger, run none.Runner, mountInfo string, prefixes ...string) error

UnmountStrictlyBelow is UnmountBelow for the mounts strictly below the prefixes: a mount at a prefix itself is left in place. A container node uses it on /var/lib/kubelet before a slot starts, to clear the pod volumes the previous slot left there without detaching the directory's own mount (the shared bind its unit makes, or a dedicated disk), which the next slot's pod mounts propagate through.

Types

type ChangedUnit

type ChangedUnit struct {
	Unit    string
	Changed bool
}

ChangedUnit is a service and whether its configuration changed.

type GoalStateSource

type GoalStateSource struct {
	Log *slog.Logger
	// Config is the agent configuration goal states are resolved from.
	Config *config.AgentConfig
	// Downloads optionally overrides artifact download sources.
	Downloads *goalstates.DownloadOverrides
	// GoalState, when set, is used instead of resolving one. Bootstrap passes the
	// goal state it has already resolved so GPU and device discovery happens once.
	GoalState *goalstates.MachineGoalState
	// Resolve overrides goal state resolution. Tests use it; the default is
	// goalstates.ResolveMachine.
	Resolve func(slot string) (*goalstates.MachineGoalState, error)
}

GoalStateSource resolves the goal state a node is built from.

func (GoalStateSource) For

For returns the goal state for slot.

type Hooks

type Hooks struct {
	// Resolve overrides goal state resolution. The default is
	// goalstates.ResolveMachine.
	Resolve func(slot string) (*goalstates.MachineGoalState, error)
	// HostRoot prefixes the same-path host locations (/etc, /var/lib, /opt/cni)
	// the node writes. Empty is the real host.
	HostRoot string
	// ConfigSnapshotDir is where Upgrade saves the shared configuration so a
	// rollback can restore it. Empty means a directory in the agent configuration
	// directory below HostRoot.
	ConfigSnapshotDir string
	// SetupNetwork and CleanupNetwork replace the shared LocalDNS network
	// phases, and WaitLocalDNS the LocalDNS readiness wait. WaitLocalDNS is
	// given the node start goal state whose listeners are waited on.
	SetupNetwork   func(ctx context.Context) error
	CleanupNetwork func(ctx context.Context) error
	WaitLocalDNS   func(ctx context.Context, ns *goalstates.NodeStart) error
}

Hooks are the seams a node exposes so tests can run it against a temporary tree and a fake host. Production leaves the zero value, which is the real host and the real phases.

func (Hooks) AwaitLocalDNS

func (h Hooks) AwaitLocalDNS(ctx context.Context, log *slog.Logger, ns *goalstates.NodeStart) error

AwaitLocalDNS waits for LocalDNS to answer.

func (Hooks) CleanupHostNetwork

func (h Hooks) CleanupHostNetwork(ctx context.Context, log *slog.Logger) error

CleanupHostNetwork removes host networking the stopped node left behind, as a repave does.

func (Hooks) SetupLocalDNSNetwork

func (h Hooks) SetupLocalDNSNetwork(ctx context.Context, log *slog.Logger, ns *goalstates.NodeStart) error

SetupLocalDNSNetwork prepares the shared LocalDNS network.

func (Hooks) SnapshotDir

func (h Hooks) SnapshotDir(name string) string

SnapshotDir is where an upgrade saves the shared configuration: the override when set, otherwise name in the agent configuration directory below HostRoot.

type Snapshot

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

Snapshot is the saved copy of the configuration files both stacks of a node share, taken before an upgrade rewrites them so a rollback can put them back (see confsnap).

func TakeSnapshot

func TakeSnapshot(log *slog.Logger, dir, hostRoot string) (*Snapshot, error)

TakeSnapshot saves the shared configuration files below hostRoot into dir.

func TakeSnapshotOf

func TakeSnapshotOf(log *slog.Logger, dir, hostRoot string, paths []string) (*Snapshot, error)

TakeSnapshotOf is TakeSnapshot of the given paths, for a mode whose node stack writes more of the host in place (see confsnap.PathsFor).

func (*Snapshot) Discard

func (s *Snapshot) Discard()

Discard removes the saved copy. A failure is logged, not returned: the configuration is already in its final state.

func (*Snapshot) Restore

func (s *Snapshot) Restore() error

Restore puts the saved files back and, on the real root, has systemd read the restored unit definitions. A failure keeps the snapshot so it can be tried again.

func (*Snapshot) Restored

func (s *Snapshot) Restored() bool

Restored reports whether Restore has succeeded.

Directories

Path Synopsis
Package hostnodetest holds the fixtures the tests of the none and container compositions share.
Package hostnodetest holds the fixtures the tests of the none and container compositions share.

Jump to

Keyboard shortcuts

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