daemon

package
v0.2.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 65 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceUnitName = "aks-flex-node-agent.service"

	// ServiceUnitPath is where the agent unit is installed. The first-boot unit
	// only runs while it is absent.
	ServiceUnitPath = systemdSystemDir + "/" + ServiceUnitName
	// FirstBootUnitName is the oneshot unit that runs bootstrap.sh on first
	// boot on a host provisioned by Ignition, as scripts/aks-flex-node-bootstrap.bu
	// documents. Reset removes it; a host without it is left alone.
	FirstBootUnitName = "aks-flex-node-bootstrap.service"
)
View Source
const (
	DeletionTaintKey    = "kubernetes.azure.com/flex-node-deleting"
	DeletionTaintValue  = "true"
	DeletionTaintEffect = corev1.TaintEffectNoSchedule
)
View Source
const DefaultMachineReconcileInterval = 10 * time.Minute

Variables

This section is empty.

Functions

func ActivateHostAgent added in v0.1.7

func ActivateHostAgent(ctx context.Context, log *slog.Logger, candidatePath string) (agentbinary.ActivationResult, error)

ActivateHostAgent activates a directly staged Flex agent binary. It uses the same lock and binary layout as MachineOperation upgrades.

func ConfigureNSpawnDependencies added in v0.1.9

func ConfigureNSpawnDependencies(log *slog.Logger, rootFS *goalstates.RootFS, requiredServices []string) phases.Task

ConfigureNSpawnDependencies orders the machine after host services that must finish changing host devices before nspawn starts.

func EnsureNSpawnLifecycleUnits added in v0.3.0

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

EnsureNSpawnLifecycleUnits returns a task that writes the nspawn lifecycle units the machines' hooks start, those that are missing, so that StartNode can start a machine: start installs the agent's other units only once the node runs. The daemon converges them with those units, while an AgentUpgrade isn't pending, so this leaves the existing ones as they are. It links the lifecycle helper too, for hooks an earlier release's pre-start writes, as after a reset that kept that release's binaries; see ensureNSpawnLifecycleHelperLink.

func HostRootMarkers added in v0.3.0

func HostRootMarkers() []string

HostRootMarkers returns the files, relative to the host root, whose presence under the legacy root identifies an installation by a release before the host root. They are the blue/green binary layout only. The plain binary is left out: install scripts put it in /usr/local/bin on fresh hosts too, so on its own it is not an installation. Neither are the files the agent library installs, such as the nspawn lifecycle helper, which an older reset can leave behind.

func InstallBinary

func InstallBinary(machineDir string) phases.Task

InstallBinary returns a task that copies the current process binary into the nspawn rootfs at /usr/local/bin/aks-flex-node.

func InstallHostBinary added in v0.3.0

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

InstallHostBinary puts the binary under the host root, <host root>/bin/aks-flex-node, which the agent's blue/green layout is seeded from:

  • While the agent's unit is installed, as for the daemon, the binary changes only through an activation, so it is copied only when no usable binary is there, as on a host an earlier release installed directly in /usr/local/bin.
  • Otherwise, as for start before it installs the agent, it is the running binary. One there that isn't, such as the one a reset left, is replaced with a copy of it, and a layout that doesn't run it, such as one a reset by an earlier release kept, is removed, so the layout start seeds runs the binary doing the start.

It fails, and leaves no copy, when the copy cannot run.

func InstallService

func InstallService(cfg *config.Config, log *slog.Logger) phases.Task

InstallService returns a task that installs, enables, and starts the systemd unit.

func MigrateHostRoot added in v0.3.0

func MigrateHostRoot(log *slog.Logger) error

MigrateHostRoot links the host root to the legacy root on a host installed by a release before the host root. Commands that change the host call it before they resolve any path.

func NewFileStateStore

func NewFileStateStore() (stateStore, error)

func PlannedHostRoot added in v0.3.0

func PlannedHostRoot() string

PlannedHostRoot returns the host root this host will resolve once migrated, without migrating it. It is for code that must not change the host.

func PreflightHostAgentActivation added in v0.1.7

func PreflightHostAgentActivation(ctx context.Context, log *slog.Logger, candidatePath string) (agentbinary.ActivationPlan, error)

PreflightHostAgentActivation validates a directly staged Flex agent binary and returns the shared activation plan without changing host state.

It does not migrate the host root, so it plans against the root the host will resolve once migrated.

func PrepareHostRoot added in v0.3.0

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

PrepareHostRoot creates the directories under the host root that the node installs into.

func RecoverAgentUpgrade added in v0.1.7

func RecoverAgentUpgrade(ctx context.Context, message string) error

RecoverAgentUpgrade records failure and restores both host and active nspawn binaries. It is invoked by the systemd recovery unit through last-good.

It recovers whatever the host root, since recovery is what brings a failed upgrade back. A host root that cannot be migrated is logged and left as it is, and the layout is the one this binary runs from: the recovery script runs the resolved last-good link, so that is the layout systemd uses.

func RemoveLegacySeed added in v0.3.0

func RemoveLegacySeed(log *slog.Logger) error

RemoveLegacySeed removes the binary install scripts left in /usr/local/bin once nothing the agent runs is under /usr/local: the host is installed under a real host root, or one an operator linked somewhere else. Only a regular file is removed: a link there is an earlier release's compatibility link, or an operator's.

Not partway through a move from /usr/local: until the move has restarted the daemon from the host root, the daemon may still be running from the files under /usr/local, and the move removes none of them until then.

It is for start, which runs from that binary on a host whose /usr/local/bin is writable, and removes it as its last step, once it has copied itself everywhere it is needed and is about to exit. The daemon keeps it while it runs from it; see removeDaemonLegacySeed.

func ResetNode

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

ResetNode returns the task that removes the node runtime from the host.

Helpers the agent library installs under the host root, the nspawn lifecycle helper and the LocalDNS network helper, are removed under the resolved host root and under the legacy root, so reset does not depend on the host root having been migrated. The managed agent binaries are intentionally kept.

func Run

func Run(ctx context.Context, cfg *config.Config, log *slog.Logger) error

Run starts the machine-driven daemon loop.

func SetupHost

func SetupHost(cfg *config.Config, log *slog.Logger) phases.Task

func StartNode

func StartNode(
	cfg *config.Config,
	log *slog.Logger,
	machineName string,
	gs *goalstates.MachineGoalState,
	containerImageArchives *goalstates.ContainerImageArchiveStaging,
	store stateStore,
	state *State,
) phases.Task

func UninstallService

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

UninstallService returns a task that removes the first-boot unit, then disables, removes, and stops the agent's systemd unit, leaving the agent's binary under the host root as a regular file, without its blue/green layout.

The paths are resolved when the task is built. Nothing in reset changes the host root, and ResetNode resolves the helper paths it removes the same way.

Types

type State

type State struct {
	AppliedSettingsVersion    string `json:"appliedSettingsVersion,omitempty"`
	AppliedKubernetesVersion  string `json:"appliedKubernetesVersion,omitempty"`
	PreviousSettingsVersion   string `json:"previousSettingsVersion,omitempty"`
	PreviousKubernetesVersion string `json:"previousKubernetesVersion,omitempty"`
	ActiveMachine             string `json:"activeMachine,omitempty"`
}

State records the last safely applied AKS machine goal and the previous known-good goal needed for rollback-oriented reconciliation.

func SeededState

func SeededState(goal aksmachine.GoalState) *State

Jump to

Keyboard shortcuts

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