ipam

package
v2.1.4+incompatible Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package ipam provides node-local IPAM calculations: POD IP addresses, VPP-host interconnect and node interconnect IP addresses.

The configuration for IPAM is retrieved from the ContivConf plugin.

Single IPAM instance is responsible for all node-local allocations. Between nodes, however, IPAMs do not communicate with each other, instead, the unique node ID (uint32), retrieved from the nodesync plugin upon the first resync, is used to avoid inter-node collisions.

The plugin calculates and assigns the following IP addresses:

  • node-local POD network and individual POD IPs (based on podSubnetCIDR, podSubnetOneNodePrefixLen and node ID)
  • IP subnet for the VPP-to-host Linux stack interconnect (based on vppHostSubnetCIDR, vppHostSubnetOneNodePrefixLen and node ID)
  • IP address of the physical interface used for node interconnect (based on nodeInterconnectCIDR and node ID)

Example (configuration from contiv.conf processed by ContivConf plugin):

	    ipamConfig:
		  podSubnetCIDR: "10.1.0.0/16"
		  podSubnetOneNodePrefixLen: 24
		  vppHostSubnetCIDR: "172.30.0.0/16"
		  vppHostSubnetOneNodePrefixLen: 24
		  nodeInterconnectCIDR: "192.168.16.0/24"

		Assigned node ID: 5

		Calculated POD IPs: 10.1.5.2 - 10.1.5.254 (/24)
		Calculated VPP-host interconnect IPs: 172.30.5.1, 172.30.5.2 (/24)
 	Calculated Node Interconnect IP:  192.168.16.5 (/24)

Index

Constants

This section is empty.

Variables

View Source
var DefaultPlugin = *NewPlugin()

DefaultPlugin is a default instance of IPAM plugin.

Functions

This section is empty.

Types

type API

type API interface {
	// NodeIPAddress computes IP address of the node based on the provided node ID.
	NodeIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)

	// VxlanIPAddress computes IP address of the VXLAN interface based on the provided
	// node ID.
	VxlanIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)

	// HostInterconnectIPInVPP provides the IPv4 address for the VPP-end of the VPP-to-host
	// interconnect.
	HostInterconnectIPInVPP() net.IP

	// HostInterconnectIPInLinux provides the IPv4 address of the host(Linux)-end
	// of the VPP-to-host interconnect.
	HostInterconnectIPInLinux() net.IP

	// HostInterconnectSubnetThisNode returns vswitch network used to connect
	// VPP to its host Linux Stack on this node.
	HostInterconnectSubnetThisNode() *net.IPNet

	// HostInterconnectSubnetAllNodes returns vswitch base subnet used to connect
	// VPP to its host Linux Stack on all nodes.
	HostInterconnectSubnetAllNodes() *net.IPNet

	// HostInterconnectSubnetOtherNode returns VPP-host network of another node
	// identified by nodeID.
	HostInterconnectSubnetOtherNode(nodeID uint32) (*net.IPNet, error)

	// PodSubnetAllNodes returns POD subnet that is a base subnet for all PODs
	// of all nodes.
	PodSubnetAllNodes() *net.IPNet

	// PodSubnetThisNode returns POD network for the current node
	// (given by nodeID allocated for this node).
	PodSubnetThisNode() *net.IPNet

	// PodSubnetOtherNode returns the POD network of another node identified by nodeID.
	PodSubnetOtherNode(nodeID uint32) (*net.IPNet, error)

	// ServiceNetwork returns range allocated for services.
	ServiceNetwork() *net.IPNet

	// PodGatewayIP returns gateway IP address of the POD subnet of this node.
	PodGatewayIP() net.IP

	// NatLoopbackIP returns the IP address of a virtual loopback, used to route
	// traffic between clients and services via VPP even if the source and destination
	// are the same IP addresses and would otherwise be routed locally.
	NatLoopbackIP() net.IP

	// AllocatePodIP tries to allocate IP address for the given pod.
	AllocatePodIP(podID podmodel.ID, ipamType string, ipamData string) (net.IP, error)

	// GetPodIP returns the allocated pod IP, together with the mask.
	// Returns nil if the pod does not have allocated IP address.
	GetPodIP(podID podmodel.ID) *net.IPNet

	// ReleasePodIP releases the pod IP address making it available for new PODs.
	ReleasePodIP(podID podmodel.ID) error
}

API defines methods provided by IPAM for use by other plugins.

type Deps

type Deps struct {
	infra.PluginDeps
	NodeSync     nodesync.API
	ContivConf   contivconf.API
	ServiceLabel servicelabel.ReaderAPI
	EventLoop    controller.EventLoop
}

Deps lists dependencies of the IPAM plugin.

type IPAM

type IPAM struct {
	Deps
	// contains filtered or unexported fields
}

IPAM plugin implements IP address allocation for Contiv.

func NewPlugin

func NewPlugin(opts ...Option) *IPAM

NewPlugin creates a new Plugin with the provides Options

func (*IPAM) AllocatePodIP

func (i *IPAM) AllocatePodIP(podID podmodel.ID, ipamType string, ipamData string) (net.IP, error)

AllocatePodIP tries to allocate IP address for the given pod.

func (*IPAM) Close

func (i *IPAM) Close() error

Close is NOOP.

func (*IPAM) GetPodIP

func (i *IPAM) GetPodIP(podID podmodel.ID) *net.IPNet

GetPodIP returns the allocated pod IP, together with the mask. Returns nil if the pod does not have allocated IP address.

func (*IPAM) HandlesEvent

func (i *IPAM) HandlesEvent(event controller.Event) bool

HandlesEvent selects any Resync event.

  • any Resync event
  • NodeUpdate for the current node if external IPAM is in use (may trigger PodCIDRChange)

func (*IPAM) HostInterconnectIPInLinux

func (i *IPAM) HostInterconnectIPInLinux() net.IP

HostInterconnectIPInLinux provides the IPv4 address of the host(Linux)-end of the VPP to host interconnect.

func (*IPAM) HostInterconnectIPInVPP

func (i *IPAM) HostInterconnectIPInVPP() net.IP

HostInterconnectIPInVPP provides the IPv4 address for the VPP-end of the VPP-to-host interconnect.

func (*IPAM) HostInterconnectSubnetAllNodes

func (i *IPAM) HostInterconnectSubnetAllNodes() *net.IPNet

HostInterconnectSubnetAllNodes returns vswitch base subnet used to connect VPP to its host Linux Stack on all nodes.

func (*IPAM) HostInterconnectSubnetOtherNode

func (i *IPAM) HostInterconnectSubnetOtherNode(nodeID uint32) (*net.IPNet, error)

HostInterconnectSubnetOtherNode returns VPP-host network of another node identified by nodeID.

func (*IPAM) HostInterconnectSubnetThisNode

func (i *IPAM) HostInterconnectSubnetThisNode() *net.IPNet

HostInterconnectSubnetThisNode returns vswitch network used to connect VPP to its host Linux Stack on this node.

func (*IPAM) Init

func (i *IPAM) Init() (err error)

Init is NOOP - the plugin is initialized during the first resync.

func (*IPAM) NatLoopbackIP

func (i *IPAM) NatLoopbackIP() net.IP

NatLoopbackIP returns the IP address of a virtual loopback, used to route traffic between clients and services via VPP even if the source and destination are the same IP addresses and would otherwise be routed locally.

func (*IPAM) NodeIPAddress

func (i *IPAM) NodeIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)

NodeIPAddress computes IP address of the node based on the provided node ID.

func (*IPAM) PodGatewayIP

func (i *IPAM) PodGatewayIP() net.IP

PodGatewayIP returns gateway IP address of the POD subnet of this node.

func (*IPAM) PodSubnetAllNodes

func (i *IPAM) PodSubnetAllNodes() *net.IPNet

PodSubnetAllNodes returns POD subnet that is a base subnet for all PODs of all nodes.

func (*IPAM) PodSubnetOtherNode

func (i *IPAM) PodSubnetOtherNode(nodeID uint32) (*net.IPNet, error)

PodSubnetOtherNode returns the POD network of another node identified by nodeID.

func (*IPAM) PodSubnetThisNode

func (i *IPAM) PodSubnetThisNode() *net.IPNet

PodSubnetThisNode returns POD network for the current node (given by nodeID given at IPAM creation).

func (*IPAM) ReleasePodIP

func (i *IPAM) ReleasePodIP(podID podmodel.ID) error

ReleasePodIP releases the pod IP address making it available for new PODs.

func (*IPAM) Resync

func (i *IPAM) Resync(event controller.Event, kubeStateData controller.KubeStateData,
	resyncCount int, txn controller.ResyncOperations) (err error)

Resync resynchronizes IPAM against the configuration and Kubernetes state data. A set of already allocated pod IPs is updated.

func (*IPAM) Revert

func (i *IPAM) Revert(event controller.Event) error

Revert is NOOP - never called.

func (*IPAM) ServiceNetwork

func (i *IPAM) ServiceNetwork() *net.IPNet

ServiceNetwork returns range allocated for services.

func (*IPAM) Update

func (i *IPAM) Update(event controller.Event, txn controller.UpdateOperations) (changeDescription string, err error)

Update handles NodeUpdate event in case that external IPAM is in use.

func (*IPAM) VxlanIPAddress

func (i *IPAM) VxlanIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)

VxlanIPAddress computes IP address of the VXLAN interface based on the provided node ID.

type Option

type Option func(*IPAM)

Option is a function that acts on a Plugin to inject Dependencies or configuration

func UseDeps

func UseDeps(cb func(*Deps)) Option

UseDeps returns Option that can inject custom dependencies.

type PodCIDRChange

type PodCIDRChange struct {
	LocalPodCIDR *net.IPNet
}

PodCIDRChange is triggered when CIDR for PODs on the current node changes.

func (*PodCIDRChange) Done

func (ev *PodCIDRChange) Done(error)

Done is NOOP.

func (*PodCIDRChange) GetName

func (ev *PodCIDRChange) GetName() string

GetName returns name of the PodCIDRChange event.

func (*PodCIDRChange) IsBlocking

func (ev *PodCIDRChange) IsBlocking() bool

IsBlocking returns false.

func (*PodCIDRChange) Method

Method is UpstreamResync.

func (*PodCIDRChange) String

func (ev *PodCIDRChange) String() string

String describes PodCIDRChange event.

Jump to

Keyboard shortcuts

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