Documentation
¶
Overview ¶
Package nodes manages the control plane's view of cluster nodes: the per-node Docker client registry and the agent connection manager.
Index ¶
- Variables
- func BuildDirectClient(srv *models.Server) (docker.Client, error)
- type Clients
- func (c *Clients) Connected(serverID uint) bool
- func (c *Clients) ConnectedSince(serverID uint) (time.Time, bool)
- func (c *Clients) For(serverID uint) (docker.Client, error)
- func (c *Clients) ForServiceTask(ctx context.Context, clusterID uint, serviceName string) (docker.Client, string, error)
- func (c *Clients) IsLocal(serverID uint) bool
- func (c *Clients) IsSelfContainer(serverID uint, containerID string) bool
- func (c *Clients) Local() docker.Client
- func (c *Clients) LocalID() uint
- func (c *Clients) RemoteIDs() []uint
- func (c *Clients) RemoveRemote(serverID uint)
- func (c *Clients) SelfContainerID(serverID uint) string
- func (c *Clients) SetLocalSelf(id string)
- func (c *Clients) SetRemote(serverID uint, cl docker.Client)
- func (c *Clients) SetRemoteSelf(serverID uint, id string)
- func (c *Clients) SetSwarmManagers(fn SwarmManagers)
- type Manager
- func (m *Manager) AddStatusListener(fn func(nodeID uint, name string, online bool))
- func (m *Manager) Clients() *Clients
- func (m *Manager) ConnectDirect(srv *models.Server) error
- func (m *Manager) Connected(nodeID uint) bool
- func (m *Manager) Disconnect(nodeID uint)
- func (m *Manager) DisconnectDirect(id uint)
- func (m *Manager) ForgetStatus(nodeID uint)
- func (m *Manager) Handle(srv *models.Server, token, agentVersion, agentContainerID string, ...)
- func (m *Manager) LoadDirect(ctx context.Context, interval time.Duration)
- func (m *Manager) ReconcileHealth(ctx context.Context)
- func (m *Manager) RefreshClient(srv *models.Server)
- func (m *Manager) SetOnConnect(...)
- func (m *Manager) SetOnRemove(fn func(ctx context.Context, srv *models.Server, dc docker.Client))
- func (m *Manager) SetSubscriber(fn func(ctx context.Context, nodeID uint, dc docker.Client))
- func (m *Manager) Teardown(ctx context.Context, srv *models.Server)
- type SwarmManagers
Constants ¶
This section is empty.
Variables ¶
var ErrNodeOffline = errors.New("node is offline (no connected agent)")
ErrNodeOffline is returned when a Docker client is requested for a node whose agent is not currently connected.
var ErrTaskUnreachable = errors.New("the service's task runs on a swarm node with no Miabi agent")
ErrTaskUnreachable is returned when a swarm service HAS a running task but no engine we hold a client for can see its container — Swarm placed it on a node with no Miabi agent. It is distinct from docker.ErrNotFound: reporting "nothing running" for a 1/1 service is simply false.
Functions ¶
Types ¶
type Clients ¶
type Clients struct {
// contains filtered or unexported fields
}
Clients resolves a Docker client for a given server/node id: the local node uses the direct engine client, remote nodes a tunneled client registered when their agent connects. A server id of 0 resolves to the local node, so paths that don't carry placement still work single-node.
func NewClients ¶
NewClients creates the registry seeded with the local node's client.
func (*Clients) ConnectedSince ¶ added in v1.10.1
ConnectedSince reports when a remote node's client was registered, and whether the node has one at all. The local engine is always reachable, so it reports the zero time.
func (*Clients) For ¶
For returns the Docker client for a node, or ErrNodeOffline if a remote node has no connected agent.
func (*Clients) ForServiceTask ¶ added in v1.3.0
func (c *Clients) ForServiceTask(ctx context.Context, clusterID uint, serviceName string) (docker.Client, string, error)
ForServiceTask resolves the engine and container id of a task of the named swarm service in the given cluster, wherever the scheduler placed it. Correlating the task's swarm node id is unreliable, so it asks the engines directly — local first, then each connected node. Exactly one node runs the task.
func (*Clients) IsSelfContainer ¶
IsSelfContainer reports whether containerID is Miabi's own runtime container on the given node (the control plane locally, or that node's agent).
func (*Clients) RemoteIDs ¶
RemoteIDs returns the ids of remote nodes that currently have a live client (the local node is excluded). Used by the health sweep to probe each tunnel.
func (*Clients) RemoveRemote ¶
RemoveRemote drops a remote node's client when its agent disconnects.
func (*Clients) SelfContainerID ¶
SelfContainerID returns Miabi's own runtime container ID on the node — the control plane locally, or the node's agent — or "" when unknown (e.g. an offline agent or detection that found nothing).
func (*Clients) SetLocalSelf ¶
SetLocalSelf records the control-plane's own container ID (detected at startup) so it is protected from removal on the local node.
func (*Clients) SetRemote ¶
SetRemote registers (or replaces) a remote node's client when its agent connects.
func (*Clients) SetRemoteSelf ¶
SetRemoteSelf records a connected node's agent container ID (reported by the agent) so it is protected from removal on that node.
func (*Clients) SetSwarmManagers ¶ added in v1.10.1
func (c *Clients) SetSwarmManagers(fn SwarmManagers)
SetSwarmManagers wires how a cluster's swarm manager is reached, so a service in any cluster is checked against its own swarm.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager accepts agent tunnels and maintains the live remote Docker clients in the registry, plus each node's online/offline status.
func (*Manager) AddStatusListener ¶ added in v1.10.4
AddStatusListener registers a hook fired when a node comes online (agent connected, or a direct node answering) or goes offline. Used by alerting to raise/resolve a "node offline" alert, and by the console to show a node connecting without a reload. Best-effort: run in a goroutine, must not block. Listeners see transitions only, never a repeat of a state they already hold.
func (*Manager) ConnectDirect ¶
ConnectDirect builds and registers a direct node's Docker client, replacing any existing one. A no-op for agent or local nodes. Best-effort: a build error is returned so callers can surface it, but the node stays registered as offline until the next attempt.
func (*Manager) Disconnect ¶
Disconnect tears down a node's tunnel (e.g. when it is deleted).
func (*Manager) DisconnectDirect ¶
DisconnectDirect drops a direct node's client (on delete or mode change).
func (*Manager) ForgetStatus ¶ added in v1.10.4
ForgetStatus drops a node's announced state, so it is announced afresh when it next appears. Called when the node record is deleted, not when its tunnel drops: a dropped tunnel is a state listeners still need, while a deleted node's id may be handed to a different machine later.
func (*Manager) Handle ¶
func (m *Manager) Handle(srv *models.Server, token, agentVersion, agentContainerID string, ws *websocket.Conn)
Handle owns an authenticated agent WebSocket: it builds the tunnel, registers the node's remote Docker client, marks it online, and blocks until the tunnel closes. The plaintext join token is passed through so the connect hook can configure node-side infrastructure.
func (*Manager) LoadDirect ¶
LoadDirect registers clients for all direct-access nodes at startup and runs a health poller that pings them on interval to keep their status current. It blocks until ctx is cancelled.
func (*Manager) ReconcileHealth ¶
ReconcileHealth actively verifies every connected node by pinging its Docker daemon over the tunnel. A node that fails to answer has a dead or half-open tunnel yamux keepalive hasn't caught, so its session is closed, triggering the normal disconnect cleanup and correcting a stale status.
func (*Manager) RefreshClient ¶
RefreshClient rebuilds a node's Docker client after its connectivity settings change. A live agent tunnel owns its own registration and is left untouched — rebuilding would evict the live client and flip a connected node offline. Direct nodes are rebuilt to pick up new credentials.
func (*Manager) SetOnConnect ¶
func (m *Manager) SetOnConnect(fn func(ctx context.Context, srv *models.Server, token string, dc docker.Client))
SetOnConnect registers a hook run in a goroutine once a node's agent has connected and its remote Docker client is live — e.g. to deploy an edge-gateway node's gateway. The hook receives the node's plaintext join token, which is only available at connect time.
func (*Manager) SetOnRemove ¶
SetOnRemove registers a hook run when a node is being removed while still connected — e.g. to tear down an edge-gateway node's gateway. It runs with the node's live Docker client before the tunnel is closed. See Teardown.
func (*Manager) SetSubscriber ¶
SetSubscriber registers a per-node worker run (in a goroutine) for the node's whole connection lifetime: started once its Docker client is live, its context cancelled when the tunnel drops. Used for the per-node app event subscriber.