ipam

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package IPAM provides IPv4 address allocation against the mesh database.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoNetwork is returned when no network is configured.
	ErrNoNetwork = fmt.Errorf("no network configured")
	// ErrNoStorage is returned when no storage is configured.
	ErrNoStorage = fmt.Errorf("no storage configured")
)

Functions

This section is empty.

Types

type Allocator

type Allocator interface {
	// Allocate allocates an IP address for the given node ID.
	Allocate(ctx context.Context, nodeID meshtypes.NodeID) (netip.Prefix, error)
	// Locker returns the underlying Locker. Locks should be acquired before
	// calls to allocate. They are provided as separate methods to ensure
	// the caller has time to write the allocation to the DB. Allocate simply
	// observes the current state and respond with an available address.
	Locker() Locker
}

Allocator is the interface for an IPAM allocator.

func NewAllocator

func NewAllocator(cfg *rest.Config, conf Config) (Allocator, error)

NewAllocator creates a new IPAM allocator. The given configuration will be copied and modified.

type Config

type Config struct {
	// IPAM is the IPAM configuration.
	IPAM meshplugins.IPAMConfig
	// Lock is the lock configuration.
	Lock LockConfig
	// Network is the IPv4 network to allocate addresses in.
	Network netip.Prefix
}

Config is the configuration for the allocator.

type LockConfig

type LockConfig struct {
	ID                 string
	Namespace          string
	LockDuration       time.Duration
	LockAcquireTimeout time.Duration
}

LockConfig is the configuration for a lock.

type Locker

type Locker interface {
	// Acquire attempts to acquire the lock. If a lock is already acquired, the
	// lock count is incremented. When the lock is released, the lock count is
	// decremented. When the lock count reaches 0, the lock is released.
	Acquire(ctx context.Context) error
	// Release releases the lock. This decrements the lock count. When the lock
	// count reaches 0, the lock is released.
	Release(ctx context.Context)
}

Locker is the interface for taking a distributed lock during IPv4 allocations.

func NewLock

func NewLock(cfg *rest.Config, config LockConfig) (Locker, error)

NewLock creates a new IPAM lock.

Jump to

Keyboard shortcuts

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