agentdeployment

package
v0.4.0-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

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

	// SystemdSystemDir is not under the host root. Units must live where
	// systemd looks for them, and /etc is writable even when /usr is not.
	SystemdSystemDir = "/etc/systemd/system"

	// 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 (
	UpgradeDownloadURLParameter = "downloadURL"
	UpgradeSHA256Parameter      = "sha256"
)
View Source
const ContainerizedEnv = "AKS_FLEX_NODE_CONTAINERIZED"

ContainerizedEnv marks the agent as running in its container image.

View Source
const (
	HostAgentHealthTimeout = 30 * time.Second
)
View Source
const (

	// ManagedBinaryDir holds the agent's blue/green binaries and recovery script.
	ManagedBinaryDir = "lib/aks-flex-node"
)

Variables

View Source
var ErrDirectActivationInContainer = errors.New("direct activation is not available in the agent's container; " +
	"upgrade it with an AgentUpgrade that names an image")

ErrDirectActivationInContainer refuses binary activation in an image deployment.

Functions

func Containerized

func Containerized() bool

Containerized reports whether the agent runs in its container image.

func CredentialPlugin

func CredentialPlugin() (string, error)

CredentialPlugin is the agent binary used by its Kubernetes clients when managed identity or a service principal supplies bootstrap credentials.

func EnsureAgentUpgradeServiceAssets

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

func EnsureDaemonServiceAssets

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

EnsureDaemonServiceAssets converges the service assets as the daemon starts, as EnsureAgentUpgradeServiceAssets does, except while an AgentUpgrade's signal exists. Then the daemon may be the upgrade's candidate, not yet judged, or recovery is under way, and the assets on disk are the last-good version's: recovery, and the restart into the last-good binary, run through them, so a candidate's broken assets would break its own rollback. It keeps them, writing only missing ones, and reports that it held them back, for the daemon to converge them once the upgrade is judged.

func EnsureNSpawnLifecycleUnits

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 GuardActivationLegacySeed

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

GuardActivationLegacySeed also keeps a seed used by the running service.

func HostAgentActivationOptions

func HostAgentActivationOptions(paths UpgradePaths, candidatePath string) agentbinary.ActivationOptions

func HostRootMarkers

func HostRootMarkers() []string

HostRootMarkers identifies the blue/green binary layout installed by releases before the host root. The plain binary and SDK helpers can exist on fresh or reset hosts, so they do not establish that an installation exists.

func HostRootMoveUnfinishedHere

func HostRootMoveUnfinishedHere() (bool, error)

HostRootMoveUnfinishedHere is hostRootMoveUnfinished for this host's root.

func InstallHostBinary

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. In the agent's container, the unit runs the agent's image instead of a binary on the host.

func MigrateHostRoot

func MigrateHostRoot(log *slog.Logger) error

MigrateHostRoot links the host root to the legacy root for older installs. Resolving paths through that link keeps existing unit and binary paths valid.

func NewHostActivationService

func NewHostActivationService(log *slog.Logger, root string, resolveRoot func() string) (*HostActivationService, UpgradePaths)

func PlannedHostRoot

func PlannedHostRoot() string

PlannedHostRoot reports the root that will be resolved after migration.

func PreflightChecks

func PreflightChecks(checks []preflight.Checker) []preflight.Checker

PreflightChecks omits host checks that do not apply in the agent container.

func PrepareHostRoot

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

PrepareHostRoot creates the directories used by the agent installation.

func RecoverAgentUpgrade

func RecoverAgentUpgrade(ctx context.Context, log *slog.Logger, message string, mode isolation.Mode, helperPaths map[string]string) error

RecoverAgentUpgrade records failure and restores both host and active worker binaries. It is invoked by the systemd recovery unit through last-good. In the agent's container, it restores the last-good image and restarts the agent's unit, which the recovery script does on a host.

On a host 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 RecoveryScriptPathUnder

func RecoveryScriptPathUnder(root string) string

RecoveryScriptPathUnder returns where the recovery script is installed under a resolved host root.

func RemoveDaemonLegacySeed

func RemoveDaemonLegacySeed(log *slog.Logger) error

RemoveDaemonLegacySeed is RemoveLegacySeed for the daemon, which keeps the binary while it runs from it.

On a host a release before the blue/green layout installed directly in /usr/local/bin, the unit runs the daemon from that binary. Once this release has copied it under the host root and rewritten the units, it is no longer needed, but the running daemon's os.Executable still names it, and nothing restarts the daemon. Removed, every later copy of the running binary, such as the one a repave installs in the machine, fails until the daemon restarts. The next start runs from the host root, and removes it then.

func RemoveIfPresent

func RemoveIfPresent(path string) error

RemoveIfPresent removes a file and treats its absence as success.

It checks first. On a read-only filesystem, such as /usr on Azure Container Linux, unlinking a path that does not exist returns EROFS rather than ENOENT, so the sweep of the legacy root would otherwise fail reset on a file that was never there. Lstat so a dangling symlink still counts as present.

func RemoveLegacySeed

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 SyncDirs

func SyncDirs(dirs ...string) error

SyncDirs makes the entries in each directory durable: the files renamed into it or removed from it. Each directory is synced once.

func SynchronizeAgentBinary

func SynchronizeAgentBinary(sourcePath, destination string) error

SynchronizeAgentBinary installs the credential helper at a runtime-resolved destination.

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.

In the agent's container, the unit of that name is the install's bootstrap unit, which runs bootstrap in a container of the image. It stays, as the rest of the install does, so starting it with new inputs joins the node again.

The paths are resolved when the task is built. Worker reset does not change the host root and resolves its helper paths the same way.

func UpgradeCleanupContext

func UpgradeCleanupContext(ctx context.Context) (context.Context, context.CancelFunc)

func UpgradeDigest

func UpgradeDigest(sha256Parameter string) (string, error)

UpgradeDigest returns an AgentUpgrade's SHA-256 in lower-case hex, without the optional "sha256:" prefix.

func VerifyMovedAgent

func VerifyMovedAgent(ctx context.Context, root string) error

VerifyMovedAgent runs the current agent binary from a copy of the layout under root, before any unit names it. A move whose copy fails this is undone, and the host stays linked to /usr/local.

Types

type ContainerConvergence

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

ContainerConvergence keeps the host in step with the image the agent runs in, as the daemon on a host keeps its binary layout and units converged at every start: the agent's unit and its recovery unit, which a newer image can change, and the agent's binary in the active machine, which kubelet runs as its credential plugin and which an upgrade or rollback changes. It also removes the agent's images that it won't run again.

func NewContainerConvergence

func NewContainerConvergence(log *slog.Logger) *ContainerConvergence

func (*ContainerConvergence) Converge

func (c *ContainerConvergence) Converge(ctx context.Context) (bool, error)

Converge updates the image's units and removes old upgrade images. While an upgrade is pending it retains last-good units, reporting that they were held so the daemon can update them after judgment.

func (*ContainerConvergence) SyncActiveWorker

func (c *ContainerConvergence) SyncActiveWorker(machine string) error

SyncActiveWorker copies the running agent into the resolved active worker, if present.

func (*ContainerConvergence) WriteUnits

func (c *ContainerConvergence) WriteUnits(ctx context.Context) error

WriteUnits updates the units held back until the upgrade was judged.

type ContainerUpgrade

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

func NewContainerUpgrade

func NewContainerUpgrade(log *slog.Logger) *ContainerUpgrade

func (*ContainerUpgrade) Abort

func (e *ContainerUpgrade) Abort(ctx context.Context) error

func (*ContainerUpgrade) Acquire

func (e *ContainerUpgrade) Acquire() (io.Closer, error)

func (*ContainerUpgrade) CandidateActive

func (e *ContainerUpgrade) CandidateActive(signal *UpgradeSignal) (bool, error)

func (*ContainerUpgrade) RecordFailure

func (e *ContainerUpgrade) RecordFailure(message string) error

func (*ContainerUpgrade) Restart

func (e *ContainerUpgrade) Restart(ctx context.Context) error

Restart resets the unit's start limit first, and restarts it, as on a host.

func (*ContainerUpgrade) RetryRecovery

func (e *ContainerUpgrade) RetryRecovery(ctx context.Context) (RecoveryRetryResult, error)

func (*ContainerUpgrade) RollbackSwitch

func (e *ContainerUpgrade) RollbackSwitch(signal *UpgradeSignal) error

func (*ContainerUpgrade) RunningLastGood

func (e *ContainerUpgrade) RunningLastGood(signal *UpgradeSignal) (bool, error)

func (*ContainerUpgrade) SignalStore

func (e *ContainerUpgrade) SignalStore() UpgradeSignalStore

func (*ContainerUpgrade) Stage

func (e *ContainerUpgrade) Stage(ctx context.Context, request UpgradeRequest) error

func (*ContainerUpgrade) Validate

func (e *ContainerUpgrade) Validate(request UpgradeRequest) error

func (*ContainerUpgrade) ValidateStarted

func (e *ContainerUpgrade) ValidateStarted(signal *UpgradeSignal) error

type HostActivationService

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

func (*HostActivationService) Preflight

func (s *HostActivationService) Preflight(ctx context.Context, currentBinaryPath string, targets ServiceTargets) (agentbinary.ServicePlan, error)

Preflight checks the service before an activation switches anything. In an activation it runs under the activation lock.

The layout was built from the host root before the lock was held. A daemon that moves the host from /usr/local to the host root holds the same lock, and may have moved it in between. An activation that went ahead would stage the candidate under /usr/local and point the units back there, and the move, whose copy still names the previous binary, would then point them at its copy and remove /usr/local, leaving the host on the previous binary. Checking here, under the lock, refuses it instead; a retry builds the layout from the root as it is now.

A move whose first pass renamed its copy into place just before the layout was built leaves the root unchanged, but has not finished, so it is checked here too, as guardLegacySeed checks it before the lock is held.

func (*HostActivationService) Prepare

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

func (*HostActivationService) Reload

func (s *HostActivationService) Reload(ctx context.Context) error

func (*HostActivationService) Restart

func (s *HostActivationService) Restart(ctx context.Context) error

func (*HostActivationService) WaitHealthyForBinary

func (s *HostActivationService) WaitHealthyForBinary(ctx context.Context, expectedBinaryPath string) (string, error)

WaitHealthyForBinary preserves an inactive service or waits for the expected binary to run stably. The caller synchronizes the worker after this succeeds.

type HostUpgrade

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

func NewHostUpgrade

func NewHostUpgrade(log *slog.Logger, mode isolation.Mode, helperPaths map[string]string) *HostUpgrade

func (*HostUpgrade) Abort

func (e *HostUpgrade) Abort(ctx context.Context) error

func (*HostUpgrade) Acquire

func (e *HostUpgrade) Acquire() (io.Closer, error)

func (*HostUpgrade) CandidateActive

func (e *HostUpgrade) CandidateActive(signal *UpgradeSignal) (bool, error)

func (*HostUpgrade) Paths

func (e *HostUpgrade) Paths() UpgradePaths

Paths is the layout resolved when this process constructed the executor.

func (*HostUpgrade) RecordFailure

func (e *HostUpgrade) RecordFailure(message string) error

func (*HostUpgrade) Restart

func (e *HostUpgrade) Restart(ctx context.Context) error

func (*HostUpgrade) RetryRecovery

func (e *HostUpgrade) RetryRecovery(ctx context.Context) (RecoveryRetryResult, error)

func (*HostUpgrade) RollbackSwitch

func (e *HostUpgrade) RollbackSwitch(signal *UpgradeSignal) error

func (*HostUpgrade) RunningLastGood

func (e *HostUpgrade) RunningLastGood(*UpgradeSignal) (bool, error)

func (*HostUpgrade) SignalStore

func (e *HostUpgrade) SignalStore() UpgradeSignalStore

func (*HostUpgrade) Stage

func (e *HostUpgrade) Stage(ctx context.Context, request UpgradeRequest) error

func (*HostUpgrade) Validate

func (e *HostUpgrade) Validate(request UpgradeRequest) error

Validate takes an archive's HTTP or HTTPS URL, and refuses an image's, as any other URL.

func (*HostUpgrade) ValidateStarted

func (e *HostUpgrade) ValidateStarted(signal *UpgradeSignal) error

type RecoveryRetryResult

type RecoveryRetryResult struct {
	RestartScheduled bool
}

RecoveryRetryResult reports whether upgrade recovery scheduled a daemon restart.

type ServiceTargets

type ServiceTargets struct {
	AfterTargets []string
	WantsTargets []string
}

ServiceTargets contains the complete dependency lists for the host agent unit.

func ServiceTargetsFromConfig

func ServiceTargetsFromConfig(cfg *config.Config, mode isolation.Mode) ServiceTargets

ServiceTargetsFromConfig selects dependencies using the effective worker mode, which may come from applied state rather than the desired bootstrap config.

type UpgradeExecutor

type UpgradeExecutor interface {
	Acquire() (io.Closer, error)
	Validate(UpgradeRequest) error
	RetryRecovery(context.Context) (RecoveryRetryResult, error)
	RecordFailure(string) error
	Stage(context.Context, UpgradeRequest) error
	Abort(context.Context) error
	Restart(context.Context) error
	SignalStore() UpgradeSignalStore
	ValidateStarted(*UpgradeSignal) error
	CandidateActive(*UpgradeSignal) (bool, error)
	RollbackSwitch(*UpgradeSignal) error
	RunningLastGood(*UpgradeSignal) (bool, error)
}

UpgradeExecutor performs deployment mechanics; daemon owns state and result publication.

type UpgradePaths

type UpgradePaths struct {
	BinaryPath   string
	BluePath     string
	GreenPath    string
	CurrentPath  string
	LastGoodPath string
	SignalPath   string
}

func DefaultUpgradePaths

func DefaultUpgradePaths() UpgradePaths

DefaultUpgradePaths returns the host-side agent upgrade layout under the resolved host root. Callers that change the host migrate it first; see MigrateHostRoot.

func UpgradePathsUnder

func UpgradePathsUnder(root string) UpgradePaths

UpgradePathsUnder builds the upgrade layout under a resolved host root.

SignalPath is under /etc rather than the root. It is state about an upgrade rather than part of the installed layout, and has to survive a rollback to a binary that predates the host root.

func (UpgradePaths) Layout

func (p UpgradePaths) Layout() agentbinary.Layout

type UpgradeRequest

type UpgradeRequest struct {
	DownloadURL string
	SHA256      string
}

UpgradeRequest contains resolved, validated agent upgrade inputs.

type UpgradeSignal

type UpgradeSignal struct {
	OperationName            string `json:"operationName"`
	ActiveMachine            string `json:"activeMachine,omitempty"`
	CandidatePath            string `json:"candidatePath,omitempty"`
	InitiatingDaemonInstance string `json:"initiatingDaemonInstance,omitempty"`
	SwitchCommitted          bool   `json:"switchCommitted,omitempty"`
	RecoveryRequired         bool   `json:"recoveryRequired,omitempty"`
	Failure                  string `json:"failure,omitempty"`
	// In the agent's container, the image an upgrade switches to and the one it switches from.
	CandidateImage string `json:"candidateImage,omitempty"`
	PreviousImage  string `json:"previousImage,omitempty"`
}

UpgradeSignal records the durable handoff between the initiating and restarted agents.

type UpgradeSignalStore

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

UpgradeSignalStore persists an agent upgrade's recovery signal.

func NewUpgradeSignalStore

func NewUpgradeSignalStore(path string) UpgradeSignalStore

NewUpgradeSignalStore uses path for the existing JSON signal format.

func (UpgradeSignalStore) Clear

func (s UpgradeSignalStore) Clear() error

func (UpgradeSignalStore) Read

func (s UpgradeSignalStore) Read() (*UpgradeSignal, error)

func (UpgradeSignalStore) RecordFailure

func (s UpgradeSignalStore) RecordFailure(message string) error

func (UpgradeSignalStore) RecordPending

func (s UpgradeSignalStore) RecordPending(operationName, activeMachine, daemonInstance string) error

func (UpgradeSignalStore) Write

func (s UpgradeSignalStore) Write(signal UpgradeSignal) error

Jump to

Keyboard shortcuts

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