Documentation
¶
Overview ¶
Package ports keeps the port table (Phase 26): every public TCP/UDP port on every load-balancer node it is served from, so a port is never given out twice on one node. Ports used by Traefik and the platform can never be taken. A port number may be reused on different load balancers (a project's own nodes and the shared one).
Index ¶
- Constants
- func Free(states []State, protocol string, port int, ...) error
- type Clash
- type ErrClash
- type ErrInvalid
- type Ledger
- func (l *Ledger) Check(ctx context.Context, o Owner, protocol string, port int, auto bool) ([]State, error)
- func (l *Ledger) CheckTarget(ctx context.Context, project string, target ingress.Target) ([]Clash, error)
- func (l *Ledger) Claims(o Owner, wants []Want) []store.PortClaim
- func (l *Ledger) Conflicts() []store.PortClaim
- func (l *Ledger) Lock()
- func (l *Ledger) Nodes(o Owner) []string
- func (l *Ledger) Pick(ctx context.Context, o Owner, protocol string, lo, hi int, skip map[int]bool) (int, error)
- func (l *Ledger) ReservedList() []Reserved
- func (l *Ledger) Run(ctx context.Context)
- func (l *Ledger) Sync(ctx context.Context) error
- func (l *Ledger) Table(ctx context.Context) ([]store.PortClaim, error)
- func (l *Ledger) Unlock()
- type Owner
- type Reserved
- type Source
- type State
- type Want
Constants ¶
const ControllerNode = "ctl-0"
ControllerNode is the controller's node name (mesh.ControllerNode): the shared load balancer always includes it.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Clash ¶
type Clash struct {
Node string `json:"node"`
Protocol string `json:"protocol"`
Port int `json:"port"`
OwnerKind string `json:"ownerKind"`
OwnerID string `json:"ownerId"`
}
Clash is a port another owner holds on a node.
type ErrClash ¶
type ErrClash struct{ Clashes []Clash }
ErrClash refuses an ingress change that would put two holders of a port on one node.
type ErrInvalid ¶
type ErrInvalid struct{ Err error }
ErrInvalid is a refused request (a bad, reserved or taken port).
func (ErrInvalid) Error ¶
func (e ErrInvalid) Error() string
func (ErrInvalid) Unwrap ¶
func (e ErrInvalid) Unwrap() error
type Ledger ¶
type Ledger struct {
// Target is who serves a project's public ports (nil: the shared
// load balancer for every project).
Target func(project string) ingress.Target
// the edge-pool nodes.
Shared func() []string
// Holders are ports something other than Traefik listens on, on one
// node ("tcp/25" -> process), from the agents' listener reports.
Holders func(node string) map[string]string
// Ranges are the automatic ranges (services, databases): kept for
// automatic use only.
Ranges [][2]int
// Sources list the existing public ports for the resync.
Sources []Source
// OnConflict runs for each port a resync could not claim on a node.
OnConflict func(c store.PortClaim)
// contains filtered or unexported fields
}
Ledger keeps the port table.
func (*Ledger) Check ¶
func (l *Ledger) Check(ctx context.Context, o Owner, protocol string, port int, auto bool) ([]State, error)
Check reports a port's state on every node an owner would claim it on. Ports the owner already holds are free for it.
func (*Ledger) CheckTarget ¶
func (l *Ledger) CheckTarget(ctx context.Context, project string, target ingress.Target) ([]Clash, error)
CheckTarget reports the ports a project would clash on if it were served by target (an ingress change, refused when it is not empty).
func (*Ledger) Claims ¶
Claims are an owner's rows for its ports on its nodes, after they have been checked; the caller writes them with its own settings.
func (*Ledger) Lock ¶
func (l *Ledger) Lock()
Lock serializes everything that picks or claims ports; the primary key is the last guard.
func (*Ledger) Pick ¶
func (l *Ledger) Pick(ctx context.Context, o Owner, protocol string, lo, hi int, skip map[int]bool) (int, error)
Pick returns the lowest port in lo–hi free for an owner on all its nodes (0: none), leaving out ports in skip (picked earlier in the same change).
func (*Ledger) ReservedList ¶
ReservedList is the fixed list plus the automatic ranges.
func (*Ledger) Sync ¶
Sync rewrites the table from the sources: each owner's ports on the nodes that serve them now (load balancers change as edge pools and project ingress change). A port that would get a second holder on a node stays with its older holder and is reported as a conflict.
type Owner ¶
type Owner struct {
Kind string // store.PortOwnerService | store.PortOwnerDatabase
ID string
// Project is the owner's project ("" for standalone databases): its
// load balancer decides the nodes.
Project string
// project chose (databases, Phase 18).
Shared bool
}
Owner is who holds a public port.
type Reserved ¶
type Reserved struct {
Protocol string `json:"protocol"` // tcp | udp | tcp+udp
Ports string `json:"ports"` // a number or LOW-HIGH
Reason string `json:"reason"`
}
Reserved is one row of the reserved list, for the dashboard.
type Source ¶
Source lists every public port that exists, by owner (the services' and the databases'), for the resync.
type State ¶
type State struct {
Node string `json:"node"`
State string `json:"state"` // free | reserved | host | taken
Reason string `json:"reason,omitempty"` // reserved: what for; host: the process
// Owner of a taken port (shown when the caller may see it).
OwnerKind string `json:"ownerKind,omitempty"`
OwnerID string `json:"ownerId,omitempty"`
PortName string `json:"portName,omitempty"`
}
State is a port's state on one node.