node

package
v1.10.28 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package node manages Docker host (server) records and their reachability.

Index

Constants

View Source
const IngressOverlay = "miabi-ingress"

IngressOverlay carries only gateway-to-VIP traffic, so workspace east-west isolation is unaffected.

Variables

View Source
var (
	ErrNodeNotFound            = errors.New("node not found")
	ErrNameRequired            = errors.New("node name is required")
	ErrLocalNode               = errors.New("the local node cannot be modified this way")
	ErrBadToken                = errors.New("invalid agent token")
	ErrNodeCordoned            = errors.New("node is cordoned and cannot accept new placements")
	ErrConnectivityAckRequired = &connectivityAckError{}
	ErrInvalidPool             = errors.New("a pool name is lowercase letters, digits and hyphens (max 32), e.g. pro")
	// Surfaced as a warning, not an abort: the cordon itself was saved.
	ErrSwarmNotMirrored    = errors.New("the node was updated, but its swarm scheduling availability could not be changed — Swarm may still place service tasks on it")
	ErrInvalidConnectivity = errors.New("a node either runs its own gateway (edge-gateway) or, as a swarm member, is served by its cluster's gateway (cluster)")
)
View Source
var AppNetwork = stack.DefaultNetwork

AppNetwork is the gateway network Goma and app containers join; set once at startup via MIABI_PROXY_NETWORK.

View Source
var ErrEdgeGatewayInDefaultCluster = errors.New("a node of the default cluster is served by the control-plane gateway and cannot run one of its own; remove it from the swarm to give it its own cluster")

ErrEdgeGatewayInDefaultCluster is returned for a node of the default cluster set to run its own gateway.

Functions

func AppAlias

func AppAlias(app *models.Application) string

AppAlias is the redeploy-stable upstream alias; legacy apps without a stored alias fall back to "mb-app-<id>".

func CanaryAlias

func CanaryAlias(app *models.Application) string

CanaryAlias differs from AppAlias so the proxy can split weighted traffic between stable and canary.

func NewAppAlias

func NewAppAlias(token string, appID uint) string

NewAppAlias builds a fresh stable alias for a newly created app.

func PublicIP added in v1.10.0

func PublicIP(raw string) string

PublicIP returns "" for non-routable addresses; raw may carry a port, which is stripped.

func ResolveAppNetwork added in v1.10.13

func ResolveAppNetwork(ctx context.Context, dc docker.Client, configured string) string

ResolveAppNetwork prefers the network found locally so installs from before the rename keep their apps' network.

func SetAppNetwork

func SetAppNetwork(name string)

SetAppNetwork must be called once at startup, before Bootstrap or any deploy.

Types

type NodeInput

type NodeInput struct {
	// The handle is derived once and not settable: deployed edge gateways poll /api/v1/provider/{name}.
	DisplayName  string
	Address      string
	Connectivity models.ServerConnectivity
	AccessMode   models.ServerAccessMode
	// DockerEndpoint is the host for non-agent modes (unix://… / tcp://host:2376).
	DockerEndpoint string
	TLSCACert      string // api, optional (PEM)
	TLSCert        string // api, optional (PEM)
	TLSKey         string // api, optional (PEM; stored encrypted)
	// Required whenever the update changes reachability, which may briefly interrupt the node's workloads.
	Acknowledge bool
}

The TLS key is plaintext on input and encrypted at rest.

type Service

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

func NewService

func NewService(repo *repositories.ServerRepository, dockerClient docker.Client) *Service

func (*Service) AdoptGateway

func (s *Service) AdoptGateway(id uint, container, image, configYAML string) (*models.Server, error)

AdoptGateway tracks an existing gateway container without recreating it; nodes that cannot run a gateway are refused.

func (*Service) Authenticate

func (s *Service) Authenticate(token string) (*models.Server, error)

func (*Service) AuthenticateProvider

func (s *Service) AuthenticateProvider(slug, token string) (*models.Server, error)

AuthenticateProvider accepts the agent join token or the gateway token; the URL slug must match the node.

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context, endpoint string)

Bootstrap is non-fatal when Docker is unreachable, so the API can still serve.

func (*Service) CreateNode

func (s *Service) CreateNode(in NodeInput) (*models.Server, string, error)

CreateNode returns a one-time join token for agent mode (only its hash is stored).

func (*Service) DeleteNode

func (s *Service) DeleteNode(id uint) error

DeleteNode removes a remote node record.

func (*Service) FindBySwarmNodeID added in v1.3.0

func (s *Service) FindBySwarmNodeID(swarmNodeID string) (*models.Server, error)

FindBySwarmNodeID resolves the node backing a swarm node id.

func (*Service) GatewayRedisPassword

func (s *Service) GatewayRedisPassword(id uint) (string, error)

GatewayRedisPassword mints on first use and stays stable so gateway and Redis credentials keep matching.

func (*Service) GatewayToken

func (s *Service) GatewayToken(id uint) (string, error)

GatewayToken mints on first use; unlike the join token it is recoverable, so the gateway can be redeployed.

func (*Service) Get

func (s *Service) Get(id uint) (*models.Server, error)

Get returns a node by id.

func (*Service) IDByUID

func (s *Service) IDByUID(uid string) (uint, error)

IDByUID resolves a node's portable uid to its numeric id.

func (*Service) LearnSwarmNodeID added in v1.3.0

func (s *Service) LearnSwarmNodeID(id uint, swarmNodeID string)

LearnSwarmNodeID maps nodes joined by hand too; an unmapped node cannot be resolved from a service's task.

func (*Service) List

func (s *Service) List(ctx context.Context) ([]models.Server, error)

List returns all servers, refreshing the local node's live status.

func (*Service) MarkConnected

func (s *Service) MarkConnected(id uint, agentVersion string)

MarkConnected records that a node's agent connected.

func (*Service) MarkDisconnected

func (s *Service) MarkDisconnected(id uint)

MarkDisconnected records that a node's agent dropped.

func (*Service) MarkGatewayDeployed

func (s *Service) MarkGatewayDeployed(id uint)

MarkGatewayDeployed also clears imported-gateway tracking, since a fresh install supersedes an import.

func (*Service) NameBySwarmNodeID

func (s *Service) NameBySwarmNodeID(swarmNodeID string) string

NameBySwarmNodeID returns "" when no node carries the id; the caller falls back to a short id.

func (*Service) Placeable

func (s *Service) Placeable(serverID uint) error

Placeable: the local node (0) always is; reachability is enforced separately when the operation runs.

func (*Service) RegenerateToken

func (s *Service) RegenerateToken(id uint) (string, error)

RegenerateToken issues a fresh join token for a node, invalidating the old one.

func (*Service) RegisterClusterNode added in v1.3.0

func (s *Service) RegisterClusterNode(clusterID uint, swarmNodeID, hostname string) (*models.Server, error)

RegisterClusterNode is not open registration: the caller has verified the swarm node belongs to this swarm.

func (*Service) ReleaseGateway

func (s *Service) ReleaseGateway(id uint) (*models.Server, error)

ReleaseGateway stops tracking an imported gateway without touching the container; copied settings remain.

func (*Service) SetClusters added in v1.10.0

func (s *Service) SetClusters(r *repositories.ClusterRepository)

SetClusters wires cluster rows; nil leaves new nodes unassigned, which resolves to the default cluster.

func (*Service) SetConnectivity added in v1.10.0

func (s *Service) SetConnectivity(id uint, c models.ServerConnectivity) (*models.Server, error)

SetConnectivity changes only how a node's apps are served, leaving its other reachability settings alone.

func (*Service) SetCordoned

func (s *Service) SetCordoned(ctx context.Context, id uint, cordoned bool) error

SetCordoned mirrors to swarm availability; on mirror failure it saves anyway and returns ErrSwarmNotMirrored.

func (*Service) SetEngineVersion added in v1.9.6

func (s *Service) SetEngineVersion(swarmNodeID, version string) error

SetEngineVersion is keyed by swarm node id and column-scoped so it never clobbers concurrent agent-connect writes.

func (*Service) SetGatewayConfig

func (s *Service) SetGatewayConfig(id uint, config string) (*models.Server, error)

SetGatewayConfig stores a custom edge-gateway config; empty resets to the rendered default.

func (*Service) SetGatewayImage

func (s *Service) SetGatewayImage(id uint, image string) (*models.Server, error)

SetGatewayImage stores an edge-gateway image override; empty resets to the resolved default.

func (*Service) SetGatewayUpdate

func (s *Service) SetGatewayUpdate(id uint, p *models.GatewayUpdateProgress) error

SetGatewayUpdate persists safe-update progress (nil clears) so it survives a reconnect.

func (*Service) SetOrphanHandler added in v1.10.2

func (s *Service) SetOrphanHandler(fn func(serverID uint))

SetOrphanHandler wires the reconciler run after a node is deleted (nil-safe).

func (*Service) SetPool added in v1.10.0

func (s *Service) SetPool(id uint, pool string) (*models.Server, error)

SetPool assigns a node to a pool (empty for none); pool-bound plans place workloads only on that pool's nodes.

func (*Service) SetSwarmCordon added in v1.10.3

func (s *Service) SetSwarmCordon(fn func(ctx context.Context, serverID uint, cordoned bool) error)

SetSwarmCordon wires the swarm-availability mirror (nil-safe; nil leaves the cordon Miabi-side only).

func (*Service) SetSwarmNodeID

func (s *Service) SetSwarmNodeID(id uint, swarmNodeID string) error

SetSwarmNodeID is a no-op when unchanged, avoiding write churn on every cluster refresh.

func (*Service) StoredGatewayRedisPassword added in v1.10.10

func (s *Service) StoredGatewayRedisPassword(id uint) (string, error)

StoredGatewayRedisPassword returns the node's gateway Redis password without minting one

func (*Service) UpdateNode

func (s *Service) UpdateNode(id uint, in NodeInput) (*models.Server, error)

UpdateNode replaces credential fields only when non-empty, so an unchanged form keeps existing secrets.

func (*Service) WorkloadImpact

func (s *Service) WorkloadImpact(id uint) (apps int64, databases int64, err error)

Jump to

Keyboard shortcuts

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