netalloc

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package netalloc hands out non-overlapping subnets, carved from a single platform pool (MIABI_NETWORK_POOL_CIDR), for every Docker network Miabi creates. It works around Docker's tiny built-in default-address-pools: instead of letting the daemon subnet the pool (which exhausts with "all predefined address pools have been fully subnetted"), Miabi allocates an explicit /N per network and passes it as IPAM. A DB ledger (models.NetworkAllocation) is the source of truth, so allocations survive restarts and are unique platform-wide.

Index

Constants

This section is empty.

Variables

View Source
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 (e.g. "10.64.0.0/12") and a per-network subnet prefix (e.g. 24). 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) Capacity

func (s *Service) Capacity() int

Capacity is the total number of subnets the pool can hold.

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

func (s *Service) ImportExisting(ctx context.Context, dc NetworkProvisioner, nodeID uint) error

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.

func (*Service) Release

func (s *Service) Release(dockerName string) error

Release frees the allocation for a removed network so its subnet returns to the pool. Idempotent.

func (*Service) Stats

func (s *Service) Stats() (used int, total int)

Stats reports pool utilization (used includes reserved rows).

Jump to

Keyboard shortcuts

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