Documentation
¶
Overview ¶
Package netlayout defines the reserved-IP layout strategy abstraction shared by Layer A (bootstrap subnet carving) and Layer B (vault reserved-ips population). A Layout answers "which named role gets which offset" for one strategy; callers select a strategy by name via Lookup or Default and never construct a Layout directly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrBandOverridePartial is returned when only one of a band override's // start/end is set (0). Both must be set together, or neither (the // caller skips ValidateBand entirely and uses the strategy's default // layout). ErrBandOverridePartial = errors.New("netlayout: band override start and end must both be set, or neither") // ErrBandOverrideStartTooLow is returned when start would collide with // the fixed named-IP slots below the historical available-band floor. ErrBandOverrideStartTooLow = errors.New("netlayout: band override start collides with reserved named-IP slots") // ErrBandOverrideEndNotAfterStart is returned when end does not fall // strictly after start. ErrBandOverrideEndNotAfterStart = errors.New("netlayout: band override end must be greater than start") // ErrBandOverrideEndBeyondSubnet is returned when end falls outside // cidr's usable address range. ErrBandOverrideEndBeyondSubnet = errors.New("netlayout: band override end is beyond the subnet's usable address range") // ErrInvalidCIDR is returned when ValidateBand cannot parse cidr as an // IPv4 CIDR. ErrInvalidCIDR = errors.New("netlayout: invalid CIDR") // ErrBandOverrideCollidesStatic is returned when a mgmt/ocf band // override's [start,end] range contains a named static's offset from // either tier, on any subnet index. Named statics from both tiers // share one physical address space per workload subnet, so an // override handed to one tier's dynamic allocator must not reach a // fixed IP the other tier's kit already reads unconditionally. ErrBandOverrideCollidesStatic = errors.New("netlayout: band override collides with a named static") // ErrBandOverrideCrossTier is returned when a mgmt/ocf band // override's [start,end] range intersects the OTHER tier's own // available band (open bands closed at the subnet's last usable // offset) on any subnet index, so the two directors' cloud-config // allocators would never race for the same dynamic IP. ErrBandOverrideCrossTier = errors.New("netlayout: band override intersects the other tier's available band") )
Sentinel errors for ValidateBand's available-band override checks. Callers match with errors.Is. These port the historical internal/bootstrap.applyAvailableBandOverride sentinels of the same shape (ErrBandOverridePartial/StartTooLow/EndNotAfterStart/EndBeyondSubnet) into this package, since ValidateBand now owns that validation.
var ( ErrOffsetCollision = errors.New("netlayout: static offset collision") ErrBandOverlap = errors.New("netlayout: band overlap or coverage error") ErrHaproxyCoupling = errors.New("netlayout: haproxy must sit at ocf band start + 1 (the cf kit claims its static window from inside the available band)") ErrPrefixTooNarrow = errors.New("netlayout: min_prefix does not fit the definition's highest offset") ErrBadPinning = errors.New("netlayout: invalid subnet pinning") // ErrDuplicateIPKey rejects two statics in one tier resolving to the // same output key (ip_key, or role+"_ip" when unset). The key is how // every downstream lookup — Layer A outputs, Layer B records, // PinnedWorkloadIndex — identifies a static; a duplicate would make // those lookups depend on map iteration order. ErrDuplicateIPKey = errors.New("netlayout: duplicate reserved-IP output key") )
Sentinel errors for validateDefinition's semantic checks (offset/pinning, collisions, band coverage and overlap, the haproxy/CF-kit coupling, and min_prefix fit). Callers match with errors.Is; the wrapped message names def.Source, def.Name, and the offending values.
var ErrInvalidDefinition = errors.New("netlayout: invalid strategy definition")
ErrInvalidDefinition is the sentinel every structural load failure wraps. Callers match with errors.Is; the wrapped message names the source file, the strategy (when known), and the failed rule.
var ErrNoMgmtTier = errors.New("netlayout: strategy defines no mgmt tier")
ErrNoMgmtTier is the sentinel LayerASlots wraps when the "ocfp" role is asked of a strategy whose definition declares no mgmt tier: the ocfp role's Layer A layout is derived entirely from that tier, so there is nothing to report. Callers match it with errors.Is.
var ErrNotImplemented = errors.New("netlayout: not implemented")
ErrNotImplemented is returned by stub Layout methods that have not yet been given a real implementation for the calling strategy. Its existence means an accidental early invocation — a misordered test, a future task that jumps the gun — fails loudly with a greppable error instead of a nil-dereference panic or a silently-wrong empty result.
var ErrSchemeCollision = errors.New("netlayout: scheme_version conflicts with an already-registered strategy")
ErrSchemeCollision is the sentinel Catalog.add wraps when a BYO strategy definition's scheme_version collides with an already-registered strategy's — a built-in's, or an earlier BYO file loaded into the same catalog. Two strategies sharing a scheme_version would make the stamped guard value ambiguous about which strategy actually produced a bloc's addresses. Callers match it with errors.Is.
var ErrStrategyShadowed = errors.New("netlayout: strategy name conflicts with an already-registered strategy")
ErrStrategyShadowed is the sentinel Catalog.add wraps when a BYO strategy definition's name collides with an already-registered strategy — a built-in, or an earlier BYO file loaded into the same catalog. Callers match it with errors.Is.
var ErrSubnetTooSmall = errors.New("subnet too small for strategy")
ErrSubnetTooSmall is the sentinel ValidateSubnet wraps when cidr's prefix is longer (fewer host addresses) than a strategy's MinPrefix requires. Callers match it with errors.Is.
var ErrTooFewSubnets = errors.New("netlayout: too few workload subnets for strategy")
ErrTooFewSubnets is the sentinel ValidateSubnetSet wraps when fewer cidrs are given than a strategy's MinSubnets requires. Callers match it with errors.Is.
var ErrUnknownRole = errors.New("unknown netlayout role")
ErrUnknownRole is the sentinel LayerASlots wraps when asked for a role that is neither "infra" nor "ocfp". Callers match it with errors.Is.
var ErrUnknownStrategy = errors.New("unknown network strategy")
ErrUnknownStrategy is the sentinel Lookup wraps when asked for a strategy name that is not registered. Callers match it with errors.Is. Every caller resolves it through a *Catalog (see Catalog.unknownError in catalog.go) — Lookup, Default, and the package-level registry are all thin wrappers over Builtins(), a *Catalog scoped to the three built-in strategies.
Functions ¶
func Compile ¶
func Compile(def Definition) (*compiledLayout, error)
Compile validates def and builds its workload table once. The returned *compiledLayout answers WorkloadTable from that precomputed table rather than rebuilding it per call.
func DefaultNameFor ¶
DefaultNameFor returns the strategy name an empty network.strategy resolves to for the given provider and subnet strategy. AWS always spans (its VPC subnets are separate address spaces, like PVE's per-workload-subnet /22s, but AWS has no wide/compact-sized single subnet to colocate onto). STACKIT shares one address space across its workload subnets under the triple layout, so only its triple subnet strategy needs spanning; the single-subnet layout colocates like PVE's default. Every other provider (including PVE and the empty/unset default) colocates onto "wide".
The provider match is case-insensitive: config validation accepts a provider in any case (internal/config validates with strings.EqualFold) and never normalizes the stored value, so "AWS" must resolve to the same default "aws" does rather than falling through to "wide".
Types ¶
type BandPlacement ¶
type BandPlacement struct {
Start int `yaml:"start"`
End int `yaml:"end"`
Subnets []int `yaml:"subnets"`
}
BandPlacement is one available-band entry. End 0 means open-ended (to the subnet's last usable host); Subnets nil means every subnet index.
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is a name-keyed set of Layouts available for selection: the built-in strategies (wide, compact, spanning), optionally extended with operator-supplied BYO definitions loaded from network.strategyPaths. Callers obtain one via Builtins or BuildCatalog and never construct a Catalog directly.
func BuildCatalog ¶
BuildCatalog returns a Catalog containing the built-in strategies plus every strategy definition loaded from paths. A relative entry in paths is resolved against baseDir (the directory containing the config file that declared network.strategyPaths). Each path may name a single strategy file or a directory, in which case every "*.yml"/"*.yaml" file inside it (sorted) is loaded. A BYO strategy whose name or scheme_version collides with an already-registered strategy (built-in or earlier BYO file) fails the whole load with ErrStrategyShadowed or ErrSchemeCollision — a silent shadow would let one operator-facing strategy name resolve to different definitions depending on load order.
func Builtins ¶
func Builtins() *Catalog
Builtins returns a fresh Catalog containing only the embedded built-in strategies (wide, compact, spanning). Each call builds a new Catalog from builtinLayouts, so callers can never observe or cause mutation of a shared instance.
func (*Catalog) Lookup ¶
Lookup resolves name to a Layout registered in this catalog. Unlike the package-level Lookup, an empty name is an error: callers resolve the provider/subnet-strategy default (see DefaultNameFor) to a concrete name before calling Lookup, so an empty name reaching here is a caller bug.
type Definition ¶
type Definition struct {
Name string
Description string
SchemeVersion string
Placement Placement
MinPrefix int
MinSubnets int
Tiers map[Tier]TierDef
// Source records where the definition came from (file path or
// "built-in") for error messages.
Source string
}
Definition is the declarative form of one reserved-IP strategy — the single representation shared by built-ins (embedded YAML) and operator BYO files. Reserved complements are never part of a Definition; the compiler derives them (see buildWorkloadTable).
func LoadDefinition ¶
func LoadDefinition(data []byte, source string) (Definition, error)
LoadDefinition parses one YAML strategy definition and applies the structural rules (fields present, placement recognized, min_subnets consistent with placement). Semantic rules (collisions, band overlaps, min_prefix fit) belong to Compile.
type LayerASlots ¶
type LayerASlots struct {
Named []NamedSlot
AvailableA int
AvailableB int
ReservedB int
ReservedC int
}
LayerASlots is the Layer A slot set for one (role, subnet index).
type Layout ¶
type Layout interface {
// Name returns the strategy's registry key, e.g. "wide" or "compact".
Name() string
// SchemeVersion returns the guard-stamped scheme identity written
// beside a bloc's reserved-ips record, e.g. "2" or "3-compact".
SchemeVersion() string
// Placement returns how the strategy distributes roles across a bloc's
// workload subnets (colocated or spanning).
Placement() Placement
// MinPrefix returns the minimum CIDR prefix length (e.g. 25, 26) this
// strategy fits in.
MinPrefix() int
// MinSubnets returns the minimum number of workload subnets this
// strategy needs (1 for colocated placements).
MinSubnets() int
// WorkloadTable returns the Layer B assignment table for cidr.
// Strategies whose table does not vary by subnet size may ignore cidr.
WorkloadTable(cidr string) (reservedip.AssignmentTable, error)
// LayerASlots returns the Layer A named-slot set for role ("infra" or
// "ocfp") on cidr at workload-subnet index idx. A negative idx means
// "no workload position" (the infra subnet, or a single-subnet
// layout): only placements that apply to every index are returned.
LayerASlots(role, cidr string, idx int) (LayerASlots, error)
// ValidateSubnet returns an error if cidr is too small for this
// strategy's highest fixed offset.
ValidateSubnet(cidr string) error
// ValidateSubnetSet returns an error if cidrs holds fewer subnets than
// this strategy needs, or if any non-empty entry fails ValidateSubnet.
// An empty entry (a CIDR the provider assigns later) counts toward the
// subnet floor but is not size-checked.
ValidateSubnetSet(cidrs []string) error
// ValidateBand returns an error if [start,end] is not a valid
// override band for tier on cidr.
ValidateBand(tier Tier, cidr string, start, end int) error
// PinnedWorkloadIndex returns the workload-subnet index the mgmt-tier
// static identified by its Layer A output key (ip_key, or role+"_ip"
// when ip_key is unset) is pinned to. ok is false when the key is
// unknown, the static is unpinned (present on every index), it is
// pinned to more than one index, or the strategy has no mgmt tier.
PinnedWorkloadIndex(ipKey string) (idx int, ok bool)
}
Layout describes one reserved-IP numbering strategy. Every implementation is a *compiledLayout built from a Definition (see compiled.go); callers obtain one via Lookup or Default and never construct a Layout directly.
func Lookup ¶
Lookup resolves name to a registered built-in Layout (see Builtins). An empty name resolves to Default. An unrecognized name returns ErrUnknownStrategy wrapping name. Lookup only ever sees the three built-in strategies: operator BYO strategies loaded from network.strategyPaths are resolved through a *Catalog instead (see BuildCatalog and Config.ResolveReservedIPLayout), never through this package-level built-ins-only registry.
type NamedSlot ¶
NamedSlot is one Layer A named static: Key is the full state-output stem ("bastion_ip", or an ip_key like "rustfs_ip_smoke").
type Placement ¶
type Placement string
Placement identifies how a strategy distributes roles across a bloc's workload subnets: colocated replicates the full table on every subnet; spanning pins roles to specific subnet indices.
type StaticPlacement ¶
StaticPlacement places one named role at a fixed offset. Subnets nil means "every subnet index"; IPKey overrides the default "{role}_ip" output key (see reservedip.Assignment.IPKey).
func (*StaticPlacement) UnmarshalYAML ¶
func (s *StaticPlacement) UnmarshalYAML(data []byte) error
UnmarshalYAML accepts either a bare integer offset or the mapping form {offset, subnets, ip_key}.
type TierDef ¶
type TierDef struct {
Statics map[string]StaticPlacement
Available []BandPlacement
}
TierDef is one tier's placements within a Definition.