nodelifecycle

package
v0.24.0 Latest Latest
Warning

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

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

Documentation

Overview

Package nodelifecycle provides the pre-start, post-start and reconcile phases that a node supervising unit runs around the node stack. The Controller interface is keyed by slot, but the only implementation is the container isolation mode's, used by the hidden node-lifecycle command.

It is intentionally separate from pkg/agent/nspawnlifecycle, which is tied to nspawn config regeneration and NVIDIA rewiring and must stay unchanged for rollback stability. The overlap is small (the three phase names and a systemd reload), so it is duplicated rather than shared.

Index

Constants

View Source
const (
	// DefaultReadyTimeout bounds PostStart's wait for the stack to be running.
	DefaultReadyTimeout = 2 * time.Minute
	// DefaultAfterStartTimeout bounds AfterStart on its own, apart from the
	// readiness wait, so it is not limited to what remained of it.
	DefaultAfterStartTimeout = 3 * time.Minute
	// PostStartBudget is the longest PostStart takes with the defaults.
	PostStartBudget = DefaultReadyTimeout + DefaultAfterStartTimeout
)

The default bounds of PostStart. The supervising unit's start timeout is derived from PostStartBudget, so they are one constant, not two numbers that have to be kept equal.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	// Regenerate re-renders the backend's host-side configuration for a slot.
	Regenerate(ctx context.Context, slot string) error
	// Running reports whether the node stack for the slot is up, with a
	// human readable detail when it is not.
	Running(ctx context.Context, slot string) (running bool, detail string, err error)
	// Restart restarts the node stack for the slot (never the host).
	Restart(ctx context.Context, slot string) error
}

Controller is what the lifecycle needs from an isolation backend, keyed by slot so this package does not depend on a concrete backend.

type Lifecycle

type Lifecycle struct {
	Log        *slog.Logger
	Controller Controller
	// ReloadSystemd reloads systemd units after configuration is regenerated.
	ReloadSystemd func(ctx context.Context) error
	// AfterStart, when set, runs at the end of PostStart once the stack is
	// running, with the slot. The container mode uses it to wire GPUs, which
	// needs the stack up. Its failure fails PostStart.
	AfterStart func(ctx context.Context, slot string) error
	// ReadyTimeout bounds PostStart's wait for the stack to be running. Zero
	// is DefaultReadyTimeout.
	ReadyTimeout time.Duration
	// AfterStartTimeout bounds AfterStart. Zero is DefaultAfterStartTimeout.
	AfterStartTimeout time.Duration
	// Peer, when set, returns the slot whose node stack must not run at the
	// same time as slot's. PreStart refuses while it runs.
	Peer func(slot string) string
	// PollInterval is the wait between readiness checks.
	PollInterval time.Duration
}

Lifecycle implements the three phases.

func (*Lifecycle) PostStart

func (l *Lifecycle) PostStart(ctx context.Context, slot string) error

PostStart waits for the node stack to be running after the supervising unit starts, then runs AfterStart. It fails when the stack is not running within ReadyTimeout or AfterStart fails.

func (*Lifecycle) PreStart

func (l *Lifecycle) PreStart(ctx context.Context, slot string) error

PreStart refuses to start a slot while its peer slot's node stack is still alive, so a failed stop can never leave two node stacks on one host. It then refreshes host-side configuration and reloads systemd so changed units take effect.

func (*Lifecycle) Reconcile

func (l *Lifecycle) Reconcile(ctx context.Context, slot string) error

Reconcile restarts the node stack, which runs PreStart and PostStart through the supervising unit's hooks.

Jump to

Keyboard shortcuts

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