allocator

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package allocator provides CIDR allocation functionality for Kubernetes nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPoolExhausted is returned when no more CIDRs are available for allocation.
	ErrPoolExhausted = errors.New("CIDR pool exhausted")
	// ErrInvalidMaskSize is returned when the mask size is invalid for the given pool.
	ErrInvalidMaskSize = errors.New("invalid mask size for pool")
)

Functions

func ParseCIDRs

func ParseCIDRs(cidrs []string) ([]*net.IPNet, error)

ParseCIDRs parses a slice of CIDR strings into net.IPNet objects.

Types

type Allocator

type Allocator struct {
	// contains filtered or unexported fields
}

Allocator manages CIDR allocation from configured pools.

func NewAllocator

func NewAllocator(ipv4Pools, ipv6Pools []*net.IPNet, ipv4MaskSize, ipv6MaskSize int) (*Allocator, error)

NewAllocator creates a new CIDR allocator with the given pools and mask sizes. Returns an error if the mask sizes are invalid for the given pools.

func (*Allocator) AllocateIPv4

func (a *Allocator) AllocateIPv4() (string, error)

AllocateIPv4 allocates the next available IPv4 CIDR from the pools. Returns ErrPoolExhausted if no CIDRs are available.

func (*Allocator) AllocateIPv6

func (a *Allocator) AllocateIPv6() (string, error)

AllocateIPv6 allocates the next available IPv6 CIDR from the pools. Returns ErrPoolExhausted if no CIDRs are available.

func (*Allocator) ContainsCIDR

func (a *Allocator) ContainsCIDR(cidr string) bool

ContainsCIDR returns true if the given CIDR falls within any of the allocator's pools.

func (*Allocator) DebugState

func (a *Allocator) DebugState() AllocatorDebugState

DebugState returns a snapshot of the allocator's internal state.

func (*Allocator) HasIPv4Pools

func (a *Allocator) HasIPv4Pools() bool

HasIPv4Pools returns true if IPv4 pools are configured.

func (*Allocator) HasIPv6Pools

func (a *Allocator) HasIPv6Pools() bool

HasIPv6Pools returns true if IPv6 pools are configured.

func (*Allocator) IsAllocated

func (a *Allocator) IsAllocated(cidr string) bool

IsAllocated checks if a CIDR is already allocated.

func (*Allocator) MarkAllocated

func (a *Allocator) MarkAllocated(cidr string)

MarkAllocated marks a CIDR as already allocated. This should be called for all existing node podCIDRs during startup.

func (*Allocator) Release

func (a *Allocator) Release(cidr string)

Release marks a CIDR as no longer allocated, freeing it for future use. This should be called when a node is deleted.

func (*Allocator) Reset

func (a *Allocator) Reset()

Reset clears all allocation state. This should be called before re-initializing the allocator when becoming leader to ensure we have a fresh state.

type AllocatorDebugState

type AllocatorDebugState struct {
	IPv4Pools      []string `json:"ipv4Pools"`
	IPv6Pools      []string `json:"ipv6Pools"`
	IPv4MaskSize   int      `json:"ipv4MaskSize"`
	IPv6MaskSize   int      `json:"ipv6MaskSize"`
	AllocatedCount int      `json:"allocatedCount"`
	AllocatedCIDRs []string `json:"allocatedCIDRs"`
}

AllocatorDebugState contains a snapshot of allocator internal state.

Jump to

Keyboard shortcuts

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