Documentation
¶
Index ¶
- Variables
- func BuildBitmap(pool PoolState) ([]bool, uint32, error)
- func CountIPsInRange(start, end string) (int32, error)
- func EnumerateIPs(start, end string) ([]string, error)
- func FormatCIDR(start, end string) string
- func IPToUint32(ip net.IP) uint32
- func ParseCIDR(cidr string) (start net.IP, end net.IP, count int32, err error)
- func ParseIPRange(rangeStr string) (start, end string, err error)
- func PoolCapacityInfo(pool PoolState) (totalIPs int32, allocatedIPs int32, availableIPs int32, err error)
- func SortPoolRefsByPriority(refs []PoolRef)
- func Uint32ToIP(n uint32) net.IP
- func ValidateCIDRContains(outer, inner string) (bool, error)
- func ValidatePoolSpec(cidr string, reservedCIDRs []string, allocStart, allocEnd string) []string
- func ValidateRangeWithinCIDR(cidr, start, end string) (bool, error)
- type AllocatedRange
- type AllocationResult
- type FragmentationInfo
- type FreeBlock
- type PoolRef
- type PoolState
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPoolExhausted indicates no contiguous block of the requested size is available. ErrPoolExhausted = errors.New("pool exhausted: no contiguous block available") // ErrInvalidCIDR indicates an unparseable CIDR string. ErrInvalidCIDR = errors.New("invalid CIDR notation") // ErrInvalidRange indicates start IP is after end IP. ErrInvalidRange = errors.New("invalid IP range: start is after end") // ErrOutOfRange indicates the requested range falls outside the pool. ErrOutOfRange = errors.New("range falls outside pool boundaries") )
Functions ¶
func BuildBitmap ¶
BuildBitmap creates a bitmap representing the allocatable range. true = used/reserved, false = free.
func CountIPsInRange ¶
CountIPsInRange returns the number of IPs between start and end (inclusive).
func EnumerateIPs ¶
EnumerateIPs returns all IPs between start and end (inclusive).
func FormatCIDR ¶
FormatCIDR returns CIDR notation if the range is power-of-2 aligned, otherwise returns "start-end" format.
func IPToUint32 ¶
IPToUint32 converts a 4-byte IPv4 address to a uint32.
func ParseCIDR ¶
ParseCIDR parses a CIDR string and returns the first IP, last IP, and total host count.
func ParseIPRange ¶
ParseIPRange parses a range string that could be either CIDR notation or "start-end" format.
func PoolCapacityInfo ¶
func PoolCapacityInfo(pool PoolState) (totalIPs int32, allocatedIPs int32, availableIPs int32, err error)
PoolCapacityInfo computes capacity information for a pool.
func SortPoolRefsByPriority ¶
func SortPoolRefsByPriority(refs []PoolRef)
SortPoolRefsByPriority sorts pool references by priority (lower = higher priority). Stable sort preserves order for equal priorities.
func Uint32ToIP ¶
Uint32ToIP converts a uint32 to a 4-byte IPv4 address.
func ValidateCIDRContains ¶
ValidateCIDRContains checks if the inner CIDR is completely contained within the outer CIDR.
func ValidatePoolSpec ¶
ValidatePoolSpec validates the internal consistency of a network pool specification.
func ValidateRangeWithinCIDR ¶
ValidateRangeWithinCIDR checks if a start-end range is within a CIDR.
Types ¶
type AllocatedRange ¶
AllocatedRange represents a contiguous block of allocated IPs.
type AllocationResult ¶
type AllocationResult struct {
Start string
End string
CIDR string // CIDR notation if power-of-2 aligned, otherwise "start-end"
Addresses []string
Count int32
}
AllocationResult contains the result of a successful allocation.
func AllocatePinnedRange ¶
func AllocatePinnedRange(pool PoolState, start, end string) (*AllocationResult, error)
AllocatePinnedRange validates and allocates a specific IP range. Returns an error if the range is outside the pool, overlaps reserved ranges, or conflicts with existing allocations.
func AllocateRange ¶
func AllocateRange(pool PoolState, requestedCount int32) (*AllocationResult, error)
AllocateRange finds the best-fit contiguous block of the requested size. Best-fit selects the smallest free block that satisfies the request, minimizing fragmentation.
type FragmentationInfo ¶
type FragmentationInfo struct {
FragmentationPercent int32
LargestFreeBlock int32
FreeBlockCount int32
TotalFreeIPs int32
}
FragmentationInfo contains pool health metrics.
func ComputeFragmentation ¶
func ComputeFragmentation(pool PoolState) (*FragmentationInfo, error)
ComputeFragmentation calculates pool health metrics from a bitmap.
type PoolState ¶
type PoolState struct {
// AllocatableStart is the first IP available for tenant allocation.
AllocatableStart string
// AllocatableEnd is the last IP available for tenant allocation.
AllocatableEnd string
// ReservedCIDRs are CIDR ranges excluded from allocation (e.g., management cluster IPs).
ReservedCIDRs []string
// ExistingAllocs are currently allocated ranges.
ExistingAllocs []AllocatedRange
}
PoolState represents the current state of a network pool for allocation purposes. It decouples the allocator from Kubernetes types.