upgrade

package
v0.2.0-beta.18 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package upgrade runs the read-only checks that gate a platform self-upgrade.

Index

Constants

View Source
const (
	ChannelStable = "stable"
	ChannelBeta   = "beta"
	ChannelEdge   = "edge"
)

Update channels a running build can compare itself against. ChannelStable is GitHub's own "latest release" concept (unchanged default behavior); ChannelBeta and ChannelEdge follow release.yml's own image-channel job scheme: a hyphenated SemVer tag (e.g. v1.2.3-beta.1) gets :beta, a main push gets :edge.

View Source
const (
	StatusOK      = "ok"
	StatusWarn    = "warn"
	StatusFail    = "fail"
	StatusUnknown = "unknown"
)

Check statuses.

View Source
const (
	ChecksumsAsset = "checksums.txt"
	SignatureAsset = "checksums.txt.sigstore.json"
)

Asset names the release workflow publishes next to the binaries.

View Source
const DefaultCacheTTL = time.Hour

DefaultCacheTTL is how long a Cache entry stays fresh before a caller should fetch again: shared by GET /api/v1/updates, updatecheck.Scheduler, and alerting's kind=version_skew evaluator, so none of them hits GitHub more often than this regardless of its own call cadence.

Variables

This section is empty.

Functions

func Blocked

func Blocked(checks []Check) bool

Blocked reports whether any check is a hard failure.

func UpdateAvailable

func UpdateAvailable(currentVersion string, latest *Release) bool

UpdateAvailable reports whether latest represents a newer build than currentVersion. A "dev" build never reports an update available: there is no meaningful newer build to compare an unreleased build against. Two SemVer tags compare by precedence (beta.9 < beta.15); anything else (edge's main-<sha>) falls back to inequality.

func ValidChannel

func ValidChannel(c string) bool

ValidChannel reports whether c is one of the three recognized channels.

Types

type Cache

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

Cache holds the last successful channel lookup, so GET /api/v1/updates and internal/updatecheck.Scheduler don't hit GitHub on every call. Keyed by channel (not just a bare TTL) so switching channels never serves a stale result cached for a different one.

func NewCache

func NewCache() *Cache

NewCache returns an empty Cache, ready to use.

func (*Cache) Fresh

func (c *Cache) Fresh(ttl time.Duration, channel string) (*Release, bool)

Fresh returns the cached release for channel if one exists and is within ttl.

func (*Cache) Set

func (c *Cache) Set(channel string, release *Release)

Set records release as the latest lookup result for channel.

func (*Cache) Stale

func (c *Cache) Stale(channel string) (*Release, bool)

Stale returns whatever was last cached for channel, regardless of age, for use when a fresh fetch just failed.

type Check

type Check struct {
	Code    string `json:"code"`
	Name    string `json:"name"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

Check is one preflight result.

func Run

func Run(ctx context.Context, in Inputs) []Check

Run evaluates every preflight check. It never changes anything.

type Fetchers

type Fetchers struct {
	Stable func(context.Context) (*Release, error)
	Beta   func(context.Context) (*Release, error)
	Edge   func(context.Context) (*Release, error)
}

Fetchers groups one fetch function per channel, the same overridable seam Router.fetchLatestRelease (internal/api/updates.go) already establishes for testing without a real outbound call.

func DefaultFetchers

func DefaultFetchers() Fetchers

DefaultFetchers wires the three real GitHub lookups above.

func (Fetchers) LatestForChannel

func (f Fetchers) LatestForChannel(ctx context.Context, channel string) (*Release, error)

LatestForChannel dispatches to the fetcher for channel, defaulting to Stable for an unrecognized or empty channel.

type Inputs

type Inputs struct {
	Lookup        func(string) (string, bool)
	DockerVersion func(ctx context.Context) (string, error)
	FreeBytes     func() (int64, error)
	NewestBackup  func() (time.Time, bool, error)
	Now           time.Time
	AssetNames    []string
	ReleaseKnown  bool
}

Inputs is everything Run needs, injected so tests use fakes.

type KnownBad

type KnownBad struct {
	Prefix string `json:"prefix"`
	Reason string `json:"reason"`
}

KnownBad is one Docker Engine version prefix that must not run an upgrade.

func LoadKnownBad

func LoadKnownBad(lookup func(string) (string, bool)) ([]KnownBad, error)

LoadKnownBad reads the known-bad Docker list from APP_DOCKER_KNOWN_BAD_FILE when set, otherwise from the embedded data file.

type Release

type Release struct {
	Tag         string
	URL         string
	PublishedAt string
	Body        string
	AssetNames  []string
}

Release is the subset of a GitHub release, or (for the edge channel) a main-branch commit treated as a pseudo-release, that a channel-aware update check needs.

func FetchLatestBeta

func FetchLatestBeta(ctx context.Context) (*Release, error)

FetchLatestBeta fetches the newest prerelease from GitHub's releases list, skipping drafts. nil, nil means no prerelease has ever been published.

func FetchLatestEdge

func FetchLatestEdge(ctx context.Context) (*Release, error)

FetchLatestEdge fetches the latest commit on main and reports it as a pseudo-release tagged "main-<short sha>", matching release.yml's own image-channel job scheme for what a main push's Docker image tag is (IMAGE_VERSION: main-<sha>). nil, nil means the lookup found nothing (an empty or inaccessible repo).

func FetchLatestStable

func FetchLatestStable(ctx context.Context) (*Release, error)

FetchLatestStable fetches GitHub's /releases/latest: the newest non-prerelease, non-draft release. With no stable release it falls back to the newest pre-release (install.sh's rule). nil, nil means nothing has been published at all.

Jump to

Keyboard shortcuts

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