Documentation
¶
Overview ¶
Package update replaces the running beekeeper with the latest signed release.
Index ¶
- Constants
- Variables
- func ClearHold(ctx context.Context, path string) error
- func CompleteProbation(ctx context.Context, path, version string) error
- func Decide(o Observed, s Signals) (verdict, reason string)
- func Digest(path string) (string, error)
- func Observe(ctx context.Context, path string, change func(*Journal) error) error
- func Quarantine(ctx context.Context, path, reason string) error
- func Quarantined(path, version string) string
- func RecoverOutdatedJudge(ctx context.Context, target, self, version string, ...) error
- func RecoveryArtifact(path string) (string, error)
- func Rollback(ctx context.Context, path, reason string, ...) error
- func SetSandboxProofRequiredForTest() func()
- func SetUpdateTargetForTest(exePath, version string, verify func(name string, data, bundle []byte) error) func()
- func VerifyCandidateBundle(assetName string, binary, bundle []byte) error
- func WatchedProbation(path string) bool
- func WithOptions(ctx context.Context, opts Options) context.Context
- type Asset
- type Binary
- type Canary
- type CanaryEvidence
- type Health
- type Journal
- type Observed
- type Options
- type Recovery
- type Release
- type Result
- type Signals
Constants ¶
const ( CanaryStatusSuccess = "success" CanaryStatusFailed = "failed" CanaryStatusPending = "pending" RecordedRunPrefix = "recorded:" )
CanaryEvidence status values and run prefixes.
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 the candidate loop's start: a // replaced loop re-executes only at a quiet pass, which can come late. HeartbeatGrace = 10 * time.Minute // ProbeFailures is how many consecutive failed probes fail a candidate. ProbeFailures = 3 )
const ( Wait = "wait" Promote = "promote" RollBack = "rollback" )
Verdicts of Decide.
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 ¶
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.
var ErrOutdated = errors.New("a newer beekeeper release is available")
ErrOutdated is what a check returns when a newer release exists.
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.
var ErrUpdateLocked = errors.New("update lock unavailable")
ErrUpdateLocked is an installation another updater holds.
Functions ¶
func ClearHold ¶
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 ¶
CompleteProbation promotes only the running version after the caller has established health. Interrupted completion is safe to repeat.
func Observe ¶
Observe lets change update the durable journal under the update lock, after reconciling an interrupted transaction. A nil journal is an error.
func Quarantine ¶
Quarantine records failed post-install health without changing the binary. It also applies at bootstrap, when there is no verified recovery target.
func Quarantined ¶
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 ¶
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 ¶
VerifyCandidateBundle verifies a staged candidate binary against its cosign bundle using the same release identity policy as self-update.
func WatchedProbation ¶
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.
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 ¶
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 ¶
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 ¶
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 ¶
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) RolledBack ¶
RolledBack says the journal's candidate was restored away from.
func (*Journal) RollingBack ¶
RollingBack says a rollback began and did not end: it is finished, not judged.
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"`
// 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"`
}
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.
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 ¶
OptionsFrom returns the Options attached to ctx.
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"`
}
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 ¶
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 ¶
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 ¶
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 ¶
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
// 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.