Documentation
¶
Overview ¶
Package netalloc hands out non-overlapping subnets, carved from a single platform pool, for every Docker network Miabi creates. It works around Docker's tiny built-in default-address-pools by allocating an explicit /N per network. A DB ledger is the source of truth, so allocations survive restarts.
Index ¶
- Variables
- type NetworkProvisioner
- type Service
- func (s *Service) Allocate(dockerName string, nodeID uint, kind string) (*models.NetworkAllocation, error)
- func (s *Service) Capacity() int
- func (s *Service) EnsureManaged(ctx context.Context, dc NetworkProvisioner, spec docker.NetworkSpec, ...) (id, subnet string, err error)
- func (s *Service) ImportExisting(ctx context.Context, dc NetworkProvisioner, nodeID uint) error
- func (s *Service) PublishStats()
- func (s *Service) Release(dockerName string) error
- func (s *Service) Stats() (used int, total int)
Constants ¶
This section is empty.
Variables ¶
var ErrPoolExhausted = errors.New("network subnet pool exhausted")
ErrPoolExhausted is returned when every subnet in the pool is allocated or reserved. The operator must enlarge MIABI_NETWORK_POOL_CIDR.
Functions ¶
This section is empty.
Types ¶
type NetworkProvisioner ¶
type NetworkProvisioner interface {
EnsureNetworkSpec(ctx context.Context, spec docker.NetworkSpec) (string, error)
ListNetworks(ctx context.Context) ([]docker.Network, error)
}
NetworkProvisioner is the subset of docker.Client the allocator drives — kept small so both the full client and narrower service-level interfaces (e.g. the stack service's NetworkManager) satisfy it.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service allocates subnets from the configured pool.
func NewService ¶
func NewService(repo *repositories.NetworkAllocationRepository, poolCIDR string, subnetPrefix int) (*Service, error)
NewService builds the allocator for an IPv4 pool CIDR and a per-network subnet prefix. Returns an error on an invalid or IPv6 pool, or a prefix that doesn't fit inside it — config.validate catches these first at boot, so this is defence in depth.
func (*Service) Allocate ¶
func (s *Service) Allocate(dockerName string, nodeID uint, kind string) (*models.NetworkAllocation, error)
Allocate reserves a subnet for dockerName idempotently: an existing allocation for the same name is returned unchanged, otherwise the lowest-index free subnet is reserved and persisted. Callers that create the Docker network should prefer EnsureManaged, which also handles host-level overlaps.
func (*Service) EnsureManaged ¶
func (s *Service) EnsureManaged(ctx context.Context, dc NetworkProvisioner, spec docker.NetworkSpec, nodeID uint, kind string) (id, subnet string, err error)
func (*Service) ImportExisting ¶
ImportExisting reserves any pool subnet already in use by a Docker network on the node, so the allocator never hands out an overlapping one. Best-effort and idempotent — called at boot. Networks Miabi already tracks are skipped.
func (*Service) PublishStats ¶
func (s *Service) PublishStats()
PublishStats updates the Prometheus pool-utilization gauges. Called after every mutation so /metrics reflects the current usage without a background loop.