plugin

package
v0.13.7-dev Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package plugin contains the load-bearing logic for the outpost-cni binary, factored out so the tiny main package stays under 100 lines.

Linux-only. The CNI binary will never run on non-Linux hosts (kubelet only invokes CNI plugins on Linux nodes); a non-Linux stub keeps the package buildable for tooling that walks the whole tree.

Index

Constants

View Source
const IPAMDir = "/var/lib/cloudbox/cni/ipam"

IPAMDir is where per-container IP allocations are persisted as <container-id>.ip → "10.42.5.7" text files. State outlives the kubelet process — it's the authority on which IPs are free.

0o700 so non-root can't snoop pod IPs (defense-in-depth; pod IPs aren't secret but root-only is the right default).

Variables

This section is empty.

Functions

func AllocateIP

func AllocateIP(cidr, containerID string) (net.IP, error)

AllocateIP grabs the next-free address in cidr and persists it. Skips .0 (network), .1 (bridge gateway), and the broadcast address. Idempotent on (containerID): if a file already exists, returns that IP — handy when kubelet retries ADD on a transient failure.

func BridgeIP

func BridgeIP(cidr string) net.IP

BridgeIP returns the .1 address of the pod CIDR — the bridge's gateway address that pods use as their default route.

func EnsureBridge

func EnsureBridge(name, podCIDR string) error

EnsureBridge creates the per-node Linux bridge if missing and assigns it the .1 address from the pod CIDR. Idempotent — safe to call on every CNI ADD. Uses iproute2 (`ip` command) rather than vishvananda/netlink to keep the CNI binary's footprint minimal; iproute2 is on every reasonable Linux distro k3s runs on.

Also enables IP forwarding (sysctl net.ipv4.ip_forward=1) since the bridge wouldn't forward pod packets otherwise. Idempotent.

func LoadInputs

func LoadInputs() (*Config, *Args, error)

LoadInputs parses stdin (CNI config JSON) + the standard CNI env vars. Returns (cfg, args, err).

func MaskBits

func MaskBits(cidr string) string

MaskBits extracts the prefix-length string from a CIDR. "10.42.5.0/24" → "24".

func PlugPod

func PlugPod(args *Args, ip net.IP, cfg *Config) error

PlugPod creates the veth pair, moves one end into the pod's netns with the assigned IP + gateway, and attaches the host end to the bridge.

func ReleaseIP

func ReleaseIP(containerID string) error

ReleaseIP removes the file for containerID. Best-effort; CNI DEL semantics expect idempotence so a missing file is fine.

func UnplugPod

func UnplugPod(args *Args) error

UnplugPod removes the host-end veth. The pod-end disappears with the pod's netns. Best-effort: failures are swallowed (CNI DEL must be idempotent and tolerant of "already cleaned up" states).

Types

type Args

type Args struct {
	ContainerID string
	Netns       string
	IfName      string
}

Args is the subset of CNI env vars we use.

type Config

type Config struct {
	CNIVersion string `json:"cniVersion"`
	Name       string `json:"name"`
	Type       string `json:"type"`
	PodCIDR    string `json:"pod_cidr"`
	BridgeName string `json:"bridge_name,omitempty"`
}

Config is the JSON kubelet hands us on stdin. The cniVersion + type fields are CNI-spec required; pod_cidr + bridge_name are our custom fields the conflist generator wires in.

Jump to

Keyboard shortcuts

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