fleet

package
v0.2.8 Latest Latest
Warning

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

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

Documentation

Overview

Package fleet is deploy's read-only view of Warden's cluster membership.

The package owns polling one Warden status endpoint, normalizing the reply into an immutable Snapshot, and projecting configured node labels onto that snapshot for placement and the operator UI. Callers may rely on Client being safe for concurrent use, on Snapshot returning a defensive copy rather than shared state, and on a failed refresh preserving the last observed membership while clearing authority and quorum and recording the error — never on it reporting an empty fleet.

Leadership, term, and quorum are Warden's observations and are never inferred here; node Role and Labels are fixed Core configuration. The package performs no writes and makes no placement decision.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client polls one Warden status endpoint and caches the latest observation. It is safe for concurrent use.

func NewWardenClient

func NewWardenClient(rawURL string, httpClient *http.Client) (*Client, error)

NewWardenClient constructs the fleet observer for one Warden endpoint.

func (*Client) Refresh

func (c *Client) Refresh(ctx context.Context) (Snapshot, error)

Refresh polls Warden once and stores the result. On failure it returns both the recorded error snapshot and the error, so a caller that only wants display state can ignore the second value.

func (*Client) Run

func (c *Client) Run(ctx context.Context, interval time.Duration, changed func(snapshot Snapshot))

Run refreshes on interval until ctx is done, invoking changed with each new observation. Delivery is latest-wins on a single-slot channel, so a slow callback drops intermediate snapshots rather than delaying polling.

func (*Client) Snapshot

func (c *Client) Snapshot() Snapshot

Snapshot returns a copy of the most recent observation without polling.

type ConfiguredNode

type ConfiguredNode struct {
	ID       string            `json:"id"`
	Name     string            `json:"name"`
	Role     string            `json:"role"`
	Labels   map[string]string `json:"labels"`
	Status   string            `json:"status"`
	Address  string            `json:"address"`
	LastSeen time.Time         `json:"last_seen"`
}

ConfiguredNode combines fixed deployment configuration with Warden's observed membership state. Leadership remains a property of the containing snapshot and is never inferred from Role.

type ConfiguredSnapshot

type ConfiguredSnapshot struct {
	Self          string           `json:"self"`
	LeaderID      string           `json:"leader_id"`
	Term          uint64           `json:"term"`
	Authoritative bool             `json:"authoritative"`
	HasQuorum     bool             `json:"has_quorum"`
	Online        int              `json:"online"`
	Required      int              `json:"required"`
	Nodes         []ConfiguredNode `json:"nodes"`
	UpdatedAt     time.Time        `json:"updated_at"`
	Error         string           `json:"error,omitempty"`
}

ConfiguredSnapshot is the operator-facing fleet status. LeaderID and Term are dynamic Warden observations; node Role and Labels are fixed Core configuration used by placement.

func WithConfiguration

func WithConfiguration(snapshot Snapshot, configured map[string]map[string]string) ConfiguredSnapshot

WithConfiguration projects configured labels onto a Warden snapshot without mutating either input.

type Node

type Node struct {
	ID       string    `json:"id"`
	Name     string    `json:"name"`
	Role     string    `json:"role"`
	Status   string    `json:"status"`
	Address  string    `json:"address"`
	LastSeen time.Time `json:"last_seen"`
}

Node is one member of the cluster as Warden currently observes it. Every field is an observation; none of it is Core configuration.

type Snapshot

type Snapshot struct {
	Self          string    `json:"self"`
	LeaderID      string    `json:"leader_id"`
	Term          uint64    `json:"term"`
	Authoritative bool      `json:"authoritative"`
	HasQuorum     bool      `json:"has_quorum"`
	Online        int       `json:"online"`
	Required      int       `json:"required"`
	Nodes         []Node    `json:"nodes"`
	UpdatedAt     time.Time `json:"updated_at"`
	Error         string    `json:"error,omitempty"`
}

Snapshot is one immutable observation of the cluster. Error is set when the most recent refresh failed, in which case the membership is the last good one and Authoritative and HasQuorum are cleared.

func (Snapshot) CanMutate

func (s Snapshot) CanMutate() bool

CanMutate reports whether this observation is safe to act on: Warden must be authoritative, name a leader, and hold quorum. It is the single gate in front of every fleet mutation.

Jump to

Keyboard shortcuts

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