Documentation
¶
Overview ¶
Package node manages Docker host (server) records and their reachability.
Index ¶
- Constants
- Variables
- func AppAlias(app *models.Application) string
- func CanaryAlias(app *models.Application) string
- func NewAppAlias(token string, appID uint) string
- func PublicIP(raw string) string
- func ResolveAppNetwork(ctx context.Context, dc docker.Client, configured string) string
- func SetAppNetwork(name string)
- type NodeInput
- type NodeLimitError
- type Service
- func (s *Service) AdoptGateway(id uint, container, image, configYAML string) (*models.Server, error)
- func (s *Service) Authenticate(token string) (*models.Server, error)
- func (s *Service) AuthenticateProvider(slug, token string) (*models.Server, error)
- func (s *Service) Bootstrap(ctx context.Context, endpoint string)
- func (s *Service) CreateNode(in NodeInput) (*models.Server, string, error)
- func (s *Service) DeleteNode(id uint) error
- func (s *Service) FindBySwarmNodeID(swarmNodeID string) (*models.Server, error)
- func (s *Service) GatewayRedisPassword(id uint) (string, error)
- func (s *Service) GatewayToken(id uint) (string, error)
- func (s *Service) Get(id uint) (*models.Server, error)
- func (s *Service) IDByUID(uid string) (uint, error)
- func (s *Service) LearnSwarmNodeID(id uint, swarmNodeID string)
- func (s *Service) List(ctx context.Context) ([]models.Server, error)
- func (s *Service) MarkConnected(id uint, agentVersion string)
- func (s *Service) MarkDisconnected(id uint)
- func (s *Service) MarkGatewayDeployed(id uint)
- func (s *Service) NameBySwarmNodeID(swarmNodeID string) string
- func (s *Service) Placeable(serverID uint) error
- func (s *Service) RegenerateToken(id uint) (string, error)
- func (s *Service) RegisterClusterNode(clusterID uint, swarmNodeID, hostname string) (*models.Server, error)
- func (s *Service) ReleaseGateway(id uint) (*models.Server, error)
- func (s *Service) SetClusters(r *repositories.ClusterRepository)
- func (s *Service) SetConnectivity(id uint, c models.ServerConnectivity) (*models.Server, error)
- func (s *Service) SetCordoned(ctx context.Context, id uint, cordoned bool) error
- func (s *Service) SetEngineVersion(swarmNodeID, version string) error
- func (s *Service) SetGatewayConfig(id uint, config string) (*models.Server, error)
- func (s *Service) SetGatewayImage(id uint, image string) (*models.Server, error)
- func (s *Service) SetGatewayUpdate(id uint, p *models.GatewayUpdateProgress) error
- func (s *Service) SetNodeLimit(fn func() int)
- func (s *Service) SetOrphanHandler(fn func(serverID uint))
- func (s *Service) SetPool(id uint, pool string) (*models.Server, error)
- func (s *Service) SetSwarmCordon(fn func(ctx context.Context, serverID uint, cordoned bool) error)
- func (s *Service) SetSwarmNodeID(id uint, swarmNodeID string) error
- func (s *Service) StoredGatewayRedisPassword(id uint) (string, error)
- func (s *Service) UpdateNode(id uint, in NodeInput) (*models.Server, error)
- func (s *Service) WorkloadImpact(id uint) (apps int64, databases int64, err error)
Constants ¶
const IngressOverlay = "miabi-ingress"
IngressOverlay carries only gateway-to-VIP traffic, so workspace east-west isolation is unaffected.
Variables ¶
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)") )
var AppNetwork = stack.DefaultNetwork
AppNetwork is the gateway network Goma and app containers join; set once at startup via MIABI_PROXY_NETWORK.
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 ¶
NewAppAlias builds a fresh stable alias for a newly created app.
func PublicIP ¶ added in v1.10.0
PublicIP returns "" for non-routable addresses; raw may carry a port, which is stripped.
func ResolveAppNetwork ¶ added in v1.10.13
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 NodeLimitError ¶
type NodeLimitError struct{ Limit int }
NodeLimitError carries a stable Code() so the API surfaces NODE_LIMIT_REACHED with an upgrade-oriented message.
func (*NodeLimitError) Code ¶
func (e *NodeLimitError) Code() string
func (*NodeLimitError) Error ¶
func (e *NodeLimitError) Error() string
func (*NodeLimitError) Message ¶
func (e *NodeLimitError) Message() string
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) AuthenticateProvider ¶
AuthenticateProvider accepts the agent join token or the gateway token; the URL slug must match the node.
func (*Service) Bootstrap ¶
Bootstrap is non-fatal when Docker is unreachable, so the API can still serve.
func (*Service) CreateNode ¶
CreateNode returns a one-time join token for agent mode (only its hash is stored).
func (*Service) DeleteNode ¶
DeleteNode removes a remote node record.
func (*Service) FindBySwarmNodeID ¶ added in v1.3.0
FindBySwarmNodeID resolves the node backing a swarm node id.
func (*Service) GatewayRedisPassword ¶
GatewayRedisPassword mints on first use and stays stable so gateway and Redis credentials keep matching.
func (*Service) GatewayToken ¶
GatewayToken mints on first use; unlike the join token it is recoverable, so the gateway can be redeployed.
func (*Service) LearnSwarmNodeID ¶ added in v1.3.0
LearnSwarmNodeID maps nodes joined by hand too; an unmapped node cannot be resolved from a service's task.
func (*Service) MarkConnected ¶
MarkConnected records that a node's agent connected.
func (*Service) MarkDisconnected ¶
MarkDisconnected records that a node's agent dropped.
func (*Service) MarkGatewayDeployed ¶
MarkGatewayDeployed also clears imported-gateway tracking, since a fresh install supersedes an import.
func (*Service) NameBySwarmNodeID ¶
NameBySwarmNodeID returns "" when no node carries the id; the caller falls back to a short id.
func (*Service) Placeable ¶
Placeable: the local node (0) always is; reachability is enforced separately when the operation runs.
func (*Service) RegenerateToken ¶
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 ¶
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
SetConnectivity changes only how a node's apps are served, leaving its other reachability settings alone.
func (*Service) SetCordoned ¶
SetCordoned mirrors to swarm availability; on mirror failure it saves anyway and returns ErrSwarmNotMirrored.
func (*Service) SetEngineVersion ¶ added in v1.9.6
SetEngineVersion is keyed by swarm node id and column-scoped so it never clobbers concurrent agent-connect writes.
func (*Service) SetGatewayConfig ¶
SetGatewayConfig stores a custom edge-gateway config; empty resets to the rendered default.
func (*Service) SetGatewayImage ¶
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) SetNodeLimit ¶
SetNodeLimit's closure is re-evaluated per registration so license changes apply without restart; nil or negative is unlimited.
func (*Service) SetOrphanHandler ¶ added in v1.10.2
SetOrphanHandler wires the reconciler run after a node is deleted (nil-safe).
func (*Service) SetPool ¶ added in v1.10.0
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
SetSwarmCordon wires the swarm-availability mirror (nil-safe; nil leaves the cordon Miabi-side only).
func (*Service) SetSwarmNodeID ¶
SetSwarmNodeID is a no-op when unchanged, avoiding write churn on every cluster refresh.
func (*Service) StoredGatewayRedisPassword ¶ added in v1.10.10
StoredGatewayRedisPassword returns the node's gateway Redis password without minting one
func (*Service) UpdateNode ¶
UpdateNode replaces credential fields only when non-empty, so an unchanged form keeps existing secrets.