This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Flannel is a network fabric for Kubernetes that provides layer 3 IPv4 networking between nodes in a cluster. The main binary is flanneld, which runs on each host and allocates subnet leases from a larger preconfigured address space.
Build for amd64 (in Docker container):
make dist/flanneld-amd64Build for specific architecture:
ARCH=arm64 make dist/flanneld-arm64
ARCH=s390x make dist/flanneld-s390xBuild multi-arch image:
make buildx-create-builder # One-time setup
make build-multi-archBuild natively (requires CGO for amd64):
CGO_ENABLED=1 make dist/flanneldRun all tests (includes license check, gofmt, unit tests, e2e tests):
make testRun unit tests only:
make unit-testRun e2e tests:
make e2e-testRun tests for specific packages:
TEST_PACKAGES="pkg/ip pkg/subnet" make unit-testCheck formatting:
make gofmtVerify go modules:
make verify-modulesUpdate dependencies:
make deps # runs go mod tidy && go mod vendorInstall binary locally (for quick iteration):
make installmain.go: Entry point that:
- Parses command-line flags (etcd endpoints, kube config, interface selection, etc.)
- Initializes the subnet manager (etcd or kube)
- Starts the backend network
- Manages traffic rules (iptables/nftables)
Backend System (pkg/backend/):
Backends are registered via init() and implement the network encapsulation layer:
vxlan: VXLAN encapsulation (recommended, default port 8472)host-gw: Direct IP routes via layer 2wireguard: WireGuard encrypted tunnelsipsec: IPsec encrypted tunnels with strongSwanudp: Simple UDP encapsulation (debug only)ipip: IP-in-IP encapsulationtencentvpc: Tencent Cloud VPC integrationalloc: Experimental allocation-only backendextension: External backend plugin support
Backends are imported with blank identifier in main.go to trigger registration:
_ "github.com/flannel-io/flannel/pkg/backend/vxlan"Subnet Managers (pkg/subnet/):
Two implementations for storing/retrieving network configuration:
etcd: Uses etcd v3 as datastore (standalone deployments)kube: Uses Kubernetes API as datastore (kube subnet manager mode, no separate etcd needed)
Traffic Management (pkg/trafficmngr/):
Manages forwarding rules and masquerading using either iptables or nftables.
pkg/ip: IP address utilities and subnet operationspkg/ipmatch: IP address matching and selection (interface selection logic)pkg/lease: Subnet lease managementpkg/routing: Route table managementpkg/ns: Network namespace utilitiespkg/version: Version information
CGO_ENABLED: Set to 1 for amd64 (enables UDP backend), 0 for other architectures.
Cross-compilation: Uses Docker with golang:1.25 image and qemu-user-static for cross-arch builds.
Version embedding: Git tag/commit is embedded via ldflags:
-ldflags '-X github.com/flannel-io/flannel/pkg/version.Version=$(TAG)'
Unit tests: Run in Docker with NET_ADMIN and SYS_ADMIN capabilities to test network operations and namespace creation.
E2E tests: Use bash_unit framework with Docker Compose. Build test images with dist/flanneld-e2e-$(TAG)-$(ARCH).docker target.
Functional tests: Located in dist/functional-test.sh and dist/functional-test-k8s.sh.
Go version: 1.25 (see Makefile GO_VERSION)
Supported architectures: amd64, arm, arm64, s390x, ppc64le, riscv64
Container registry: quay.io/coreos/flannel (override with REGISTRY env var)
Default test packages:
pkg/ip pkg/subnet pkg/subnet/etcd pkg/subnet/kube pkg/trafficmngr pkg/backend
See Documentation/building.md for full details. Key steps:
- Create and push a git tag
- Run
make releaseto build all architectures - Run
make release-manifestto generate kube-flannel.yml - Run
make release-helmto package Helm chart - Upload artifacts from
dist/to GitHub release
Interface selection: Flannel selects interfaces via -iface, -iface-regex, or -iface-can-reach flags. Logic in pkg/ipmatch.
Backend issues: Check backend-specific documentation in Documentation/backends.md.
Subnet conflicts: Network configuration stored in etcd or Kubernetes configmap/node annotations (depending on subnet manager).