types

package
v0.8.8 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IPv4      = IPFamilyMode("IPv4Only")
	IPv6      = IPFamilyMode("IPv6Only")
	DualStack = IPFamilyMode("DualStack")
)
View Source
const (
	IPv4Alias = "IPv4"
	IPv6Alias = "IPv6"
)

short aliases

View Source
const (
	Underlay  = NetworkType("Underlay")
	Overlay   = NetworkType("Overlay")
	GlobalBGP = NetworkType("GlobalBGP")
)
View Source
const (
	IPStatusAllocated = "Allocated"
	IPStatusReserved  = "Reserved"
)

Variables

View Source
var (
	ErrNotFoundNetwork = errors.New("network not found")
	ErrEmptySubnetName = errors.New("subnet name must be specified")
)
View Source
var (
	ErrNoAvailableSubnet      = errors.New("no available subnet")
	ErrNotFoundSubnet         = errors.New("subnet not found")
	ErrNotFoundAssignedIP     = errors.New("assigned ip not found")
	ErrNotAvailableAssignedIP = errors.New("assigned ip is not available")
)

Functions

func IsValidFamilyMode added in v0.7.0

func IsValidFamilyMode(ipFamily IPFamilyMode) bool

func IsValidNetworkType added in v0.7.0

func IsValidNetworkType(networkType NetworkType) bool

Types

type AdditionalLabels added in v0.6.0

type AdditionalLabels map[string]string

func (AdditionalLabels) ApplyToCouple added in v0.6.0

func (a AdditionalLabels) ApplyToCouple(options *CoupleOptions)

func (AdditionalLabels) ApplyToReCouple added in v0.6.0

func (a AdditionalLabels) ApplyToReCouple(options *ReCoupleOptions)

type AllocateOption added in v0.6.0

type AllocateOption interface {
	ApplyToAllocate(*AllocateOptions)
}

type AllocateOptions added in v0.6.0

type AllocateOptions struct {
	// Subnets is the specified subnet list where IP should be allocated from
	Subnets []string
}

AllocateOptions is a collection of all configurable configs for Allocate action

func (*AllocateOptions) ApplyOptions added in v0.6.0

func (a *AllocateOptions) ApplyOptions(opts []AllocateOption)

type AllocateSubnets added in v0.6.0

type AllocateSubnets []string

func (AllocateSubnets) ApplyToAllocate added in v0.6.0

func (a AllocateSubnets) ApplyToAllocate(options *AllocateOptions)

type AssignForce added in v0.6.0

type AssignForce bool

func (AssignForce) ApplyToAssign added in v0.6.0

func (a AssignForce) ApplyToAssign(options *AssignOptions)

type AssignOption added in v0.6.0

type AssignOption interface {
	ApplyToAssign(options *AssignOptions)
}

type AssignOptions added in v0.6.0

type AssignOptions struct {
	// Force means this assignment can force to use reserved IP
	Force bool
}

AssignOptions is a collection of all configurable configs for Assign action

func (*AssignOptions) ApplyOptions added in v0.6.0

func (a *AssignOptions) ApplyOptions(opts []AssignOption)

type CoupleOption added in v0.6.0

type CoupleOption interface {
	ApplyToCouple(*CoupleOptions)
}

type CoupleOptions added in v0.6.0

type CoupleOptions struct {
	// AdditionalLabels will be patched to IP when coupling
	AdditionalLabels map[string]string

	// SpecifiedMACAddress will be used as mac address of Pod
	SpecifiedMACAddress SpecifiedMACAddress

	// OwnerReference will replace the owner reference fetched from Pod explicitly
	OwnerReference *metav1.OwnerReference
}

CoupleOptions is a collection of all configurable configs for Couple action

func (*CoupleOptions) ApplyOptions added in v0.6.0

func (c *CoupleOptions) ApplyOptions(opts []CoupleOption)

type DropPodName added in v0.6.0

type DropPodName bool

func (DropPodName) ApplyToReserve added in v0.6.0

func (d DropPodName) ApplyToReserve(options *ReserveOptions)

type IP

type IP struct {
	Address      *net.IPNet
	Gateway      net.IP
	NetID        *uint32
	Subnet       string
	Network      string
	PodName      string
	PodNamespace string
	Status       string
}

func (*IP) IsIPv6

func (i *IP) IsIPv6() bool

func (*IP) String

func (i *IP) String() string

type IPFamilyMode

type IPFamilyMode string

func ParseIPFamilyFromEnv added in v0.4.3

func ParseIPFamilyFromEnv() IPFamilyMode

func ParseIPFamilyFromEnvOnce added in v0.4.3

func ParseIPFamilyFromEnvOnce() IPFamilyMode

func ParseIPFamilyFromString

func ParseIPFamilyFromString(in string) IPFamilyMode

type IPSet

type IPSet map[string]*IP

func NewIPSet

func NewIPSet() IPSet

func (IPSet) Add

func (s IPSet) Add(ip string, content *IP)

func (IPSet) Count

func (s IPSet) Count() int

func (IPSet) Delete

func (s IPSet) Delete(ip string)

func (IPSet) Get

func (s IPSet) Get(ip string) *IP

func (IPSet) Has

func (s IPSet) Has(ip string) bool

func (IPSet) Update

func (s IPSet) Update(ip, podName, podNamespace, status string)

func (IPSet) UpdateStatus added in v0.6.0

func (s IPSet) UpdateStatus(ip, status string)

type IPSlice

type IPSlice struct {
	IPs     []string
	IPCount int
	IPIndex int
}

func NewIPSlice

func NewIPSlice() *IPSlice

func (*IPSlice) Add

func (s *IPSlice) Add(ip string, isDefault bool)

func (*IPSlice) Count

func (s *IPSlice) Count() int

func (*IPSlice) Current

func (s *IPSlice) Current() string

func (*IPSlice) Next

func (s *IPSlice) Next() string

type Network

type Network struct {
	// Spec fields
	Name        string
	NetID       *uint32
	Type        NetworkType
	IPv4Subnets *SubnetSlice
	IPv6Subnets *SubnetSlice
}

func NewNetwork

func NewNetwork(name string, netID *uint32, lastAllocatedSubnet, lastAllocatedIPv6Subnet string, networkType NetworkType) *Network

func (*Network) AddSubnet

func (n *Network) AddSubnet(subnet *Subnet, ips IPSet) error

func (*Network) GetDualStackSubnetsByNameOrAvailable added in v0.6.0

func (n *Network) GetDualStackSubnetsByNameOrAvailable(v4SubnetName, v6SubnetName string) (v4Subnet *Subnet, v6Subnet *Subnet, err error)

func (*Network) GetIPv4SubnetByNameOrAvailable added in v0.6.0

func (n *Network) GetIPv4SubnetByNameOrAvailable(subnetName string) (sn *Subnet, err error)

func (*Network) GetIPv6SubnetByNameOrAvailable added in v0.6.0

func (n *Network) GetIPv6SubnetByNameOrAvailable(subnetName string) (sn *Subnet, err error)

func (*Network) GetSubnetByName added in v0.6.0

func (n *Network) GetSubnetByName(subnetName string) (*Subnet, error)

func (*Network) GetSubnetByNameOrIP added in v0.6.0

func (n *Network) GetSubnetByNameOrIP(subnetName, ip string) (*Subnet, error)

func (*Network) SubnetCount added in v0.7.0

func (n *Network) SubnetCount() int

func (*Network) Usage

func (n *Network) Usage() *NetworkUsage

type NetworkSet

type NetworkSet map[string]*Network

func NewNetworkSet

func NewNetworkSet() NetworkSet

func (NetworkSet) CheckNetworkByType added in v0.7.0

func (n NetworkSet) CheckNetworkByType(networkName string, networkType NetworkType) bool

func (NetworkSet) GetNetworkByName added in v0.7.0

func (n NetworkSet) GetNetworkByName(name string) (*Network, error)

func (NetworkSet) ListNetworkToNames added in v0.7.0

func (n NetworkSet) ListNetworkToNames() []string

func (NetworkSet) RefreshNetwork

func (n NetworkSet) RefreshNetwork(name string, network *Network)

func (NetworkSet) RemoveNetwork

func (n NetworkSet) RemoveNetwork(name string)

type NetworkType

type NetworkType string

func ParseNetworkTypeFromEnv

func ParseNetworkTypeFromEnv() NetworkType

func ParseNetworkTypeFromEnvOnce added in v0.5.0

func ParseNetworkTypeFromEnvOnce() NetworkType

func ParseNetworkTypeFromString

func ParseNetworkTypeFromString(in string) NetworkType

type NetworkUsage added in v0.6.0

type NetworkUsage struct {
	Usages map[IPFamilyMode]*Usage
}

func (*NetworkUsage) GetByType added in v0.6.0

func (n *NetworkUsage) GetByType(ipFamily IPFamilyMode) *Usage

type OwnerReference added in v0.6.0

type OwnerReference metav1.OwnerReference

func ResetOwnerReference added in v0.6.0

func ResetOwnerReference(orig *metav1.OwnerReference) OwnerReference

func (OwnerReference) ApplyToCouple added in v0.6.0

func (o OwnerReference) ApplyToCouple(options *CoupleOptions)

func (OwnerReference) ApplyToReCouple added in v0.6.0

func (o OwnerReference) ApplyToReCouple(options *ReCoupleOptions)

type PodInfo added in v0.6.0

type PodInfo struct {
	types.NamespacedName
	IPFamily IPFamilyMode
}

type ReCoupleOption added in v0.6.0

type ReCoupleOption interface {
	ApplyToReCouple(*ReCoupleOptions)
}

type ReCoupleOptions added in v0.6.0

type ReCoupleOptions struct {
	// AdditionalLabels will be patched to IP when recoupling
	AdditionalLabels map[string]string

	// SpecifiedMACAddress will be used as mac address of Pod
	SpecifiedMACAddress SpecifiedMACAddress

	// OwnerReference will replace the owner reference fetched from Pod explicitly
	OwnerReference *metav1.OwnerReference
}

ReCoupleOptions is a collection of all configurable configs for ReCouple action

func (*ReCoupleOptions) ApplyOptions added in v0.6.0

func (r *ReCoupleOptions) ApplyOptions(opts []ReCoupleOption)

type RefreshForceAll added in v0.6.0

type RefreshForceAll bool

func (RefreshForceAll) ApplyToRefresh added in v0.6.0

func (r RefreshForceAll) ApplyToRefresh(options *RefreshOptions)

type RefreshNetworks added in v0.6.0

type RefreshNetworks []string

func (RefreshNetworks) ApplyToRefresh added in v0.6.0

func (r RefreshNetworks) ApplyToRefresh(options *RefreshOptions)

type RefreshOption added in v0.6.0

type RefreshOption interface {
	ApplyToRefresh(*RefreshOptions)
}

type RefreshOptions added in v0.6.0

type RefreshOptions struct {
	// ForceAll will force all registered networks to be refreshed
	ForceAll bool

	// Networks is the specified network list to be refreshed
	Networks []string
}

RefreshOptions is a collection of all configurable configs for Refresh action

func (*RefreshOptions) ApplyOptions added in v0.6.0

func (r *RefreshOptions) ApplyOptions(opts []RefreshOption)

type ReserveOption added in v0.6.0

type ReserveOption interface {
	ApplyToReserve(*ReserveOptions)
}

type ReserveOptions added in v0.6.0

type ReserveOptions struct {
	// DropPodName means this reservation will drop pod name binding,
	// if pod name will change when IP reservation, set it true
	DropPodName bool
}

ReserveOptions is a coolection of all configurable configs for Reserve action

func (*ReserveOptions) ApplyOptions added in v0.6.0

func (r *ReserveOptions) ApplyOptions(opts []ReserveOption)

type SpecifiedMACAddress added in v0.7.0

type SpecifiedMACAddress string

func (SpecifiedMACAddress) ApplyToCouple added in v0.7.0

func (s SpecifiedMACAddress) ApplyToCouple(options *CoupleOptions)

func (SpecifiedMACAddress) ApplyToReCouple added in v0.7.0

func (s SpecifiedMACAddress) ApplyToReCouple(options *ReCoupleOptions)

func (SpecifiedMACAddress) EqualsTo added in v0.7.0

func (s SpecifiedMACAddress) EqualsTo(normalizedMACAddr string) bool

EqualsTo returns whether current specified MAC address is equal to another normalized MAC address.

func (SpecifiedMACAddress) IsEmpty added in v0.7.0

func (s SpecifiedMACAddress) IsEmpty() bool

type Subnet

type Subnet struct {
	// Spec fields
	// `Canonicalize` method will initialize these
	Name            string
	ParentNetwork   string
	NetID           *uint32
	Start           net.IP
	End             net.IP
	CIDR            *net.IPNet
	Gateway         net.IP
	ReservedList    map[string]struct{}
	BlackList       map[string]struct{}
	LastAllocatedIP net.IP
	Private         bool
	IPv6            bool

	// Status fields
	// `Sync` method will initialize these
	AvailableIPs    *IPSlice
	UsingIPs        IPSet
	ReservedIPCount int
}

func NewSubnet

func NewSubnet(
	name, network string, netID *uint32,
	start, end, gateway net.IP, cidr *net.IPNet,
	reservedList, blackList map[string]struct{}, lastAllocated net.IP,
	private, IPv6 bool) *Subnet

func (*Subnet) AllocateNext

func (s *Subnet) AllocateNext(podName, podNamespace string) *IP

func (*Subnet) Assign

func (s *Subnet) Assign(podName, podNamespace, ip string, forced bool) (*IP, error)

func (*Subnet) Canonicalize

func (s *Subnet) Canonicalize() error

Canonicalize takes a given subnet and ensures that all information is consistent, filling out Start, End, and Gateway with sane values if missing

func (*Subnet) Contains

func (s *Subnet) Contains(addr net.IP) bool

Contains checks if a given ip is a valid, allocatable address in a given Range This address should be in CIDR [start,gw) (gw,end], and not in black list.

func (*Subnet) IsAvailable

func (s *Subnet) IsAvailable() bool

func (*Subnet) IsBlackIP

func (s *Subnet) IsBlackIP(ip string) bool

func (*Subnet) IsIPv4 added in v0.6.0

func (s *Subnet) IsIPv4() bool

func (*Subnet) IsIPv6

func (s *Subnet) IsIPv6() bool

func (*Subnet) IsReservedIP

func (s *Subnet) IsReservedIP(ip string) bool

func (*Subnet) Overlap

func (s *Subnet) Overlap(s1 *Subnet) bool

Overlap must be called **after** Canonicalize

func (*Subnet) Release

func (s *Subnet) Release(ip string)

func (*Subnet) Reserve added in v0.6.0

func (s *Subnet) Reserve(ip string)

func (*Subnet) Sync

func (s *Subnet) Sync(parentNetID *uint32, ipSet IPSet) error

Sync will generate netID, filtered Reserved List, Available IP Slice and Using IP Set based on subnet spec and input

func (*Subnet) Usage

func (s *Subnet) Usage() *Usage

func (*Subnet) UsingIPCount

func (s *Subnet) UsingIPCount() int

UsingIPCount will count the IP which are being used, but the reserved IPs will be excluded

func (*Subnet) Validate

func (s *Subnet) Validate() error

Validate can ensure that all necessary information are valid

type SubnetIPSuite added in v0.6.0

type SubnetIPSuite struct {
	Subnet string
	IP     string
}

func AssignIP added in v0.6.0

func AssignIP(ip string) SubnetIPSuite

func AssignIPOfSubnet added in v0.6.0

func AssignIPOfSubnet(subnet, ip string) SubnetIPSuite

func ReleaseIPOfSubnet added in v0.6.0

func ReleaseIPOfSubnet(subnet, ip string) SubnetIPSuite

func ReserveIPOfSubnet added in v0.6.0

func ReserveIPOfSubnet(subnet, ip string) SubnetIPSuite

type SubnetSlice

type SubnetSlice struct {
	Subnets             []*Subnet
	SubnetIndexMap      map[string]int
	SubnetIndex         int
	SubnetCount         int
	LastAllocatedSubnet string
}

func NewSubnetSlice

func NewSubnetSlice(lastAllocatedSubnet string) *SubnetSlice

func (*SubnetSlice) AddSubnet

func (s *SubnetSlice) AddSubnet(subnet *Subnet, parentNetID *uint32, ips IPSet) error

func (*SubnetSlice) Count added in v0.7.0

func (s *SubnetSlice) Count() int

func (*SubnetSlice) CurrentSubnetName added in v0.7.0

func (s *SubnetSlice) CurrentSubnetName() string

func (*SubnetSlice) GetAvailableSubnet

func (s *SubnetSlice) GetAvailableSubnet() (*Subnet, error)

func (*SubnetSlice) GetSubnet

func (s *SubnetSlice) GetSubnet(name string) (*Subnet, error)

func (*SubnetSlice) GetSubnetByIP

func (s *SubnetSlice) GetSubnetByIP(ip string) (*Subnet, error)

func (*SubnetSlice) Usage

func (s *SubnetSlice) Usage() *Usage

type Usage

type Usage struct {
	Total          uint32
	Used           uint32
	Available      uint32
	LastAllocation string
}

func (*Usage) Add

func (u *Usage) Add(in *Usage)

Jump to

Keyboard shortcuts

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