agentupdate

package
v1.5.9 Latest Latest
Warning

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

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

Documentation

Overview

Package agentupdate replaces the running agent binary with a verified release, keeps the previous one as .prev and can swap it back.

Index

Constants

View Source
const (
	ActionNone      = "none"
	ActionAvailable = "available"
	ActionStaged    = "staged"
	ActionRestarted = "restarted"
	ActionRolled    = "rolled-back"
	ActionHold      = "hold"
)

Outcomes reported in Result.Action.

View Source
const PackageManagedHelp = "" /* 226-byte string literal not displayed */

PackageManagedHelp is the next step printed when a package manager owns the agent.

Variables

View Source
var ErrBusy = errors.New("another agent update or rollback is already running")

ErrBusy means another install or rollback holds the lock.

View Source
var ErrNoServiceManager = errors.New("no service manager found to restart the agent")

ErrNoServiceManager means no supported service manager owns this agent.

View Source
var ErrPackageManaged = errors.New("the agent binary is managed by a package manager; update it with that package manager instead")

ErrPackageManaged means a package manager owns the agent binary, so an in-place replace would be overwritten or fight the package database.

Functions

func ClearMarker

func ClearMarker(dir string)

ClearMarker removes the marker; a missing file is fine.

func DefaultServiceName

func DefaultServiceName(goos string) string

DefaultServiceName is the service label the packaged installers register.

func ForceCommand

func ForceCommand(target string) string

ForceCommand is the one-line retry for a target the agent did not apply.

func Install

func Install(ctx context.Context, o Options, target string) (string, error)

Install downloads target, verifies checksum and signature (never skipped), keeps the current binary as .prev and swaps the new one in atomically.

func IsReleaseTarget

func IsReleaseTarget(v string) bool

IsReleaseTarget reports whether v is a published release tag such as v1.2.3, as opposed to dev or main-<sha> builds.

func PackageManaged

func PackageManaged(exe, dataDir string) bool

PackageManaged reports whether exe is installed by a package manager: by location, by an install-source marker reading "package", or by dpkg or rpm.

func PrevPath

func PrevPath(exe string) string

PrevPath is where the replaced binary is kept.

func WriteFailed

func WriteFailed(dir string, f Failed) error

WriteFailed records a failed target.

func WriteMarker

func WriteMarker(dir string, m Marker) error

WriteMarker stores the marker.

Types

type Decider

type Decider func(ctx context.Context) (nodeinsight.UpdateDecision, error)

Decider answers what the control plane wants this node to run.

type Failed

type Failed struct {
	Target string    `json:"target"`
	At     time.Time `json:"at"`
	Reason string    `json:"reason"`
}

Failed remembers a target that did not work, so it is not retried in a loop.

func ReadFailed

func ReadFailed(dir string) (Failed, bool)

ReadFailed returns the last failed target, or false.

type Marker

type Marker struct {
	From        string    `json:"from"`
	To          string    `json:"to"`
	InstalledAt time.Time `json:"installed_at"`
}

Marker records one install so a rollback is only ever judged against the version that was just installed, never against an older, healthy one.

func ReadMarker

func ReadMarker(dir string) (Marker, bool)

ReadMarker returns the pending install marker, or false when there is none.

func (Marker) InProbation

func (m Marker) InProbation(running string, window time.Duration, now time.Time) bool

InProbation reports whether the marker still guards a rollback decision for the running version.

type Options

type Options struct {
	Decide  Decider
	Release Release
	Service Service
	// Asset is the release asset for this OS and arch.
	Asset   string
	Current string
	// DataDir holds the install marker and the failed-target record.
	DataDir string
	ExePath string
	// Apply installs and restarts now; Check only reports. With neither the
	// update is installed only when the control plane says AutoApply.
	Apply bool
	Check bool
	// Smoke runs the staged binary and returns its version; required to install.
	Smoke func(ctx context.Context, path string) (string, error)
	// ForceTarget installs this release instead of the control plane answer. It
	// still goes through the signed download, version check and rollback.
	ForceTarget string
}

Options configures one run.

type Release

type Release interface {
	Fetch(ctx context.Context, tag, asset, dir string) (selfupgrade.Fetched, error)
	Verify(ctx context.Context, checksumsPath, bundlePath string) (string, error)
}

Release fetches and verifies one release. The real implementation wraps selfupgrade.Fetcher and selfupgrade.Signer in require mode.

type Result

type Result struct {
	Action   string `json:"action"`
	Current  string `json:"current"`
	Target   string `json:"target,omitempty"`
	Reason   string `json:"reason,omitempty"`
	Previous string `json:"previous,omitempty"`
	Detail   string `json:"verification,omitempty"`
}

Result describes what a run did.

func Rollback

func Rollback(ctx context.Context, exe, dataDir string, svc Service) (Result, error)

Rollback puts the .prev binary back and restarts. The failed binary is kept as .failed, and the target is remembered so it is not retried in a loop.

func Run

func Run(ctx context.Context, o Options) (Result, error)

Run asks for the target and, when allowed, installs it.

type Service

type Service interface {
	Restart(ctx context.Context) error
}

Service restarts the agent through its service manager.

type SystemService

type SystemService struct {
	Name string
	// Domain is the launchd domain target (gui/501 or system); empty derives
	// it from where the unit is installed.
	Domain string
	// GOOS is overridable for tests.
	GOOS string
	Run  func(ctx context.Context, argv []string) error
}

SystemService restarts the agent through the host service manager, with a fixed argv and no shell.

func (SystemService) Argv

func (s SystemService) Argv() ([]string, error)

Argv returns the restart command for the service manager of goos.

func (SystemService) Restart

func (s SystemService) Restart(ctx context.Context) error

Restart runs the restart command.

Jump to

Keyboard shortcuts

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