ipam

package
v1.9.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: Apache-2.0 Imports: 39 Imported by: 14

Documentation

Overview

Package ipam handles address allocation management

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrIPv4Disabled is returned when IPv4 allocation is disabled
	ErrIPv4Disabled = errors.New("IPv4 allocation disabled")

	// ErrIPv6Disabled is returned when Ipv6 allocation is disabled
	ErrIPv6Disabled = errors.New("IPv6 allocation disabled")
)

Error definitions

Functions

This section is empty.

Types

type AllocationAction

type AllocationAction struct {
	// InterfaceID is set to the identifier describing the interface on
	// which the IPs must be allocated. This is optional, an IPAM
	// implementation can leave this empty to indicate that no interface
	// context is needed or a new interface must be created.
	InterfaceID string

	// Interface is the interface to allocate IPs on
	Interface ipamTypes.InterfaceRevision

	// PoolID is the IPAM pool identifier to allocate the IPs from. This
	// can correspond to a subnet ID or it can also left blank or set to a
	// value such as "global" to indicate a single address pool.
	PoolID ipamTypes.PoolID

	// AvailableForAllocation is the number IPs available for allocation.
	// If InterfaeID is set, then this number corresponds to the number of
	// IPs available for allocation on that interface. This number may be
	// lower than the number of IPs required to resolve the deficit.
	AvailableForAllocation int

	// MaxIPsToAllocate is set by the core IPAM layer before
	// NodeOperations.AllocateIPs() is called and defines the maximum
	// number of IPs to allocate in order to stay within the boundaries as
	// defined by NodeOperations.{ MinAllocate() | PreAllocate() |
	// getMaxAboveWatermark() }.
	MaxIPsToAllocate int

	// AvailableInterfaces is the number of interfaces available to be created
	AvailableInterfaces int
}

AllocationAction is the action to be taken to resolve allocation deficits for a particular node. It is returned by NodeOperations.PrepareIPAllocation() and passed into NodeOperations.AllocateIPs().

type AllocationImplementation

type AllocationImplementation interface {
	// CreateNode is called when the IPAM layer has learned about a new
	// node which requires IPAM services. This function must return a
	// NodeOperations implementation which will render IPAM services to the
	// node context provided.
	CreateNode(obj *v2.CiliumNode, node *Node) NodeOperations

	// GetPoolQuota is called to retrieve the remaining IP addresses in all
	// IP pools known to the IPAM implementation.
	GetPoolQuota() ipamTypes.PoolQuotaMap

	// Resync is called periodically to give the IPAM implementation a
	// chance to resync its own state with external APIs or systems. It is
	// also called when the IPAM layer detects that state got out of sync.
	Resync(ctx context.Context) time.Time
}

AllocationImplementation is the interface an implementation must provide. Other than NodeOperations, this implementation is not related to a node specifically.

type AllocationResult

type AllocationResult struct {
	// IP is the allocated IP
	IP net.IP

	// CIDRs is a list of all CIDRs to which the IP has direct access to.
	// This is primarily useful if the IP has been allocated out of a VPC
	// subnet range and the VPC provides routing to a set of CIDRs in which
	// the IP is routable.
	CIDRs []string

	// Master is the MAC address of the master interface. This is useful
	// when the IP is a secondary address of an interface which is
	// represented on the node as a Linux device and all routing of the IP
	// must occur through that master interface.
	Master string

	// GatewayIP is the IP of the gateway which must be used for this IP.
	// If the allocated IP is derived from a VPC, then the gateway
	// represented the gateway of the VPC or VPC subnet.
	GatewayIP string

	// ExpirationUUID is the UUID of the expiration timer. This field is
	// only set if AllocateNextWithExpiration is used.
	ExpirationUUID string
}

AllocationResult is the result of an allocation

type Allocator

type Allocator interface {
	// Allocate allocates a specific IP or fails
	Allocate(ip net.IP, owner string) (*AllocationResult, error)

	// AllocateWithoutSyncUpstream allocates a specific IP without syncing
	// upstream or fails
	AllocateWithoutSyncUpstream(ip net.IP, owner string) (*AllocationResult, error)

	// Release releases a previously allocated IP or fails
	Release(ip net.IP) error

	// AllocateNext allocates the next available IP or fails if no more IPs
	// are available
	AllocateNext(owner string) (*AllocationResult, error)

	// AllocateNextWithoutSyncUpstream allocates the next available IP without syncing
	// upstream or fails if no more IPs are available
	AllocateNextWithoutSyncUpstream(owner string) (*AllocationResult, error)

	// Dump returns a map of all allocated IPs with the IP represented as
	// key in the map. Dump must also provide a status one-liner to
	// represent the overall status, e.g. number of IPs allocated and
	// overall health information if available.
	Dump() (map[string]string, string)

	// RestoreFinished marks the status of restoration as done
	RestoreFinished()
}

Allocator is the interface for an IP allocator implementation

type CiliumNodeGetterUpdater

type CiliumNodeGetterUpdater interface {
	Create(node *v2.CiliumNode) (*v2.CiliumNode, error)
	Update(origResource, newResource *v2.CiliumNode) (*v2.CiliumNode, error)
	UpdateStatus(origResource, newResource *v2.CiliumNode) (*v2.CiliumNode, error)
	Get(name string) (*v2.CiliumNode, error)
	Delete(name string) error
}

CiliumNodeGetterUpdater defines the interface used to interact with the k8s apiserver to retrieve and update the CiliumNode custom resource

type Configuration

type Configuration interface {
	// IPv4Enabled must return true when IPv4 is enabled
	IPv4Enabled() bool

	// IPv6 must return true when IPv6 is enabled
	IPv6Enabled() bool

	// IPAMMode returns the IPAM mode
	IPAMMode() string

	// HealthCheckingEnabled must return true when health-checking is
	// enabled
	HealthCheckingEnabled() bool

	// SetIPv4NativeRoutingCIDR is called by the IPAM module to announce
	// the native IPv4 routing CIDR if it exists
	SetIPv4NativeRoutingCIDR(cidr *cidr.CIDR)

	// IPv4NativeRoutingCIDR is called by the IPAM module retrieve
	// the native IPv4 routing CIDR if it exists
	IPv4NativeRoutingCIDR() *cidr.CIDR
}

Configuration is the configuration passed into the IPAM subsystem

type ErrAllocation

type ErrAllocation error

type Family

type Family string

Family is the type describing all address families support by the IP allocation manager

const (
	IPv6 Family = "ipv6"
	IPv4 Family = "ipv4"
)

func DeriveFamily

func DeriveFamily(ip net.IP) Family

DeriveFamily derives the address family of an IP

type IPAM

type IPAM struct {
	IPv6Allocator Allocator
	IPv4Allocator Allocator
	// contains filtered or unexported fields
}

IPAM is the configuration used for a particular IPAM type.

func NewIPAM

func NewIPAM(nodeAddressing datapath.NodeAddressing, c Configuration, owner Owner, k8sEventReg K8sEventRegister) *IPAM

NewIPAM returns a new IP address manager

func (*IPAM) AllocateIP

func (ipam *IPAM) AllocateIP(ip net.IP, owner string) (err error)

AllocateIP allocates a IP address.

func (*IPAM) AllocateIPString

func (ipam *IPAM) AllocateIPString(ipAddr, owner string) error

AllocateIPString is identical to AllocateIP but takes a string

func (*IPAM) AllocateIPWithoutSyncUpstream

func (ipam *IPAM) AllocateIPWithoutSyncUpstream(ip net.IP, owner string) (err error)

AllocateIPWithoutSyncUpstream allocates a IP address without syncing upstream.

func (*IPAM) AllocateNext

func (ipam *IPAM) AllocateNext(family, owner string) (ipv4Result, ipv6Result *AllocationResult, err error)

AllocateNext allocates the next available IPv4 and IPv6 address out of the configured address pool. If family is set to "ipv4" or "ipv6", then allocation is limited to the specified address family. If the pool has been drained of addresses, an error will be returned.

func (*IPAM) AllocateNextFamily

func (ipam *IPAM) AllocateNextFamily(family Family, owner string) (result *AllocationResult, err error)

AllocateNextFamily allocates the next IP of the requested address family

func (*IPAM) AllocateNextFamilyWithoutSyncUpstream

func (ipam *IPAM) AllocateNextFamilyWithoutSyncUpstream(family Family, owner string) (result *AllocationResult, err error)

AllocateNextFamilyWithoutSyncUpstream allocates the next IP of the requested address family without syncing upstream

func (*IPAM) AllocateNextWithExpiration

func (ipam *IPAM) AllocateNextWithExpiration(family, owner string, timeout time.Duration) (ipv4Result, ipv6Result *AllocationResult, err error)

AllocateNextWithExpiration is identical to AllocateNext but registers an expiration timer as well. This is identical to using AllocateNext() in combination with StartExpirationTimer()

func (*IPAM) BlacklistIP added in v1.6.0

func (ipam *IPAM) BlacklistIP(ip net.IP, owner string)

BlacklistIP ensures that a certain IP is never allocated. It is preferred to use BlacklistIP() instead of allocating the IP as the allocation block can change and suddenly cover the IP to be blacklisted.

func (*IPAM) DebugStatus

func (ipam *IPAM) DebugStatus() string

DebugStatus implements debug.StatusObject to provide debug status collection ability

func (*IPAM) Dump

func (ipam *IPAM) Dump() (allocv4 map[string]string, allocv6 map[string]string, status string)

Dump dumps the list of allocated IP addresses

func (*IPAM) ReleaseIP

func (ipam *IPAM) ReleaseIP(ip net.IP) error

ReleaseIP release a IP address.

func (*IPAM) ReleaseIPString added in v1.5.0

func (ipam *IPAM) ReleaseIPString(releaseArg string) (err error)

ReleaseIPString is identical to ReleaseIP but takes a string and supports referring to the IPs to be released with the IP itself or the owner name used during allocation. If the owner can be referred to multiple IPs, then all IPs are being released.

func (*IPAM) StartExpirationTimer

func (ipam *IPAM) StartExpirationTimer(ip net.IP, timeout time.Duration) (string, error)

StartExpirationTimer installs an expiration timer for a previously allocated IP. Unless StopExpirationTimer is called in time, the IP will be released again after expiration of the specified timeout. The function will return a UUID representing the unique allocation attempt. The same UUID must be passed into StopExpirationTimer again.

This function is to be used as allocation and use of an IP can be controlled by an external entity and that external entity can disappear. Therefore such users should register an expiration timer before returning the IP and then stop the expiration timer when the IP has been used.

func (*IPAM) StopExpirationTimer

func (ipam *IPAM) StopExpirationTimer(ip net.IP, allocationUUID string) error

StopExpirationTimer will remove the expiration timer for a particular IP. The UUID returned by the symmetric StartExpirationTimer must be provided. The expiration timer will only be removed if the UUIDs match. Releasing an IP will also stop the expiration timer.

type IPBlacklist added in v1.6.0

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

IPBlacklist is a structure used to store information related to blacklisted IPs and IPNetworks.

func (*IPBlacklist) Contains added in v1.6.0

func (blacklist *IPBlacklist) Contains(ip net.IP) bool

Contains method is used to check if a particular IP is blacklisted or not.

type K8sEventRegister

type K8sEventRegister interface {
	// K8sEventReceived is called to do metrics accounting for received
	// Kubernetes events
	K8sEventReceived(scope string, action string, valid, equal bool)

	// K8sEventProcessed is called to do metrics accounting for each processed
	// Kubernetes event
	K8sEventProcessed(scope string, action string, status bool)
}

type MetricsAPI

type MetricsAPI interface {
	IncAllocationAttempt(status, subnetID string)
	AddIPAllocation(subnetID string, allocated int64)
	AddIPRelease(subnetID string, released int64)
	SetAllocatedIPs(typ string, allocated int)
	SetAvailableInterfaces(available int)
	SetAvailableIPsPerSubnet(subnetID string, availabilityZone string, available int)
	SetNodes(category string, nodes int)
	IncResyncCount()
	PoolMaintainerTrigger() trigger.MetricsObserver
	K8sSyncTrigger() trigger.MetricsObserver
	ResyncTrigger() trigger.MetricsObserver
}

MetricsAPI represents the metrics being maintained by a NodeManager

type Node

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

Node represents a Kubernetes node running Cilium with an associated CiliumNode custom resource

func (*Node) GetNeededAddresses

func (n *Node) GetNeededAddresses() int

GetNeededAddresses returns the number of needed addresses that need to be allocated or released. A positive number is returned to indicate allocation. A negative number is returned to indicate release of addresses.

func (*Node) InstanceID

func (n *Node) InstanceID() (id string)

InstanceID returns the instance ID of the node

func (*Node) IsRunning

func (n *Node) IsRunning() bool

IsRunning returns true if the node is considered to be running

func (*Node) MaintainIPPool

func (n *Node) MaintainIPPool(ctx context.Context) error

MaintainIPPool attempts to allocate or release all required IPs to fulfill the needed gap. If required, interfaces are created.

func (*Node) Ops

func (n *Node) Ops() NodeOperations

Ops returns the IPAM implementation operations for the node

func (*Node) Pool

func (n *Node) Pool() (pool ipamTypes.AllocationMap)

Pool returns the IP allocation pool available to the node

func (*Node) ResourceCopy

func (n *Node) ResourceCopy() *v2.CiliumNode

ResourceCopy returns a deep copy of the CiliumNode custom resource associated with the node

func (*Node) SetRunning

func (n *Node) SetRunning(running bool)

func (*Node) Stats

func (n *Node) Stats() Statistics

Stats returns a copy of the node statistics

func (*Node) UpdatedResource

func (n *Node) UpdatedResource(resource *v2.CiliumNode) bool

UpdatedResource is called when an update to the CiliumNode has been received. The IPAM layer will attempt to immediately resolve any IP deficits and also trigger the background sync to continue working in the background to resolve any deficits or excess.

type NodeManager

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

NodeManager manages all nodes with ENIs

func NewNodeManager

func NewNodeManager(instancesAPI AllocationImplementation, k8sAPI CiliumNodeGetterUpdater, metrics MetricsAPI, parallelWorkers int64, releaseExcessIPs bool) (*NodeManager, error)

NewNodeManager returns a new NodeManager

func (*NodeManager) Create added in v1.8.0

func (n *NodeManager) Create(resource *v2.CiliumNode) bool

func (*NodeManager) Delete

func (n *NodeManager) Delete(nodeName string)

Delete is called after a CiliumNode resource has been deleted via the Kubernetes apiserver

func (*NodeManager) Get

func (n *NodeManager) Get(nodeName string) *Node

Get returns the node with the given name

func (*NodeManager) GetNames

func (n *NodeManager) GetNames() (allNodeNames []string)

GetNames returns the list of all node names

func (*NodeManager) GetNodesByIPWatermark added in v1.8.0

func (n *NodeManager) GetNodesByIPWatermark() []*Node

GetNodesByIPWatermark returns all nodes that require addresses to be allocated or released, sorted by the number of addresses needed to be operated in descending order. Number of addresses to be released is negative value so that nodes with IP deficit are resolved first

func (*NodeManager) InstancesAPIIsReady

func (n *NodeManager) InstancesAPIIsReady() bool

InstancesAPIIsReady returns true if the instances API is stable and ready

func (*NodeManager) Resync

func (n *NodeManager) Resync(ctx context.Context, syncTime time.Time)

Resync will attend all nodes and resolves IP deficits. The order of attendance is defined by the number of IPs needed to reach the configured watermarks. Any updates to the node resource are synchronized to the Kubernetes apiserver.

func (*NodeManager) SetInstancesAPIReadiness

func (n *NodeManager) SetInstancesAPIReadiness(ready bool)

SetInstancesAPIReadiness sets the readiness state of the instances API

func (*NodeManager) Start

func (n *NodeManager) Start(ctx context.Context) error

Start kicks of the NodeManager by performing the initial state synchronization and starting the background sync go routine

func (*NodeManager) Update added in v1.8.0

func (n *NodeManager) Update(resource *v2.CiliumNode) (nodeSynced bool)

Update is called whenever a CiliumNode resource has been updated in the Kubernetes apiserver

type NodeOperations

type NodeOperations interface {
	// UpdateNode is called when an update to the CiliumNode is received.
	UpdatedNode(obj *v2.CiliumNode)

	// PopulateStatusFields is called to give the implementation a chance
	// to populate any implementation specific fields in CiliumNode.Status.
	PopulateStatusFields(resource *v2.CiliumNode)

	// CreateInterface is called to create a new interface. This is only
	// done if PrepareIPAllocation indicates that no more IPs are available
	// (AllocationAction.AvailableForAllocation == 0) for allocation but
	// interfaces are available for creation
	// (AllocationAction.AvailableInterfaces > 0). This function must
	// create the interface *and* allocate up to
	// AllocationAction.MaxIPsToAllocate.
	CreateInterface(ctx context.Context, allocation *AllocationAction, scopedLog *logrus.Entry) (int, string, error)

	// ResyncInterfacesAndIPs is called to synchronize the latest list of
	// interfaces and IPs associated with the node. This function is called
	// sparingly as this information is kept in sync based on the success
	// of the functions AllocateIPs(), ReleaseIPs() and CreateInterface().
	ResyncInterfacesAndIPs(ctx context.Context, scopedLog *logrus.Entry) (ipamTypes.AllocationMap, error)

	// PrepareIPAllocation is called to calculate the number of IPs that
	// can be allocated on the node and whether a new network interface
	// must be attached to the node.
	PrepareIPAllocation(scopedLog *logrus.Entry) (*AllocationAction, error)

	// AllocateIPs is called after invoking PrepareIPAllocation and needs
	// to perform the actual allocation.
	AllocateIPs(ctx context.Context, allocation *AllocationAction) error

	// PrepareIPRelease is called to calculate whether any IP excess needs
	// to be resolved. It behaves identical to PrepareIPAllocation but
	// indicates a need to release IPs.
	PrepareIPRelease(excessIPs int, scopedLog *logrus.Entry) *ReleaseAction

	// ReleaseIPs is called after invoking PrepareIPRelease and needs to
	// perform the release of IPs.
	ReleaseIPs(ctx context.Context, release *ReleaseAction) error

	// GetMaximumAllocatableIPv4 returns the maximum amount of IPv4 addresses
	// that can be allocated to the instance
	GetMaximumAllocatableIPv4() int
}

NodeOperations is the interface an IPAM implementation must provide in order to provide IP allocation for a node. The structure implementing this API *must* be aware of the node connected to this implementation. This is achieved by considering the node context provided in AllocationImplementation.CreateNode() function and returning a NodeOperations implementation which performs operations in the context of that node.

type Owner

type Owner interface {
	// UpdateCiliumNodeResource is called to create/update the CiliumNode
	// resource. The function must block until the custom resource has been
	// created.
	UpdateCiliumNodeResource()
}

Owner is the interface the owner of an IPAM allocator has to implement

type ReleaseAction

type ReleaseAction struct {
	// InterfaceID is set to the identifier describing the interface on
	// which the IPs must be released. This is optional, an IPAM
	// implementation can leave this empty to indicate that no interface
	// context is needed.
	InterfaceID string

	// PoolID is the IPAM pool identifier to release the IPs from. This can
	// correspond to a subnet ID or it can also left blank or set to a
	// value such as "global" to indicate a single address pool.
	PoolID ipamTypes.PoolID

	// IPsToRelease is the list of IPs to release
	IPsToRelease []string
}

ReleaseAction is the action to be taken to resolve allocation excess for a particular node. It is returned by NodeOperations.PrepareIPRelease() and passed into NodeOperations.ReleaseIPs().

type Statistics

type Statistics struct {
	// UsedIPs is the number of IPs currently in use
	UsedIPs int

	// AvailableIPs is the number of IPs currently available for allocation
	// by the node
	AvailableIPs int

	// NeededIPs is the number of IPs needed to reach the PreAllocate
	// watermwark
	NeededIPs int

	// ExcessIPs is the number of free IPs exceeding MaxAboveWatermark
	ExcessIPs int

	// RemainingInterfaces is the number of interfaces that can either be
	// allocated or have not yet exhausted the instance specific quota of
	// addresses
	RemainingInterfaces int
}

Statistics represent the IP allocation statistics of a node

Directories

Path Synopsis
aws
+groupName=ipam
+groupName=ipam

Jump to

Keyboard shortcuts

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