pub struct NodeSliceAllocator { /* private fields */ }Expand description
Leader-side allocator that carves per-node slices out of a cluster CIDR.
Used to fix the latent IP-collision bug where every agent independently
allocated container IPs from the full cluster /16. With a NodeSliceAllocator
the leader hands each joining node its own non-overlapping slice, and the
agent-local IpAllocator is bounded to that slice.
Slice assignment is deterministic within a leader process: the node ID hashes
to a candidate slice index; collisions are resolved by linear probing forward
until a free slot is found. Existing assignments are preserved across leader
restart via snapshot() / restore().
Implementations§
Source§impl NodeSliceAllocator
impl NodeSliceAllocator
Sourcepub fn new(cluster_cidr: IpNet, slice_prefix: u8) -> Result<Self>
pub fn new(cluster_cidr: IpNet, slice_prefix: u8) -> Result<Self>
Create a new slice allocator that carves /slice_prefix-sized slices
out of cluster_cidr.
§Errors
Returns OverlayError::InvalidCidr if slice_prefix is not strictly
more specific than cluster_cidr.prefix_len(), or if it exceeds the
address family’s maximum prefix length.
Sourcepub fn assign(&mut self, node_id: &str) -> Result<IpNet>
pub fn assign(&mut self, node_id: &str) -> Result<IpNet>
Assign (or return an existing) slice for node_id.
Idempotent: calling assign with a node ID that already has a slice
returns the existing slice without re-assigning.
§Errors
Returns OverlayError::NoAvailableIps if every slice in the cluster
CIDR is already assigned.
Sourcepub fn release(&mut self, node_id: &str) -> bool
pub fn release(&mut self, node_id: &str) -> bool
Release node_id’s slice back to the free pool.
Returns true if a slice was released, false if the node was not assigned.
Sourcepub fn slice_for(&self, node_id: &str) -> Option<IpNet>
pub fn slice_for(&self, node_id: &str) -> Option<IpNet>
Look up a node’s assigned slice without mutating state.
Sourcepub fn assigned_count(&self) -> usize
pub fn assigned_count(&self) -> usize
Number of currently-assigned slices.
Sourcepub fn capacity(&self) -> u64
pub fn capacity(&self) -> u64
Total number of slices the cluster CIDR can hold at the configured slice prefix.
Sourcepub fn cluster_cidr(&self) -> IpNet
pub fn cluster_cidr(&self) -> IpNet
Cluster CIDR the allocator operates over.
Sourcepub fn slice_prefix(&self) -> u8
pub fn slice_prefix(&self) -> u8
Slice prefix length (e.g. 28 for /28 slices).
Sourcepub fn snapshot(&self) -> NodeSliceAllocatorSnapshot
pub fn snapshot(&self) -> NodeSliceAllocatorSnapshot
Build a persistable snapshot for durable leader state.
Sourcepub fn restore(snapshot: NodeSliceAllocatorSnapshot) -> Result<Self>
pub fn restore(snapshot: NodeSliceAllocatorSnapshot) -> Result<Self>
Rebuild an allocator from a snapshot.
§Errors
Returns OverlayError::InvalidCidr if the snapshot’s CIDR or any
assigned slice fails to parse, or if the slice prefix is inconsistent.
Trait Implementations§
Source§impl Clone for NodeSliceAllocator
impl Clone for NodeSliceAllocator
Source§fn clone(&self) -> NodeSliceAllocator
fn clone(&self) -> NodeSliceAllocator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more