Documentation ¶
Overview ¶
Package ipnet configures VPP-based IPv4 network connectivity between Kubernetes pods and nodes.
TODO: cleanup config The plugin is configurable via its config file that can be specified using `-contiv-config="<path to config>` argument when running the contiv-agent. This is usually being injected into the vswitch POD by a config map inside of the k8s deployment file of the contiv-VPP k8s networking plugin (see contiv-agent-cfg ConfigMap in ../../k8s/contiv-vpp.yaml).
Based on the configuration, the plugin can wire PODs in 2 different ways:
1. VETH-based pod-VPP connectivity (default)
Each POD is wired to VPP using a virtual ethernet interface pair, where one end is connected to VPP using AF_PACKET interface and the other end is placed into the POD's network namespace:
+-------------------------------------------------+ | vSwitch VPP host.go | +--------------+ | +--------------+ | | VETH VPP |____________| VETH Host | | routing | | | | | | +--------------+ | +--------------+ | +------+ +------+ | | | AF1 | | AFn | | | | | ... | | | | +------+ +------+ | | ^ | | | | +------|------------------------------------------+
v +------------+ | | | VETH1-VPP | | | +------------+ ^ | pod.go
+------|------------+ | NS1 v | | +------------+ | | | | | | | VETH1-POD | | | | | | | +------------+ | | | +-------------------+
2. TAP-based pod-VPP connectivity
Each POD is wired to VPP using a TAP interface created on VPP. Can be turned on by setting the UseTAPInterfaces: True in the config file. Legacy and the new virtio-based TAP interfaces are supported, the latter can be turned on by setting the TAPInterfaceVersion: 2.
+-------------------------------------------------+ | vSwitch VPP host.go | +--------------+ | +--------------+ | | VETH VPP |____________| VETH Host | | routing | | | | | | +--------------+ | +--------------+ | +-------+ +-------+ | | | TAP1 | | TAPn | | | | | ... | | | | +-------+ +-------+ | | ^ | | | | +------|------------------------------------------+
| | pod.go
+------|------------+ | NS1 v | | +------------+ | | | | | | | TAP1-POD | | | | | | | +------------+ | | | +-------------------+
Plugin Structure ================
The plugin consists of these components:
Plugin base: - plugin_*.go: plugin definition and setup - node_events.go: handler of changes in nodes within the k8s cluster (node add / delete)
Remote CNI Server - the main logic of the plugin that is in charge of wiring the PODs.
Node ID Allocator - manages allocation/deallocation of unique number identifying a node within the k8s cluster. Allocated identifier is used as an input of the IPAM calculations.
IPAM module (separate package, described in its own doc.go) - provides node-local IP address assignments.
Helper functions: - host.go: provides host-related helper functions and VPP-Agent NB API builders - pod.go: provides POD-related helper functions and VPP-Agent NB API builders
Additionally, the package provides REST endpoint for getting some of the IPAM-related information for the node on the URL: GET /contiv/v1/ipam.
Example:
$ curl localhost:9999/contiv/v1/ipam { "nodeId": 1, "nodeName": "vagrant-arch.vagrantup.com", "nodeIP": "192.168.16.1", "podSubnetThisNode": "10.1.1.0/24", "vppHostNetwork": "172.30.1.0/24" }
Index ¶
- Constants
- Variables
- type API
- type Deps
- type GoVPP
- type HostLinkIPsDumpClb
- type IPNet
- func (n *IPNet) Close() error
- func (n *IPNet) DescribeInternalData() string
- func (n *IPNet) GetExternalIfName(extIfName string, vlan uint32) (ifName string)
- func (n *IPNet) GetExternalIfNetworkName(ifName string) (string, error)
- func (n *IPNet) GetHostIPs() []net.IP
- func (n *IPNet) GetHostInterconnectIfName() string
- func (n *IPNet) GetNodeIP() (ip net.IP, network *net.IPNet)
- func (n *IPNet) GetOrAllocateVrfID(networkName string) (vrf uint32, err error)
- func (n *IPNet) GetOrAllocateVxlanVNI(networkName string) (vni uint32, err error)
- func (n *IPNet) GetPodByIf(ifName string) (podNamespace string, podName string, exists bool)
- func (n *IPNet) GetPodCustomIfNames(podNamespace, podName, customIfName string) (ifName string, linuxIfName string, exists bool)
- func (n *IPNet) GetPodCustomIfNetworkName(podID podmodel.ID, ifName string) (string, error)
- func (n *IPNet) GetPodIfNames(podNamespace string, podName string) (vppIfName, linuxIfName, loopIfName string, exists bool)
- func (n *IPNet) GetVxlanBVIIfName() string
- func (n *IPNet) HandlesEvent(event controller.Event) bool
- func (n *IPNet) Init() error
- func (n *IPNet) ReleaseVrfID(networkName string) (err error)
- func (n *IPNet) ReleaseVxlanVNI(networkName string) (err error)
- func (n *IPNet) Resync(event controller.Event, kubeStateData controller.KubeStateData, ...) error
- func (n *IPNet) Revert(event controller.Event) error
- func (s IPNet) StateToString() string
- func (n *IPNet) Update(event controller.Event, txn controller.UpdateOperations) (change string, err error)
- type NodeIPv4Change
- type Option
- type PodCustomIfUpdate
- func (ev *PodCustomIfUpdate) Direction() controller.UpdateDirectionType
- func (ev *PodCustomIfUpdate) Done(error)
- func (ev *PodCustomIfUpdate) GetName() string
- func (ev *PodCustomIfUpdate) IsBlocking() bool
- func (ev *PodCustomIfUpdate) Method() controller.EventMethodType
- func (ev *PodCustomIfUpdate) String() string
- func (ev *PodCustomIfUpdate) TransactionType() controller.UpdateTransactionType
Constants ¶
const ( // HostInterconnectTAPinVPPLogicalName is the logical name of the TAP interface // connecting host stack with VPP // - VPP side HostInterconnectTAPinVPPLogicalName = "tap-vpp2" // HostInterconnectTAPinLinuxLogicalName is the logical name of the TAP interface // connecting host stack with VPP // - Linux side HostInterconnectTAPinLinuxLogicalName = "tap-vpp1" // HostInterconnectTAPinLinuxHostName is the physical name of the TAP interface // connecting host stack with VPP // - the Linux side HostInterconnectTAPinLinuxHostName = "vpp1" )
VPP - Host interconnect
const ( // DefaultVxlanBVIInterfaceName name of the VXLAN interface for the default pod network. DefaultVxlanBVIInterfaceName = vxlanBVIInterfacePrefix // VxlanVniPoolName is name for the ID pool of VXLAN VNIs VxlanVniPoolName = "vni" )
VXLANs
const (
// DefaultPodNetworkName is the network name dedicated to the default pod network
DefaultPodNetworkName = "default"
)
Variables ¶
var DefaultPlugin = *NewPlugin()
DefaultPlugin is a default instance of IPNet.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { // GetPodIfNames looks up logical interface names that correspond to the interfaces // associated with the given local pod name + namespace. GetPodIfNames(podNamespace string, podName string) (vppIfName, linuxIfName, loopIfName string, exists bool) // GetPodCustomIfNames looks up logical interface name that corresponds to the custom interface // with specified name and type associated with the given local pod name + namespace. GetPodCustomIfNames(podNamespace, podName, customIfName string) (ifName string, linuxIfName string, exists bool) // GetExternalIfName returns logical name that corresponds to the specified external interface name and VLAN ID. GetExternalIfName(extIfName string, vlan uint32) (ifName string) // GetPodCustomIfNetworkName returns the name of custom network which should contain given // pod custom interface or error otherwise. This supports both type of pods, remote and local GetPodCustomIfNetworkName(podID podmodel.ID, ifName string) (string, error) // GetExternalIfNetworkName returns the name of custom network which should contain given // external interface or error otherwise. GetExternalIfNetworkName(ifName string) (string, error) // GetPodByIf looks up name and namespace that is associated with logical interface name. // The method can be called from outside of the main event loop. GetPodByIf(ifname string) (podNamespace string, podName string, exists bool) // GetNodeIP returns the IP+network address of this node. GetNodeIP() (ip net.IP, network *net.IPNet) // GetHostIPs returns all IP addresses of this node present in the host network namespace (Linux). GetHostIPs() []net.IP // GetHostInterconnectIfName returns the name of the TAP/AF_PACKET interface // interconnecting VPP with the host stack. GetHostInterconnectIfName() string // GetVxlanBVIIfName returns the name of an BVI interface facing towards VXLAN tunnels to other hosts. // Returns an empty string if VXLAN is not used (in no-overlay interconnect mode). GetVxlanBVIIfName() string // GetOrAllocateVxlanVNI returns the allocated VXLAN VNI number for the given network. // Allocates a new VNI if not already allocated. GetOrAllocateVxlanVNI(networkName string) (vni uint32, err error) // ReleaseVxlanVNI releases the allocated VXLAN VNI number for the given network. ReleaseVxlanVNI(networkName string) (err error) // GetOrAllocateVrfID returns the allocated VRF ID number for the given network. // Allocates a new VRF ID if not already allocated. GetOrAllocateVrfID(networkName string) (vrf uint32, err error) // ReleaseVrfID releases the allocated VRF ID number for the given network. ReleaseVrfID(networkName string) (err error) }
API defines methods provided by IPNet plugin for use by other plugins to query IPv4 network-related information. Apart from GetPodByIf, these methods should not be accessed from outside of the main event loop!
type Deps ¶
type Deps struct { infra.PluginDeps EventLoop controller.EventLoop ServiceLabel servicelabel.ReaderAPI ContivConf contivconf.API IDAlloc idalloc.API IPAM ipam.API NodeSync nodesync.API PodManager podmanager.API DeviceManager devicemanager.API VPPIfPlugin vpp_ifplugin.API LinuxNsPlugin linux_nsplugin.API GoVPP GoVPP HTTPHandlers rest.HTTPHandlers RemoteDB nodesync.KVDBWithAtomic }
Deps groups the dependencies of the plugin.
type GoVPP ¶
type GoVPP interface { // NewAPIChannel returns a new API channel for communication with VPP via govpp. NewAPIChannel() (govpp.Channel, error) // NewAPIChannelBuffered returns a new API channel for communication with VPP via govpp. NewAPIChannelBuffered(reqChanBufSize, replyChanBufSize int) (govpp.Channel, error) }
GoVPP is the interface of govppmux plugin replicated here to avoid direct dependency on vppapiclient.h for other plugins that import ipnet just to read some constants etc.
type HostLinkIPsDumpClb ¶
HostLinkIPsDumpClb is callback for dumping all IP addresses assigned to interfaces in the host stack.
type IPNet ¶
type IPNet struct { Deps // contains filtered or unexported fields }
IPNet plugin builds configuration to be applied by ligato/VPP-agent for VPP-based IP network connectivity between Kubernetes pods and nodes.
func (*IPNet) Close ¶
Close is called by the plugin infra upon agent cleanup. It cleans up the resources allocated by the plugin.
func (*IPNet) DescribeInternalData ¶
DescribeInternalData describes the internal state of IPNet plugin. Used for Verification Resync.
func (*IPNet) GetExternalIfName ¶
GetExternalIfName returns logical name that corresponds to the specified external interface name and VLAN ID.
func (*IPNet) GetExternalIfNetworkName ¶
GetExternalIfNetworkName returns the name of custom network which should contain given external interface or error otherwise.
func (*IPNet) GetHostIPs ¶
GetHostIPs returns all IP addresses of this node present in the host network namespace (Linux).
func (*IPNet) GetHostInterconnectIfName ¶
GetHostInterconnectIfName returns the name of the TAP/AF_PACKET interface interconnecting VPP with the host stack.
func (*IPNet) GetOrAllocateVrfID ¶
GetOrAllocateVrfID returns the allocated VRF ID number for the given network. Allocates a new VRF ID if not already allocated.
func (*IPNet) GetOrAllocateVxlanVNI ¶
GetOrAllocateVxlanVNI returns the allocated VXLAN VNI number for the given network. Allocates a new VNI if not already allocated.
func (*IPNet) GetPodByIf ¶
GetPodByIf looks up podName and podNamespace that is associated with logical interface name. The method can be called from outside of the main event loop.
func (*IPNet) GetPodCustomIfNames ¶
func (n *IPNet) GetPodCustomIfNames(podNamespace, podName, customIfName string) (ifName string, linuxIfName string, exists bool)
GetPodCustomIfNames looks up logical interface name that corresponds to the custom interface with specified name and type associated with the given local pod name + namespace.
func (*IPNet) GetPodCustomIfNetworkName ¶
GetPodCustomIfNetworkName returns the name of custom network which should contain given pod custom interface or error otherwise. This supports both type of pods, remote and local
func (*IPNet) GetPodIfNames ¶
func (n *IPNet) GetPodIfNames(podNamespace string, podName string) (vppIfName, linuxIfName, loopIfName string, exists bool)
GetPodIfNames looks up logical interface names that correspond to the interfaces associated with the given local pod name + namespace.
func (*IPNet) GetVxlanBVIIfName ¶
GetVxlanBVIIfName returns the name of an BVI interface facing towards VXLAN tunnels to other hosts. Returns an empty string if VXLAN is not used (in no overlay mode).
func (*IPNet) HandlesEvent ¶
func (n *IPNet) HandlesEvent(event controller.Event) bool
HandlesEvent selects:
- any Resync event (extra action for NodeIPv4Change)
- AddPod and DeletePod (CNI)
- POD k8s state changes
- POD custom interfaces update
- custom network update
- external interfaces update
- NodeUpdate for other nodes
- Shutdown event
func (*IPNet) Init ¶
Init initializes attributes/callbacks used to access the plugin-external state. Internal state is initialized later by the first resync.
func (*IPNet) ReleaseVrfID ¶
ReleaseVrfID releases the allocated VRF ID number for the given network.
func (*IPNet) ReleaseVxlanVNI ¶
ReleaseVxlanVNI releases the allocated VXLAN VNI number for the given network.
func (*IPNet) Resync ¶
func (n *IPNet) Resync(event controller.Event, kubeStateData controller.KubeStateData, resyncCount int, txn controller.ResyncOperations) error
Resync is called by Controller to handle event that requires full re-synchronization. For startup resync, resyncCount is 1. Higher counter values identify run-time resync.
func (*IPNet) Revert ¶
func (n *IPNet) Revert(event controller.Event) error
Revert is called for AddPod.
func (IPNet) StateToString ¶
func (s IPNet) StateToString() string
StateToString returns human-readable string representation of the ipnet plugin internal state. The method cannot be called String(), otherwise it overloads the Stringer from PluginDeps.
func (*IPNet) Update ¶
func (n *IPNet) Update(event controller.Event, txn controller.UpdateOperations) (change string, err error)
Update is called for:
- AddPod and DeletePod (CNI)
- POD k8s state changes
- NodeUpdate for other nodes
- Shutdown event
type NodeIPv4Change ¶
NodeIPv4Change is triggered when DHCP-assigned IPv4 address of the node changes.
func (*NodeIPv4Change) GetName ¶
func (ev *NodeIPv4Change) GetName() string
GetName returns name of the NodeIPv4Change event.
func (*NodeIPv4Change) IsBlocking ¶
func (ev *NodeIPv4Change) IsBlocking() bool
IsBlocking returns false.
func (*NodeIPv4Change) Method ¶
func (ev *NodeIPv4Change) Method() controller.EventMethodType
Method is UpstreamResync.
func (*NodeIPv4Change) String ¶
func (ev *NodeIPv4Change) String() string
String describes NodeIPv4Change event.
type Option ¶
type Option func(*IPNet)
Option is a function that acts on a Plugin to inject Dependencies or configuration
type PodCustomIfUpdate ¶
type PodCustomIfUpdate struct { PodID podmodel.ID Labels map[string]string Annotations map[string]string }
PodCustomIfUpdate is triggered when pod custom interfaces configuration needs to be updated.
func (*PodCustomIfUpdate) Direction ¶
func (ev *PodCustomIfUpdate) Direction() controller.UpdateDirectionType
Direction is forward.
func (*PodCustomIfUpdate) GetName ¶
func (ev *PodCustomIfUpdate) GetName() string
GetName returns name of the PodCustomIfUpdate event.
func (*PodCustomIfUpdate) IsBlocking ¶
func (ev *PodCustomIfUpdate) IsBlocking() bool
IsBlocking returns false.
func (*PodCustomIfUpdate) Method ¶
func (ev *PodCustomIfUpdate) Method() controller.EventMethodType
Method is Update.
func (*PodCustomIfUpdate) String ¶
func (ev *PodCustomIfUpdate) String() string
String describes PodCustomIfUpdate event.
func (*PodCustomIfUpdate) TransactionType ¶
func (ev *PodCustomIfUpdate) TransactionType() controller.UpdateTransactionType
TransactionType is RevertOnFailure.