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
- Variables
- func ClearMarker(dir string)
- func DefaultServiceName(goos string) string
- func ForceCommand(target string) string
- func Install(ctx context.Context, o Options, target string) (string, error)
- func IsReleaseTarget(v string) bool
- func PackageManaged(exe, dataDir string) bool
- func PrevPath(exe string) string
- func WriteFailed(dir string, f Failed) error
- func WriteMarker(dir string, m Marker) error
- type Decider
- type Failed
- type Marker
- type Options
- type Release
- type Result
- type Service
- type SystemService
Constants ¶
const ( ActionNone = "none" ActionAvailable = "available" ActionStaged = "staged" ActionRestarted = "restarted" ActionRolled = "rolled-back" ActionHold = "hold" )
Outcomes reported in Result.Action.
const PackageManagedHelp = "" /* 226-byte string literal not displayed */
PackageManagedHelp is the next step printed when a package manager owns the agent.
Variables ¶
var ErrBusy = errors.New("another agent update or rollback is already running")
ErrBusy means another install or rollback holds the lock.
var ErrNoServiceManager = errors.New("no service manager found to restart the agent")
ErrNoServiceManager means no supported service manager owns this agent.
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 ¶
DefaultServiceName is the service label the packaged installers register.
func ForceCommand ¶
ForceCommand is the one-line retry for a target the agent did not apply.
func Install ¶
Install downloads target, verifies checksum and signature (never skipped), keeps the current binary as .prev and swaps the new one in atomically.
func IsReleaseTarget ¶
IsReleaseTarget reports whether v is a published release tag such as v1.2.3, as opposed to dev or main-<sha> builds.
func PackageManaged ¶
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 WriteFailed ¶
WriteFailed records a failed target.
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 ¶
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 ¶
ReadMarker returns the pending install marker, or false when there is none.
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.
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.