ports

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func Free

func Free(states []State, protocol string, port int, describe func(kind, id string) string) error

Free reports whether a port can be claimed by an owner (nil), or why not.

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.

func (ErrClash) Error

func (e ErrClash) Error() string

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
	// Shared are the nodes of the shared load balancer: the controller and
	// 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 New

func New(st *store.Store, log *slog.Logger) *Ledger

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

func (l *Ledger) Claims(o Owner, wants []Want) []store.PortClaim

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) Conflicts

func (l *Ledger) Conflicts() []store.PortClaim

Conflicts are the ports the last resync could not claim on a node.

func (*Ledger) Lock

func (l *Ledger) Lock()

Lock serializes everything that picks or claims ports; the primary key is the last guard.

func (*Ledger) Nodes

func (l *Ledger) Nodes(o Owner) []string

Nodes are the load-balancer nodes an owner's ports are claimed on.

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

func (l *Ledger) ReservedList() []Reserved

ReservedList is the fixed list plus the automatic ranges.

func (*Ledger) Run

func (l *Ledger) Run(ctx context.Context)

Run resyncs every minute (edge nodes come and go).

func (*Ledger) Sync

func (l *Ledger) Sync(ctx context.Context) error

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.

func (*Ledger) Table

func (l *Ledger) Table(ctx context.Context) ([]store.PortClaim, error)

Table is every claim.

func (*Ledger) Unlock

func (l *Ledger) Unlock()

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
	// Shared keeps the owner on the shared load balancer whatever its
	// 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

type Source func(ctx context.Context) map[Owner][]Want

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.

type Want

type Want struct {
	PortName string // the service's port, or rw/ro
	Protocol string // tcp | udp
	Port     int
	Mode     string // store.PortAuto | store.PortChosen
}

Want is one public port an owner holds or asks for.

Jump to

Keyboard shortcuts

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