Documentation
¶
Overview ¶
Package upgrade replaces the controller and agent binaries in place with automatic rollback (§5.0.1). The process that is replaced cannot watch its own replacement, so a detached guard (a copy of the old binary) stops it, swaps the binary, starts the new one, checks it and restores the old binary (and, for the controller, the database snapshot) when it is not healthy.
Index ¶
- Constants
- Variables
- func AgentGuard(ctx context.Context, dataDir string) error
- func AgentStagingFile(dataDir string) string
- func FileSHA256(path string) (string, error)
- func Guard(ctx context.Context, dataDir string) error
- func Install(src, dst string) error
- func Reexec(ri RunInfo) error
- func Spawn(name, logPath string, underSystemd bool, argv ...string) error
- func Start(ri RunInfo, fallbackLog string) (int, error)
- func Stop(ri RunInfo, timeout time.Duration) error
- func Terminal(p string) bool
- func ValidVersion(v string) bool
- func WriteRunInfo(path, healthURL string) error
- func WriteSums(dir string) error
- type AgentPending
- type AgentResult
- type Files
- type Health
- type Options
- type RunInfo
- type Service
- type Source
- type State
- type Step
Constants ¶
const ( PhasePreparing = "preparing" PhaseStopping = "stopping" PhaseStarting = "starting" PhaseVerifying = "verifying" PhaseDone = "done" PhaseRollingBack = "rolling-back" PhaseRolledBack = "rolled-back" PhaseFailed = "failed" // rollback did not bring the old controller back )
Phases of a controller upgrade.
const DefaultReleaseURL = version.Repository
DefaultReleaseURL is where releases are published: the project's GitHub releases.
const RunInfoFile = "controller-run.json"
RunInfoFile is where the controller records how it was started.
Variables ¶
var AgentReconnectTimeout = 2 * time.Minute
AgentReconnectTimeout is how long a new agent has to reconnect before the guard restores the old one.
Functions ¶
func AgentGuard ¶
AgentGuard waits for the new agent to reconnect (it removes the pending file) and otherwise restores and restarts the old one.
func AgentStagingFile ¶
AgentStagingFile is where an incoming agent binary is written.
func FileSHA256 ¶
FileSHA256 is the hex SHA-256 of a file.
func Guard ¶
Guard runs the upgrade prepared by Begin: stop, swap, start, verify, and roll back when the new controller is not healthy.
func Install ¶
Install replaces dst with src atomically (rename over a running binary is safe on Linux: the old inode lives until the process exits).
func Reexec ¶
Reexec replaces this process with the (new) binary, keeping its PID, arguments and environment. Containers keep running meanwhile.
func Spawn ¶
Spawn starts a detached helper (the guard) that survives the caller: as a transient systemd unit when the caller runs under systemd (so stopping the caller's unit does not kill it), else in its own session.
func ValidVersion ¶
ValidVersion reports whether v is usable as a path segment.
func WriteRunInfo ¶
WriteRunInfo records this process in path.
Types ¶
type AgentPending ¶
type AgentPending struct {
Version string `json:"version"`
From string `json:"from"`
Exe string `json:"exe"`
Prev string `json:"prev"`
Deadline time.Time `json:"deadline"`
Run RunInfo `json:"run"`
}
AgentPending is written before an agent replaces itself and removed by the new agent once the controller accepts it.
func ReadAgentPending ¶
func ReadAgentPending(dataDir string) (AgentPending, bool)
ReadAgentPending returns the pending upgrade, if any.
type AgentResult ¶
AgentResult is left for the restored agent to report.
func AgentConnected ¶
func AgentConnected(dataDir, running string) *AgentResult
AgentConnected is called by an agent once the controller accepted it: a pending upgrade to this version succeeded. It returns a result to report (a rolled-back upgrade), if any.
type Health ¶
type Health struct {
Version string `json:"version"`
Ready bool `json:"ready"`
Problems []string `json:"problems"`
}
Health is what /api/v1/system/health returns.
type Options ¶
type Options struct {
DataDir string
DBPath string
Version string // target
Current string // running version
Source Source
HealthURL string
Downloads string // agents and synctl served to workers ("" = none)
// Snapshot writes a consistent copy of the database to path.
Snapshot func(ctx context.Context, path string) error
// Run is how the running controller was started.
Run RunInfo
Settle time.Duration // healthy for this long before it counts (default 2m)
Timeout time.Duration // to become healthy (default 5m)
}
Options of a controller upgrade.
type RunInfo ¶
type RunInfo struct {
PID int `json:"pid"`
Exe string `json:"exe"`
Argv []string `json:"argv"`
Env []string `json:"env"`
Dir string `json:"dir"`
// Stdout is the file standard output and error went to ("" if not a file).
Stdout string `json:"stdout,omitempty"`
// Unit is the systemd unit running the process ("" when not under systemd).
Unit string `json:"unit,omitempty"`
// HealthURL is the controller's /api/v1/system/health (controllers only).
HealthURL string `json:"healthUrl,omitempty"`
}
RunInfo is how a running controller or agent was started, written at start so a guard can stop and start it again the same way.
func BeginAgent ¶
BeginAgent replaces the running agent's binary with staged (already verified) after starting a guard; the caller then re-executes itself.
func ReadRunInfo ¶
ReadRunInfo reads a RunInfo written by WriteRunInfo.
type Service ¶
type Service struct {
DataDir string
DBPath string
Downloads string
Source Source
Channel string
Current string
Settle time.Duration
Snapshot func(ctx context.Context, path string) error
// contains filtered or unexported fields
}
Service starts controller upgrades for the API and reports their state.
func (*Service) RunInfoPath ¶
RunInfoPath is where the running controller recorded how it was started.
type Source ¶
type Source struct {
Base string
HTTP *http.Client
// API is GitHub's REST API (default https://api.github.com).
API string
}
Release layout (the same as install.sh downloads):
<base>/channels/<channel> a version, e.g. "1.4.2" <base>/<version>/SHA256SUMS <base>/<version>/syncloud-controller-linux-<arch> <base>/<version>/syncloud-agent-linux-<arch> <base>/<version>/synctl-linux-<arch>
base is https://…, http://… or file:///dir (mirrors, air-gapped installs and tests). A GitHub repository base (https://github.com/<owner>/<repo>) uses GitHub's release layout instead: files are release assets of the tag v<version>, "stable" is the latest release and "beta" the newest one including prereleases.
func (Source) Fetch ¶
Fetch downloads a release into dir and checks every file against SHA256SUMS. The controller for this machine's architecture is required; agents and synctl for other architectures are taken when present.
type State ¶
type State struct {
ID string `json:"id"`
From string `json:"from"`
To string `json:"to"`
Phase string `json:"phase"`
Message string `json:"message,omitempty"`
Steps []Step `json:"steps"`
StartedAt time.Time `json:"startedAt"`
UpdatedAt time.Time `json:"updatedAt"`
FinishedAt *time.Time `json:"finishedAt,omitempty"`
Dir string `json:"dir"`
Exe string `json:"exe"`
Prev string `json:"prev"`
New string `json:"new"`
Snapshot string `json:"snapshot"`
DBPath string `json:"dbPath"`
HealthURL string `json:"healthUrl"`
Downloads string `json:"downloads,omitempty"`
Files Files `json:"files"`
Run RunInfo `json:"run"`
Settle int `json:"settleSeconds"`
Timeout int `json:"timeoutSeconds"`
}
State of the current (or last) controller upgrade, in <data>/upgrade/state.json.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package rollout upgrades agents node by node (§5.0.1 step 6, §6.2): each node gets the agent binary from the controller's downloads over its agent stream, restarts into it, and must reconnect with the new version before the next node starts.
|
Package rollout upgrades agents node by node (§5.0.1 step 6, §6.2): each node gets the agent binary from the controller's downloads over its agent stream, restarts into it, and must reconnect with the new version before the next node starts. |