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 ¶
- Variables
- type API
- type Deps
- type IPAM
- func (i *IPAM) AllocatePodCustomIfIP(podID podmodel.ID, ifName, network string) (net.IP, error)
- func (i *IPAM) AllocatePodIP(podID podmodel.ID, ipamType string, ipamData string) (net.IP, error)
- func (i *IPAM) BsidForNodeToNodeHostPolicy(nodeIP net.IP) net.IP
- func (i *IPAM) BsidForNodeToNodePodPolicy(nodeIP net.IP) net.IP
- func (i *IPAM) BsidForServicePolicy(serviceIPs []net.IP) net.IP
- func (i *IPAM) Close() error
- func (i *IPAM) GetIPAMConfigForJSON() *config.IPAMConfig
- func (i *IPAM) GetPodCustomIfIP(podID podmodel.ID, ifName, network string) *net.IPNet
- func (i *IPAM) GetPodFromIP(podIP net.IP) (podID podmodel.ID, found bool)
- func (i *IPAM) GetPodIP(podID podmodel.ID) *net.IPNet
- func (i *IPAM) HandlesEvent(event controller.Event) bool
- func (i *IPAM) HostInterconnectIPInLinux() net.IP
- func (i *IPAM) HostInterconnectIPInVPP() net.IP
- func (i *IPAM) HostInterconnectSubnetAllNodes() *net.IPNet
- func (i *IPAM) HostInterconnectSubnetOtherNode(nodeID uint32) (*net.IPNet, error)
- func (i *IPAM) HostInterconnectSubnetThisNode() *net.IPNet
- func (i *IPAM) Init() (err error)
- func (i *IPAM) NatLoopbackIP() net.IP
- func (i *IPAM) NodeIDFromPodIP(podIP net.IP) (uint32, error)
- func (i *IPAM) NodeIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)
- func (i *IPAM) PodGatewayIP() net.IP
- func (i *IPAM) PodSubnetAllNodes() *net.IPNet
- func (i *IPAM) PodSubnetOtherNode(nodeID uint32) (*net.IPNet, error)
- func (i *IPAM) PodSubnetThisNode() *net.IPNet
- func (i *IPAM) ReleasePodIPs(podID podmodel.ID) error
- func (i *IPAM) Resync(event controller.Event, kubeStateData controller.KubeStateData, ...) (err error)
- func (i *IPAM) Revert(event controller.Event) error
- func (i *IPAM) ServiceNetwork() *net.IPNet
- func (i *IPAM) SidForNodeToNodeHostLocalsid(nodeIP net.IP) net.IP
- func (i *IPAM) SidForNodeToNodePodLocalsid(nodeIP net.IP) net.IP
- func (i *IPAM) SidForServiceHostLocalsid() net.IP
- func (i *IPAM) SidForServiceNodeLocalsid(nodeIP net.IP) net.IP
- func (i *IPAM) SidForServicePodLocalsid(backendIP net.IP) net.IP
- func (i *IPAM) Update(event controller.Event, txn controller.UpdateOperations) (changeDescription string, err error)
- func (i *IPAM) VxlanIPAddress(nodeID uint32) (net.IP, *net.IPNet, error)
- type Option
- type PodCIDRChange
Constants ¶
This section is empty.
Variables ¶
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 (*IPAM) AllocatePodCustomIfIP ¶
AllocatePodCustomIfIP tries to allocate custom IP address for the given interface of a given pod.
func (*IPAM) AllocatePodIP ¶
AllocatePodIP tries to allocate IP address for the given pod.
func (*IPAM) BsidForNodeToNodeHostPolicy ¶
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 ¶
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 ¶
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) GetIPAMConfigForJSON ¶
func (i *IPAM) GetIPAMConfigForJSON() *config.IPAMConfig
GetIPAMConfigForJSON returns actual (contivCIDR dissected into ranges, if used) IPAM configuration
func (*IPAM) GetPodCustomIfIP ¶
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 ¶
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 ¶
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 ¶
HostInterconnectIPInLinux provides the IP address of the host(Linux)-end of the VPP to host interconnect.
func (*IPAM) HostInterconnectIPInVPP ¶
HostInterconnectIPInVPP provides the IP address for the VPP-end of the VPP-to-host interconnect.
func (*IPAM) HostInterconnectSubnetAllNodes ¶
HostInterconnectSubnetAllNodes returns vswitch base subnet used to connect VPP to its host Linux Stack on all nodes.
func (*IPAM) HostInterconnectSubnetOtherNode ¶
HostInterconnectSubnetOtherNode returns VPP-host network of another node identified by nodeID.
func (*IPAM) HostInterconnectSubnetThisNode ¶
HostInterconnectSubnetThisNode returns vswitch network used to connect VPP to its host Linux Stack on this node.
func (*IPAM) NatLoopbackIP ¶
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 ¶
NodeIDFromPodIP returns node ID from provided POD IP address.
func (*IPAM) NodeIPAddress ¶
NodeIPAddress computes IP address of the node based on the provided node ID.
func (*IPAM) PodGatewayIP ¶
PodGatewayIP returns gateway IP address of the POD subnet of this node.
func (*IPAM) PodSubnetAllNodes ¶
PodSubnetAllNodes returns POD subnet that is a base subnet for all PODs of all nodes.
func (*IPAM) PodSubnetOtherNode ¶
PodSubnetOtherNode returns the POD network of another node identified by nodeID.
func (*IPAM) PodSubnetThisNode ¶
PodSubnetThisNode returns POD network for the current node (given by nodeID given at IPAM creation).
func (*IPAM) ReleasePodIPs ¶
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 ¶
ServiceNetwork returns range allocated for services.
func (*IPAM) SidForNodeToNodeHostLocalsid ¶
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 ¶
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 ¶
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 ¶
SidForServiceNodeLocalsid creates a valid SRv6 SID for service locasid serving as intermediate step in policy segment list.
func (*IPAM) SidForServicePodLocalsid ¶
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.
type Option ¶
type Option func(*IPAM)
Option is a function that acts on a Plugin to inject Dependencies or configuration
type PodCIDRChange ¶
PodCIDRChange is triggered when CIDR for PODs on the current node changes.
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 ¶
func (ev *PodCIDRChange) Method() controller.EventMethodType
Method is UpstreamResync.
func (*PodCIDRChange) String ¶
func (ev *PodCIDRChange) String() string
String describes PodCIDRChange event.