Documentation
¶
Overview ¶
Package selfupdate lets the d8 binary update itself through the cluster (registry-packages-proxy, kubeconfig identity - no registry credentials).
It implements the `d8 cli` command tree:
- check - is a newer version available
- versions - list published versions (alias: list)
- update - install a version and switch to it
- use - switch to a version (instant if already installed)
How it works, in short:
- Versions are kept in a per-user store (~/.deckhouse-cli/cli/versions/<tag>/d8); the active one is selected by the `current` symlink, so switching is an atomic repoint - no file copying, no sudo. The PATH entry (e.g. /opt/deckhouse/bin/d8) is a one-time-created symlink to that `current`, with the original binary kept as <exe>.old. Full layout: store.go.
- Every downloaded binary is smoke-tested (`--version`) before it becomes active; a corrupt or wrong-platform artifact never replaces a working d8.
Wiring: the cobra commands live in the cmd subpackage; this package holds the update flow (update.go) and the store (store.go). Downloads go through the Source interface (source.go) backed by internal/rpp. Details, trade-offs, and the full file map are in README.md next to this file.
Index ¶
Constants ¶
const ( // OldSuffix marks the backup of a plain-file install made when it is migrated // to the store-managed (symlink) layout. OldSuffix = ".old" )
Variables ¶
This section is empty.
Functions ¶
func CurrentExecutable ¶
CurrentExecutable resolves the running binary to a real file path (symlinks evaluated). For a store-managed install this lands inside the store (the `current` chain resolved), which is exactly how SwitchTo detects the mode.
Types ¶
type Source ¶
type Source interface {
ListTags(ctx context.Context) ([]string, error)
ExtractBinary(ctx context.Context, tag, destination string) error
}
Source lists available deckhouse-cli versions and extracts the binary for a tag.
func NewRPPSource ¶
NewRPPSource builds the proxy-backed release source.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the local store of installed d8 versions plus the `current` symlink that selects the active one - the same versions-directory-plus-symlink layout the plugin installer uses:
<root>/current -> versions/<version>/d8 (atomic repoint on switch) <root>/versions/<version>/d8
The PATH entry (e.g. /opt/deckhouse/bin/d8) is a one-time-created symlink to <root>/current, so switching never touches root-owned directories.
Addressed by its own well-known paths, never via os.Executable(). On Linux /proc/self/exe resolves to the symlink TARGET: "replace what the executable resolves to" would overwrite a stored version in place instead of repointing the link.
A nil *Store is a valid no-op store (all read methods are nil-safe), so callers degrade gracefully when the home directory cannot be resolved.
func NewStore ¶
NewStore returns the per-user version store at ~/.deckhouse-cli/cli (next to the plugins home-fallback layout).
func NewStoreAt ¶
NewStoreAt returns a store rooted at an explicit directory (tests, tooling).
func (*Store) Archive ¶
Archive copies the binary at srcPath into the store under tag (used to seed the store with the running binary during migration). Same immutability and semver rules as Install.
func (*Store) Contains ¶
Contains reports whether path (already symlink-resolved) lies inside the store - i.e. the running binary is store-managed.
func (*Store) CurrentTag ¶
CurrentTag returns the version the `current` symlink points at, or "" when the link is absent or points outside the expected versions layout.
type SwitchResult ¶
type SwitchResult struct {
// PrevTag is the version `current` pointed at before the switch ("" when the
// install was not store-managed yet).
PrevTag string
// Migrated reports that the PATH entry was converted from a plain file to a
// symlink into the store (the original is backed up with OldSuffix).
Migrated bool
}
SwitchResult describes what a switch did, so commands can tell the user what was left behind and how to undo it.
func SwitchTo ¶
func SwitchTo(ctx context.Context, exePath, tag string, store *Store, logger *dkplog.Logger, stage func(dst string) error) (SwitchResult, error)
SwitchTo makes tag the active d8 version: ensures it is in the store (fetching via stage when missing; stage == nil demands a store hit), smoke-tests it and atomically repoints the store's `current` symlink. The PATH binary is never rewritten - it is a symlink into the store, so the switch happens entirely in the user's home, with no elevated privileges and no file copies.
exePath is the resolved path of the running binary. When it lies outside the store (a plain-file install), the switch MIGRATES it: the running binary is seeded into the store under its own version, and the PATH file is backed up as <exe>.old and replaced with a symlink to the store's `current`. The same path heals an install whose symlink was overwritten by external tooling.
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
Updater checks for and installs newer deckhouse-cli releases from a Source.
func NewUpdater ¶
NewUpdater builds an Updater over the given Source. The store is where versions are installed and switched; without it (nil) updates cannot proceed.
func (*Updater) Apply ¶
Apply downloads tag into the version store (unless already present) and makes it the active version by repointing the store's `current` symlink. A plain-file install is migrated to the symlink layout on the way (backup kept as <exe>.old).
func (*Updater) LatestVersion ¶
LatestVersion returns the highest available STABLE semver tag and whether it is newer than current (pre-releases are ignored - install them explicitly via --version). A non-semver current (e.g. a "dev" build) is treated as older than any real release, so an update is always offered.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package selfupdatecmd implements the `d8 cli` command tree on top of the internal/selfupdate machinery (store, updater).
|
Package selfupdatecmd implements the `d8 cli` command tree on top of the internal/selfupdate machinery (store, updater). |
|
errdetect
Package errdetect maps registry-packages-proxy failures from `d8 cli` to HelpfulErrors with CLI-specific guidance.
|
Package errdetect maps registry-packages-proxy failures from `d8 cli` to HelpfulErrors with CLI-specific guidance. |