Documentation
¶
Overview ¶
Package nodemove runs persisted, resumable moves of apps and databases between nodes, and node drains built on those moves. Every phase is idempotent and recorded before the next starts, so a restart resumes.
Index ¶
- Constants
- func IsPermanent(err error) bool
- func Permanent(err error) error
- type BlockedError
- type Config
- type DrainPlanner
- type Executor
- type Option
- type Request
- type Resource
- type Runner
- func (r *Runner) Advance(ctx context.Context, id string) (store.NodeMove, error)
- func (r *Runner) AdvanceDrain(ctx context.Context, id string) error
- func (r *Runner) Kick()
- func (r *Runner) Run(ctx context.Context)
- func (r *Runner) Start(ctx context.Context, req Request) (store.NodeMove, error)
- func (r *Runner) StartDrain(ctx context.Context, nodeID, explicitTarget string) (store.NodeDrain, error)
- func (r *Runner) Tick(ctx context.Context)
- type Store
Constants ¶
const ( PhasePreflight = "preflight" PhaseStopSource = "stop_source" PhaseCopyVolumes = "copy_volumes" PhasePlace = "place" PhaseVerify = "verify" PhaseStopOld = "stop_old" PhaseFinalize = "finalize" PhaseRollback = "rollback" PhaseDone = "done" )
Phases of a move, in order. Stateless moves skip stop_source and copy_volumes, stateful ones skip stop_old (the source is already stopped).
const ( OutcomeOK = "ok" OutcomeRetry = "retry" OutcomeFailed = "failed" OutcomeWaiting = "waiting" )
Step outcomes recorded in a move's history.
Variables ¶
This section is empty.
Functions ¶
func IsPermanent ¶
IsPermanent reports whether err was marked with Permanent.
Types ¶
type BlockedError ¶
type BlockedError struct{ Reason string }
BlockedError means a resource cannot be moved by a drain at all.
func (*BlockedError) Error ¶
func (e *BlockedError) Error() string
type DrainPlanner ¶
type DrainPlanner interface {
Cordon(ctx context.Context, nodeID string) error
// Remaining lists what still runs on nodeID, databases before apps so
// an app can follow its database.
Remaining(ctx context.Context, nodeID string) ([]Resource, error)
// PickTarget chooses where res goes, honoring explicit when set. A
// *BlockedError skips res and records why.
PickTarget(ctx context.Context, res Resource, fromNodeID, explicit string) (string, error)
// Blocked lists resources on nodeID a drain can never move (e.g. models).
Blocked(ctx context.Context, nodeID string) ([]store.NodeDrainBlocked, error)
}
DrainPlanner supplies what a drain needs from the platform.
type Executor ¶
type Executor interface {
// Preflight refuses a move that cannot work (wrap with Permanent) and
// prepares dependencies such as a database's mesh endpoint.
Preflight(ctx context.Context, m store.NodeMove) error
// Stop suspends the resource and removes its containers from nodeID.
Stop(ctx context.Context, kind, name, nodeID string) error
CopyVolume(ctx context.Context, fromNodeID, toNodeID, volume string) error
Place(ctx context.Context, kind, name, nodeID string) error
Resume(ctx context.Context, kind, name string) error
// Ready reports whether the resource runs and passes readiness on
// nodeID, judged only on observations made after since.
Ready(ctx context.Context, kind, name, nodeID string, since time.Time) (bool, string, error)
// RemoveFrom removes the resource's containers from nodeID only.
RemoveFrom(ctx context.Context, kind, name, nodeID string) error
// Finalize runs after a verified move, e.g. restarting a database's dependents.
Finalize(ctx context.Context, m store.NodeMove) error
}
Executor performs the side effects of each phase against the platform. Every method must be idempotent: a crash between an action and the phase save replays the action.
type Option ¶
type Option func(*Runner)
Option configures a Runner.
func WithDrainPlanner ¶
func WithDrainPlanner(p DrainPlanner) Option
WithDrainPlanner enables drains.
type Request ¶
type Request struct {
Kind string
Resource string
FromNodeID string
ToNodeID string
Volumes []string
DrainID string
}
Request starts one move.
type Runner ¶
type Runner struct {
// contains filtered or unexported fields
}
Runner advances moves and drains.
func (*Runner) Advance ¶
Advance runs phases of one move until it waits, finishes, or a phase needs a retry. It returns the persisted move.
func (*Runner) AdvanceDrain ¶
AdvanceDrain moves the next resource off the drained node, one at a time, each through a full verified move. It stops at the first failed move and leaves the node cordoned.
func (*Runner) Start ¶
Start records a new move and wakes the runner. It fails with store.ErrNodeMoveInProgress when the resource is already moving.
type Store ¶
type Store interface {
CreateNodeMove(ctx context.Context, m store.NodeMove) error
SaveNodeMove(ctx context.Context, m store.NodeMove) error
GetNodeMove(ctx context.Context, id string) (store.NodeMove, error)
ListNodeMoves(ctx context.Context, f store.NodeMoveFilter) ([]store.NodeMove, error)
CreateNodeDrain(ctx context.Context, d store.NodeDrain) error
SaveNodeDrain(ctx context.Context, d store.NodeDrain) error
GetNodeDrain(ctx context.Context, id string) (store.NodeDrain, error)
ListNodeDrains(ctx context.Context, nodeID string, limit int) ([]store.NodeDrain, error)
}
Store is the persistence the runner needs; *store.DB satisfies it.