ipam

package
v3.1.0+incompatible Latest Latest
Warning

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

Go to latest
Published: May 17, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

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

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)

	// NodeIDFromPodIP returns node ID from provided POD IP address.
	NodeIDFromPodIP(podIP net.IP) (uint32, 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

	// AllocatePodCustomIfIP tries to allocate custom IP address for the given interface of a given pod.
	AllocatePodCustomIfIP(podID podmodel.ID, ifName, network string) (net.IP, error)

	// GetPodCustomIfIP returns the allocated custom interface pod IP, together with the mask.
	// Returns nil if the pod does not have allocated custom interface IP address.
	GetPodCustomIfIP(podID podmodel.ID, ifName, network string) *net.IPNet

	// GetPodFromIP returns the pod information related to the allocated pod IP.
	// found is false if the provided IP address has not been allocated to any local pod.
	GetPodFromIP(podIP net.IP) (podID podmodel.ID, found bool)

	// ReleasePodIPs releases all pod IP addresses making them available for new PODs.
	ReleasePodIPs(podID podmodel.ID) error

	// BsidForServicePolicy creates a valid SRv6 binding SID for given k8s service IP addresses <serviceIPs>. This sid
	// should be used only for k8s service policy
	BsidForServicePolicy(serviceIPs []net.IP) net.IP

	// SidForServiceHostLocalsid creates a valid SRv6 SID for service locasid leading to host on the current node. Created SID
	// doesn't depend on anything and is the same for each node, because there is only one way how to get to host in each
	// node and localsid have local significance (their sid don't have to be globally unique)
	SidForServiceHostLocalsid() net.IP

	// SidForServicePodLocalsid creates a valid SRv6 SID for service locasid leading to pod backend. The SID creation is
	// based on backend IP <backendIP>.
	SidForServicePodLocalsid(backendIP net.IP) net.IP

	// SidForNodeToNodePodLocalsid creates a valid SRv6 SID for locasid that is part of node-to-node Srv6 tunnel and
	// outputs packets to pod VRF table.
	SidForNodeToNodePodLocalsid(nodeIP net.IP) net.IP

	// SidForNodeToNodeHostLocalsid creates a valid SRv6 SID for locasid that is part of node-to-node Srv6 tunnel and
	// outputs packets to main VRF table.
	SidForNodeToNodeHostLocalsid(nodeIP net.IP) net.IP

	// SidForServiceNodeLocalsid creates a valid SRv6 SID for service locasid serving as intermediate step in policy segment list.
	SidForServiceNodeLocalsid(nodeIP net.IP) net.IP

	// BsidForNodeToNodePodPolicy creates a valid SRv6 SID for policy that is part of node-to-node Srv6 tunnel and routes traffic to pod VRF table
	BsidForNodeToNodePodPolicy(nodeIP net.IP) net.IP

	// BsidForNodeToNodeHostPolicy creates a valid SRv6 SID for policy that is part of node-to-node Srv6 tunnel and routes traffic to main VRF table
	BsidForNodeToNodeHostPolicy(nodeIP net.IP) net.IP

	// GetIPAMConfigForJSON returns IPAM configuration in format suitable
	// for marshalling to JSON (subnets not converted to net.IPNet + defined
	// JSON flag for every option). If contivCIDR is used it returns actual
	// dissected subnets.
	GetIPAMConfigForJSON() *config.IPAMConfig
}

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
	HTTPHandlers rest.HTTPHandlers
}

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) AllocatePodCustomIfIP

func (i *IPAM) AllocatePodCustomIfIP(podID podmodel.ID, ifName, network string) (net.IP, error)

AllocatePodCustomIfIP tries to allocate custom IP address for the given interface of a given pod.

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) BsidForNodeToNodeHostPolicy

func (i *IPAM) BsidForNodeToNodeHostPolicy(nodeIP net.IP) net.IP

BsidForNodeToNodeHostPolicy creates a valid SRv6 SID for policy that is part of node-to-node Srv6 tunnel and routes traffic to main VRF table

func (*IPAM) BsidForNodeToNodePodPolicy

func (i *IPAM) BsidForNodeToNodePodPolicy(nodeIP net.IP) net.IP

BsidForNodeToNodePodPolicy creates a valid SRv6 SID for policy that is part of node-to-node Srv6 tunnel and routes traffic to pod VRF table

func (*IPAM) BsidForServicePolicy

func (i *IPAM) BsidForServicePolicy(serviceIPs []net.IP) net.IP

BsidForServicePolicy creates a valid SRv6 binding SID for given k8s service IP addresses <serviceIPs>. This sid should be used only for k8s service policy

func (*IPAM) Close

func (i *IPAM) Close() error

Close is NOOP.

func (*IPAM) GetIPAMConfigForJSON

func (i *IPAM) GetIPAMConfigForJSON() *config.IPAMConfig

GetIPAMConfigForJSON returns actual (contivCIDR dissected into ranges, if used) IPAM configuration

func (*IPAM) GetPodCustomIfIP

func (i *IPAM) GetPodCustomIfIP(podID podmodel.ID, ifName, network string) *net.IPNet

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

func (*IPAM) GetPodFromIP

func (i *IPAM) GetPodFromIP(podIP net.IP) (podID podmodel.ID, found bool)

GetPodFromIP returns the pod information related to the allocated pod IP. found is false if the provided IP address has not been allocated to any local pod.

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 IP address of the host(Linux)-end of the VPP to host interconnect.

func (*IPAM) HostInterconnectIPInVPP

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

HostInterconnectIPInVPP provides the IP 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 initializes the REST handlers of the plugin.

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) NodeIDFromPodIP

func (i *IPAM) NodeIDFromPodIP(podIP net.IP) (uint32, error)

NodeIDFromPodIP returns node ID from provided POD IP address.

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) ReleasePodIPs

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

ReleasePodIPs 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) SidForNodeToNodeHostLocalsid

func (i *IPAM) SidForNodeToNodeHostLocalsid(nodeIP net.IP) net.IP

SidForNodeToNodeHostLocalsid creates a valid SRv6 SID for locasid that is part of node-to-node Srv6 tunnel and outputs packets to main VRF table.

func (*IPAM) SidForNodeToNodePodLocalsid

func (i *IPAM) SidForNodeToNodePodLocalsid(nodeIP net.IP) net.IP

SidForNodeToNodePodLocalsid creates a valid SRv6 SID for locasid that is part of node-to-node Srv6 tunnel and outputs packets to pod VRF table.

func (*IPAM) SidForServiceHostLocalsid

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

SidForServiceHostLocalsid creates a valid SRv6 SID for service locasid leading to host on the current node. Created SID doesn't depend on anything and is the same for each node, because there is only one way how to get to host in each node and localsid have local significance (their sid don't have to be globally unique)

func (*IPAM) SidForServiceNodeLocalsid

func (i *IPAM) SidForServiceNodeLocalsid(nodeIP net.IP) net.IP

SidForServiceNodeLocalsid creates a valid SRv6 SID for service locasid serving as intermediate step in policy segment list.

func (*IPAM) SidForServicePodLocalsid

func (i *IPAM) SidForServicePodLocalsid(backendIP net.IP) net.IP

SidForServicePodLocalsid creates a valid SRv6 SID for service locasid leading to pod backend. The SID creation is based on backend IP <backendIP>.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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