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
- func AllocateIP(cidr, containerID string) (net.IP, error)
- func BridgeIP(cidr string) net.IP
- func EnsureBridge(name, podCIDR string) error
- func LoadInputs() (*Config, *Args, error)
- func MaskBits(cidr string) string
- func PlugPod(args *Args, ip net.IP, cfg *Config) error
- func ReleaseIP(containerID string) error
- func UnplugPod(args *Args) error
- type Args
- type Config
Constants ¶
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 ¶
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 ¶
BridgeIP returns the .1 address of the pod CIDR — the bridge's gateway address that pods use as their default route.
func EnsureBridge ¶
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 ¶
LoadInputs parses stdin (CNI config JSON) + the standard CNI env vars. Returns (cfg, args, err).
func PlugPod ¶
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.
Types ¶
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.