update

package
v0.175.0-rc.521 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: 27 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package update replaces the running beekeeper with the latest signed release.

Index

Constants

View Source
const (
	CanaryStatusSuccess = "success"
	CanaryStatusFailed  = "failed"
	CanaryStatusPending = "pending"
	RecordedRunPrefix   = "recorded:"
)

CanaryEvidence status values and run prefixes.

View Source
const (
	// ProbationWindow is how long a watched candidate is observed. A failure
	// restores the recovery target at once, so a broken release is gone within it.
	ProbationWindow = 30 * time.Minute
	// HeartbeatGrace is how long a candidate's loop may stay silent before the
	// silence counts as a failure. It counts from its last heartbeat, or its
	// start before the first heartbeat; handover to a candidate can come late.
	HeartbeatGrace = 10 * time.Minute
	// ProbeFailures is how many consecutive failed probes fail a candidate.
	ProbeFailures = 3
)
View Source
const (
	Wait     = "wait"
	Promote  = "promote"
	RollBack = "rollback"
)

Verdicts of Decide.

View Source
const MissingHeartbeatReason = "no health heartbeat from the candidate's loop"

MissingHeartbeatReason identifies the rollback whose evidence must be re-read immediately before changing the installed binary.

View Source
const Repository = "giantswarm/beekeeper"

Repository is the GitHub repository whose releases carry the binaries: beekeeper-<os>-<arch> (beekeeper-windows-<arch>.exe), each next to its cosign Sigstore bundle (<asset>.bundle), which the download is verified against before anything is written.

Variables

View Source
var ErrHealthUnproven = errors.New("candidate health is unproven")

ErrHealthUnproven leaves probation pending when live health evidence is unavailable. It neither promotes nor quarantines the installed candidate.

View Source
var ErrOutdated = errors.New("a newer beekeeper release is available")

ErrOutdated is what a check returns when a newer release exists.

View Source
var ErrProbationWatched = errors.New("a recovery controller supervises the installed candidate's probation")

ErrProbationWatched is an update asked for while a recovery controller supervises the installed candidate: its verdict comes first.

View Source
var ErrUpdateLocked = errors.New("update lock unavailable")

ErrUpdateLocked is an installation another updater holds.

Functions

func ClearHold

func ClearHold(ctx context.Context, path string) error

ClearHold lifts a failed recovery's hold once an operator has dealt with its cause. The quarantine stays: the failed candidate is never promoted. A recovery target that no longer verifies is dropped, or it would refuse every update after this one: the next install has none, as a first install has.

func CompleteProbation

func CompleteProbation(ctx context.Context, path, version string) error

CompleteProbation promotes only the running version after the caller has established health. Interrupted completion is safe to repeat.

func Decide

func Decide(o Observed, s Signals) (verdict, reason string)

Decide is a probation's verdict after o, given s.

func Digest

func Digest(path string) (string, error)

Digest is the SHA-256 of the file at path, as a journal records it.

func Observe

func Observe(ctx context.Context, path string, change func(*Journal) error) error

Observe lets change update the durable journal under the update lock, after reconciling an interrupted transaction. A nil journal is an error.

func Quarantine

func Quarantine(ctx context.Context, path, reason string) error

Quarantine records failed post-install health without changing the binary. It also applies at bootstrap, when there is no verified recovery target.

func Quarantined

func Quarantined(path, version string) string

Quarantined is why the version is quarantined on the installation at path, "" when it is not.

func RecoverOutdatedJudge

func RecoverOutdatedJudge(ctx context.Context, target, self, version string, health func(context.Context, string) error, guard func(string, string, func() error) error) error

RecoverOutdatedJudge reinstalls only the installer's recorded verified candidate after an isolated-probe rollback. Health is evaluated while holding the installation lock; the state guard must validate compatibility and hold its locks through replacement. No arbitrary downloaded bytes can enter here.

func RecoveryArtifact

func RecoveryArtifact(path string) (string, error)

RecoveryArtifact is the verified recovery binary of the installation at path.

func Rollback

func Rollback(ctx context.Context, path, reason string, guard func(previous, failed string, restore func() error) error) error

Rollback requires a guard that holds the state lock, verifies the previous version can write the CURRENT state, and invokes restore under that lock. No state snapshot is ever restored. A nil guard is refused.

func SetSandboxProofRequiredForTest

func SetSandboxProofRequiredForTest() func()

SetSandboxProofRequiredForTest selects the provisioned policy for integration tests of containment, returning a restore function. Production uses only the embedded policy; this does not add a runtime configuration override.

func SetUpdateTargetForTest

func SetUpdateTargetForTest(exePath, version string, verify func(name string, data, bundle []byte) error) func()

SetUpdateTargetForTest configures the target executable path, running version, and signature bundle validator for integration tests, returning a restore func.

func VerifyCandidateBundle

func VerifyCandidateBundle(assetName string, binary, bundle []byte) error

VerifyCandidateBundle verifies a staged candidate binary against its cosign bundle using the same release identity policy as self-update.

func WatchedProbation

func WatchedProbation(path string) bool

WatchedProbation says the installation at path has a supervised candidate awaiting its verdict: an update would only be refused, so it waits. A journal that cannot be read answers false: the update itself refuses it.

func WithOptions

func WithOptions(ctx context.Context, opts Options) context.Context

WithOptions attaches opts to ctx for Run.

Types

type Asset

type Asset struct {
	ID   int64  `json:"id"`
	Name string `json:"name"`
	Size int    `json:"size"`
	// URL is the asset's public download URL.
	URL string `json:"url"`
}

Asset is one binary or bundle of a Release.

type Binary

type Binary struct {
	Version string `json:"version"`
	Digest  string `json:"sha256"`
}

Binary identifies bytes verified by the release installer. A digest alone is not release evidence: only an installed, successfully probated candidate can become a recovery target.

type Canary

type Canary func(ctx context.Context, path, version string) error

Canary checks a verified candidate binary at path for version before it replaces the installed executable. Returning an error keeps the current executable in place.

type CanaryEvidence

type CanaryEvidence struct {
	Schema      int    `json:"schema"`
	Version     string `json:"version"`
	Commit      string `json:"commit,omitempty"`
	SHA256      string `json:"sha256"`
	OS          string `json:"os"`
	Arch        string `json:"arch"`
	Status      string `json:"status"`
	Run         string `json:"run"`
	MergeCommit string `json:"merge_commit"`
	Reason      string `json:"reason,omitempty"`
}

CanaryEvidence is signed separately from the binary, only after the staging workflow observes the sandbox merge. Schema changes require a new gate.

func ValidateEvidence

func ValidateEvidence(data []byte, version, digest string) (CanaryEvidence, error)

ValidateEvidence validates raw canary evidence JSON for the current platform against the expected release version tag and candidate binary SHA-256 digest.

func ValidateEvidenceFor

func ValidateEvidenceFor(data []byte, version, digest, goos, goarch string) (CanaryEvidence, error)

ValidateEvidenceFor validates raw canary evidence JSON for a target OS/Arch against the expected release version tag and candidate binary SHA-256 digest.

func ValidateRecordedEvidenceFor

func ValidateRecordedEvidenceFor(data []byte, version, digest, goos, goarch string) (CanaryEvidence, error)

ValidateRecordedEvidenceFor validates raw canary evidence JSON produced by a local/CI recorded fixture run (--canary-recorded). Recorded evidence is always rejected by ValidateEvidence, ValidateEvidenceFor, and requireEvidence so fixture runs can never grant release installation eligibility.

type Health

type Health func(ctx context.Context, path, version string) error

Health checks the executable at path, the installed candidate of version. Return ErrHealthUnproven (possibly wrapped) for transient or unreadable evidence.

type Journal

type Journal struct {
	Schema      int               `json:"schema"`
	Displaced   Binary            `json:"displaced"`
	Previous    *Binary           `json:"previous,omitempty"`
	Candidate   Binary            `json:"candidate"`
	InstalledAt time.Time         `json:"installedAt"`
	Probation   string            `json:"probation"`            // prepared, pending, passed, rolling-back, rolled-back
	Quarantine  map[string]string `json:"quarantine,omitempty"` // digest -> reason
	// Watched says a recovery controller supervises this candidate's probation:
	// its verdict decides, and an update waits for it.
	Watched bool `json:"watched,omitempty"`
	// JudgeRecovery preserves the original quarantine reason after explicit recovery.
	JudgeRecovery string `json:"judgeRecovery,omitempty"`
	// Observed is the controller's durable record of this probation.
	Observed *Observed `json:"observed,omitempty"`
}

Journal is durable before executable replacement. Schema is fenced because guessing at a future journal's semantics could destroy its recovery target.

func Inspect

func Inspect(path string) (*Journal, error)

Inspect reads the journal of the installation at path, nil for none, without the update lock: a journal is replaced in one rename, and an updater holding the lock through a download must not stall a controller's evaluation.

func (*Journal) Held

func (j *Journal) Held() string

Held is why recovery of this journal failed, "" when it did not.

func (*Journal) Pending

func (j *Journal) Pending() bool

Pending says the installed candidate of a journal awaits its verdict.

func (*Journal) RolledBack

func (j *Journal) RolledBack() bool

RolledBack says the journal's candidate was restored away from.

func (*Journal) RollingBack

func (j *Journal) RollingBack() bool

RollingBack says a rollback began and did not end: it is finished, not judged.

func (*Journal) Settled

func (j *Journal) Settled() bool

Settled says no controller has anything left to do for this journal.

type Observed

type Observed struct {
	Elapsed       time.Duration `json:"elapsed"`
	ProbePassed   bool          `json:"probePassed,omitempty"`
	ProbeFailures int           `json:"probeFailures,omitempty"`
	// ProbeFailure is the bounded cause of the latest counted candidate failure.
	ProbeFailure string `json:"probeFailure,omitempty"`
	// ProbedAt is the Elapsed of the last probe; LastPassAt is the Elapsed of
	// the last passed probe, kept as history when a later probe is inconclusive.
	ProbedAt   time.Duration `json:"probedAt,omitempty"`
	LastPassAt time.Duration `json:"lastPassAt,omitempty"`
	// Held is why recovery itself failed: updates and starts stay held.
	Held string `json:"held,omitempty"`
	// Reason is why the candidate was rolled back.
	Reason string `json:"reason,omitempty"`
	// Notified says the person's one line about the rollback is out.
	Notified bool `json:"notified,omitempty"`
	// Restarts counts the ticks spent moving processes off the failed candidate;
	// Restarted says none is left on it.
	Restarts  int  `json:"restarts,omitempty"`
	Restarted bool `json:"restarted,omitempty"`
	// RestartServices retains managed services seen on replaced bytes, so a
	// failed start is retried even after their old process has stopped.
	RestartServices []string `json:"restartServices,omitempty"`
	// RollbackFailures counts the failed attempts at a rollback.
	RollbackFailures int `json:"rollbackFailures,omitempty"`
	// LoopStarted says the candidate's own loop was seen running; LoopStartedAt
	// is the Elapsed at which it started, the start of its heartbeat grace.
	LoopStarted   bool          `json:"loopStarted,omitempty"`
	LoopStartedAt time.Duration `json:"loopStartedAt,omitempty"`
	// LastBeatAt is the latest healthy checkpoint in observed time. The flag
	// distinguishes a checkpoint at elapsed zero from an old journal with none.
	HeartbeatSeen bool          `json:"heartbeatSeen,omitempty"`
	LastBeatAt    time.Duration `json:"lastBeatAt,omitempty"`
}

Observed is a controller's durable record of one probation. Elapsed counts observed time, tick by tick: a machine that slept proves nothing and fails nothing while it slept.

func (*Observed) NoteLoop

func (o *Observed) NoteLoop(s Signals)

NoteLoop records the first start and latest healthy checkpoint in observed time. Ages are capped by observed time. The controller also caps startup age at one step, so downtime before the first sighting cannot consume startup grace.

type Options

type Options struct {
	// Version selects an exact release tag, including pre-releases.
	Version string
	Canary  Canary
	// Health checks the installed candidate before an update promotes it. Nil,
	// that the candidate runs the update is its evidence.
	Health Health
	Skip   func(tag string) bool
	// Recovery launches the controller that supervises the candidate about to
	// replace target, from the verified recovery binary at artifact. It runs
	// before the replacement: a candidate that never starts cannot prevent it.
	// Nil or an error leaves the candidate unwatched, promoted by its next update.
	Recovery Recovery
	// HostRollback authorizes an execution host to follow its coordinator back
	// to the verified previous release during probation. The guard checks live
	// state compatibility and fences candidate writers under the state lock.
	// Ordinary self-updates leave this nil and wait for the controller verdict.
	HostRollback func(previous, failed string, restore func() error) error
}

Options configures a Run call through its context.

func OptionsFrom

func OptionsFrom(ctx context.Context) Options

OptionsFrom returns the Options attached to ctx.

type Recovery

type Recovery func(ctx context.Context, previous Binary, artifact, target string) error

Recovery launches a recovery controller; see Options.Recovery.

type Release

type Release struct {
	Tag        string            `json:"tag"`
	ID         int64             `json:"id"`
	URL        string            `json:"url"`
	Published  time.Time         `json:"published"`
	Prerelease bool              `json:"prerelease"`
	Assets     []Asset           `json:"assets"`
	Tools      map[string]string `json:"tools,omitempty"`
}

Release is one release of Repository as an authenticated lookup found it: what an execution host needs to install it without asking GitHub's API itself. Its assets are downloaded from their public download URLs, which GitHub's API rate limits do not cover, and verified against their bundles on the host as any download is.

func LookupVersion

func LookupVersion(ctx context.Context, version string) (Release, error)

LookupVersion looks up release version (a tag, "v0.3.0") of Repository with the gh login (or GH_TOKEN, GITHUB_TOKEN), never anonymously, so that the call counts in the person's budget like every other GitHub call of beekeeper. A coordinator hands the answer to the execution host it updates (InstallRelease).

type Result

type Result struct {
	Current   string    `json:"current"`
	Latest    string    `json:"latest"`
	Published time.Time `json:"published"`
	URL       string    `json:"url"`
	Newer     bool      `json:"newer"`
	// Path is the file the update replaced, symbolic links not resolved.
	Path    string `json:"path,omitempty"`
	Updated bool   `json:"updated"`
}

Result is what a check or an update found and did.

func InstallRelease

func InstallRelease(ctx context.Context, w io.Writer, rel Release) (Result, error)

InstallRelease installs rel, as a coordinator's LookupVersion found it, over the running executable once its bundle verifies, as InstallVersion does, without asking GitHub's API: the binary and its bundle come from their public download URLs under the release's tag.

func InstallVersion

func InstallVersion(ctx context.Context, w io.Writer, version string) (Result, error)

InstallVersion installs exactly the release version (a tag, "v0.3.0") over the running executable once its bundle verifies, as Run installs the latest: an execution host follows its coordinator's release, never a newer one. The verified download is staged beside the destination and renamed over it atomically, retaining a verified recovery target once probation has succeeded. First installation has no trusted recovery target.

func Run

func Run(ctx context.Context, w io.Writer, checkOnly bool) (Result, error)

Run looks up the latest release and, unless checkOnly, installs its binary for this OS and architecture over the running executable once its bundle verifies. A running pre-release looks among the pre-releases too, a running release only among releases. Progress goes to w. With checkOnly the error is ErrOutdated when a newer release exists.

The binary is renamed over the executable in one step, symbolic links resolved: a beekeeper watch that runs keeps running the old binary, every process started afterwards runs the new one. Concurrent updates serialize through a durable journal lock. A development build, a release without a bundle for this platform's binary and a download that does not verify are refused, and the executable stays as it is.

type Signals

type Signals struct {
	// Failure is a tripped failure streak of the candidate's merges or starts.
	Failure string
	// Intentional says a stop or hold explains the silence: nothing counts.
	Intentional bool
	// Unproven is why the evidence cannot be trusted (GitHub unavailable,
	// unreadable health). It keeps the candidate pending, never rolls it back.
	Unproven string
	// HeartbeatRequired says this machine runs a loop that must show up.
	HeartbeatRequired, Heartbeat bool
	// HeartbeatAgo is the age of the checkpoint, not the age of the loop.
	HeartbeatAgo time.Duration
	// LoopStarted says the candidate's own loop started after the install,
	// LoopStartedAgo how long ago. LoopPending says it has not, while a loop of
	// another version still runs and re-executes at its next quiet pass.
	LoopStarted, LoopPending bool
	LoopStartedAgo           time.Duration
}

Signals are what one evaluation sees of the installed candidate.

Jump to

Keyboard shortcuts

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