Documentation ¶
Overview ¶
Package ipv4net 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 IPAMData
- type IPv4Net
- func (n *IPv4Net) Close() error
- func (n *IPv4Net) GetHostIPs() []net.IP
- func (n *IPv4Net) GetHostInterconnectIfName() string
- func (n *IPv4Net) GetIfName(podNamespace string, podName string) (name string, exists bool)
- func (n *IPv4Net) GetNodeIP() (ip net.IP, network *net.IPNet)
- func (n *IPv4Net) GetPodByIf(ifName string) (podNamespace string, podName string, exists bool)
- func (n *IPv4Net) GetVxlanBVIIfName() string
- func (n *IPv4Net) HandlesEvent(event controller.Event) bool
- func (n *IPv4Net) Init() error
- func (n *IPv4Net) Resync(event controller.Event, kubeStateData controller.KubeStateData, ...) error
- func (n *IPv4Net) Revert(event controller.Event) error
- func (s IPv4Net) StateToString() string
- func (n *IPv4Net) Update(event controller.Event, txn controller.UpdateOperations) (change string, err error)
- type NodeIPv4Change
- type Option
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 ( // Prefix is versioned prefix for REST urls Prefix = "/contiv/v1/" // PluginURL is versioned URL (using prefix) for IPAM REST endpoint PluginURL = Prefix + "ipam" )
const (
// VxlanBVIInterfaceName is the name of the VXLAN BVI interface.
VxlanBVIInterfaceName = "vxlanBVI"
)
VXLANs
Variables ¶
var DefaultPlugin = *NewPlugin()
DefaultPlugin is a default instance of IPv4Net.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API interface { // GetIfName looks up logical interface name that corresponds to the interface // associated with the given pod. GetIfName(podNamespace string, podName string) (name string, exists bool) // 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. 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 L2 interconnect mode). GetVxlanBVIIfName() string }
API defines methods provided by IPv4Net 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 IPAM ipam.API NodeSync nodesync.API PodManager podmanager.API VPPIfPlugin vpp_ifplugin.API GoVPP GoVPP HTTPHandlers rest.HTTPHandlers }
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 ipv4net just to read some constants etc.
type HostLinkIPsDumpClb ¶
HostLinkIPsDumpClb is callback for dumping all IP addresses assigned to interfaces in the host stack.
type IPAMData ¶
type IPAMData struct { NodeID uint32 `json:"nodeId"` NodeName string `json:"nodeName"` NodeIP string `json:"nodeIP"` PodSubnetThisNode string `json:"podSubnetThisNode"` VppHostNetwork string `json:"vppHostNetwork"` Config *contivconf.IPAMConfigForJSON `json:"config"` }
IPAMData defines attributes exposed by the IPAM REST handler.
type IPv4Net ¶
type IPv4Net struct { Deps // contains filtered or unexported fields }
IPv4Net plugin builds configuration to be applied by ligato/VPP-agent for VPP-based IPv4 network connectivity between Kubernetes pods and nodes.
func (*IPv4Net) Close ¶
Close is called by the plugin infra upon agent cleanup. It cleans up the resources allocated by the plugin.
func (*IPv4Net) GetHostIPs ¶
GetHostIPs returns all IP addresses of this node present in the host network namespace (Linux).
func (*IPv4Net) GetHostInterconnectIfName ¶
GetHostInterconnectIfName returns the name of the TAP/AF_PACKET interface interconnecting VPP with the host stack.
func (*IPv4Net) GetIfName ¶
GetIfName looks up logical interface name that corresponds to the interface associated with the given POD name.
func (*IPv4Net) 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 (*IPv4Net) 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 L2 interconnect mode).
func (*IPv4Net) HandlesEvent ¶
func (n *IPv4Net) HandlesEvent(event controller.Event) bool
HandlesEvent selects:
- any Resync event (extra action for NodeIPv4Change)
- AddPod and DeletePod
- NodeUpdate for other nodes
- Shutdown event
func (*IPv4Net) Init ¶
Init initializes attributes/callbacks used to access the plugin-external state. Internal state is initialized later by the first resync.
func (*IPv4Net) Resync ¶
func (n *IPv4Net) 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 (*IPv4Net) Revert ¶
func (n *IPv4Net) Revert(event controller.Event) error
Revert is called for AddPod.
func (IPv4Net) StateToString ¶
func (s IPv4Net) StateToString() string
StateToString returns human-readable string representation of the ipv4net plugin internal state. The method cannot be called String(), otherwise it overloads the Stringer from PluginDeps.
func (*IPv4Net) Update ¶
func (n *IPv4Net) Update(event controller.Event, txn controller.UpdateOperations) (change string, err error)
Update is called for:
- AddPod and DeletePod
- 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.