Help us shape the future of Go! Take the 2026 Go Developer Survey

supervisor

package
v1.37.1-stratum.0-rc.2 Latest Latest
Warning

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

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

Documentation

Overview

Package supervisor runs and restarts the host processes that make up a SKE node: containerd, kubelet, and the operator. (The control plane itself is kubelet-managed static pods, owned by internal/staticpod.) Start, restart with backoff, stop everything on shutdown — plus a control socket (/run/stratum/stratum.sock) so separate invocations (`stratum certs rotate`, HA join) can restart or stop individual components the way systemctl does for systemd units.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotSupervised = errors.New("not a supervised component")

ErrNotSupervised is returned when a caller asks about an unknown component.

View Source
var ErrReExecUnsupported = errors.New("supervisor does not support reexec")

ErrReExecUnsupported identifies a supervisor that predates the reexec request, from the exact response such a supervisor gives, so the caller must restart it some other way. Other rejection and transport errors are not a reason to fall back.

View Source
var ErrReloadUnsupported = errors.New("supervisor does not support reload")

ErrReloadUnsupported identifies the exact response from supervisors that predate reload. Other rejection, transport and recovery errors are not a compatibility fallback.

Functions

func DialReExec

func DialReExec(socket string) error

DialReExec asks the supervisor to stop every component and replace itself with its configured re-exec command. A supervisor that predates the request answers with ErrReExecUnsupported, and nothing changes.

func DialReload

func DialReload(socket, name string, spec ProcSpec) error

DialReload sends a "reload" op: it updates the named component's exec definition in the running supervisor and restarts it. Separate from Dial because it carries a process payload.

func Run

func Run(ctx context.Context, procs []Process, opts Options) error

Run starts every process and supervises them until ctx is cancelled.

A component that exits is restarted with exponential backoff: a control plane where the scheduler died and stayed dead is worse than one that is visibly flapping, because only the second is obvious.

Types

type Options

type Options struct {
	LogDir     string
	MinBackoff time.Duration
	MaxBackoff time.Duration
	// ControlSocket, when set, serves the restart/stop/start/status protocol
	// that internal/comps speaks (the supervisor's systemctl equivalent).
	ControlSocket string
	// OnStart is called after each successful start, with the pid.
	OnStart func(name string, pid int)
	// ReExec, when set, is the command line a "reexec" request replaces this
	// process with once every component has stopped; ReExec[0] is the binary.
	// Without it the request is refused.
	ReExec []string
}

Options tunes restart behaviour.

type ProcSpec

type ProcSpec struct {
	Path string   `json:"path"`
	Args []string `json:"args"`
	Env  []string `json:"env,omitempty"`
}

ProcSpec is the wire form of a component's exec definition, sent with a "reload" op. It carries only the marshalable fields of Process: an in-place `stratum upgrade` runs as the NEW binary and uses it to hand the running (old-binary) supervisor a component's new argv/config path, so the change applies without a full restart.

type ProcStatus

type ProcStatus struct {
	Name    string `json:"name"`
	Pid     int    `json:"pid"`
	Running bool   `json:"running"`
	Wanted  bool   `json:"wanted"`
	// Foreign: the component's socket is served by a process the supervisor
	// does not own, so Running (if set) is not this component.
	Foreign bool `json:"foreign,omitempty"`
}

func Dial

func Dial(socket, op, name string) ([]ProcStatus, error)

Dial sends one request to a control socket and returns the reply. Client side of the protocol; internal/comps wraps it with the systemctl-shaped API.

func DialContext

func DialContext(ctx context.Context, socket, op, name string) ([]ProcStatus, error)

DialContext is Dial bounded by ctx: the connect, the write and the wait for the reply all end when ctx does (or at Dial's own limits, whichever is sooner), so a caller on a deadline is not held for the 30s a hung supervisor would otherwise take.

type Process

type Process struct {
	Name string
	Path string
	Args []string
	// ArgsFn, when set, is evaluated on every (re)start instead of Args — for
	// components whose flags must re-render after external surgery (etcd
	// membership after `stratum snapshot rejoin`).
	ArgsFn func() []string
	Env    []string
	// WaitFor gates each start. Without it, every apiserver client crash-loops
	// through the seconds before the apiserver has bootstrapped its RBAC — the
	// supervisor recovers, but a control plane that always logs a crash on boot
	// trains people to ignore crash logs.
	WaitFor func(context.Context) error
	// Socket, when set, is the unix socket this component serves. If the
	// component exits while that socket is still live, someone else owns it
	// (an orphan from an earlier run): the component is reported Foreign
	// instead of silently retrying forever.
	Socket string
	// ExecLabel, when set, is the SELinux context the component is exec'd in,
	// rather than the one it would inherit from this process.
	ExecLabel string
}

Process is one supervised component.

type Supervisor

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

Supervisor tracks the running components for the control socket.

Jump to

Keyboard shortcuts

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