How jovik31/tenantcni works
1. What this repository is
- TenantCNI is a Go-based Kubernetes operator plus node-side networking component for multi-tenant pod networking.
- It registers a custom resource definition (CRD) for Tenant objects and uses those objects to create isolated tenant network behavior inside a cluster.
2. Top-level runtime split
- cmd/tenantcni is the operator/control-plane binary.
- cmd/tenantcnid is the node-side daemon/binary that likely participates in CNI and per-node network setup.
- The repository is therefore split across a Kubernetes reconciliation plane and a node networking plane.
3. Custom API boundary
- The API lives under pkg/apis/jovik31.dev/v1alpha1.
- The main custom resource is Tenant, with generated deepcopy/defaulting code, showing that tenant state is meant to be a first-class Kubernetes object.
- pkg/crd/register.go handles CRD registration, making the tenant API available through the Kubernetes API server.
4. Generated Kubernetes client stack
- The pkg/client tree is fully generated client machinery: typed clients, informers, listers, fake clients, and apply configurations.
- This indicates the operator is built in the standard Kubernetes pattern: watch resources through shared informers, cache them with listers, and reconcile via the typed client against the API server.
5. Controller/reconciliation layer
- pkg/controller contains the reconciliation logic, split into add.go, update.go, delete.go, handlers.go, and utility code.
- This is the main orchestration layer that reacts to Tenant lifecycle events and likely creates or tears down tenant-specific network state and related Kubernetes objects.
- The controller boundary is the core decision point between desired tenant state and actual network configuration.
6. Network subsystem
- pkg/network/backend contains two backends: bridge.go and vxlan.go.
- This implies the system can realize tenant networking using either Linux bridge-based attachment or VXLAN-based overlay networking.
- pkg/network/routing contains iptables.go and routes.go, showing that packet forwarding and tenant isolation are enforced with host routing and firewall rules.
- The architecture therefore spans both Kubernetes control logic and node-level Linux networking primitives.
7. IP address management
- pkg/network/ipam is the allocation subsystem.
- It has separate stores for node, pod, and tenant, plus locking support, which suggests coordinated address/lease management across cluster objects and nodes.
- This is an important boundary: IP allocation is not incidental; it is a dedicated subsystem used to keep tenant networking consistent and prevent collisions.
8. Kubernetes integration and node utilities
- pkg/k8s/kube.go likely wraps Kubernetes client setup and cluster interactions.
- pkg/log/log.go centralizes logging.
- These are supporting boundaries used by both the operator and node daemon to talk to the API server and emit consistent diagnostics.
9. Operational model and data flow
- A tenant is created as a Kubernetes custom resource, then the controller reconciles that desired state into network resources and IPAM state.
- The README indicates a default tenant is created automatically, while custom tenants must exist before pods are scheduled into them.
- Pods targeting custom tenants require both an annotation and a node selector, meaning scheduling is part of the tenant selection mechanism rather than being inferred automatically.
10. Cluster and packet-flow assumptions
- The README states node CIDRs must use a /22 mask so each tenant can get the full 254 pods available in that range.
- That tells you the implementation assumes a fixed per-node address budget and builds tenant allocation around it.
- This is an architectural constraint worth showing in any diagram because it affects capacity and address partitioning.
11. Deployment artifacts
- manifests/operator_deploy.yaml and manifests/local_operator.yaml deploy the operator.
- manifests/tenant_example.yaml, tenant_RED.yaml, tenant_GREEN.yaml, and pod examples document the expected tenant and pod wiring.
- manifests/busybox*.yaml are test workloads for validating tenant-specific networking behavior.
12. Build and generation tooling
- The repo is Go module-based, with Makefile, Dockerfile, and code generation scripts under scripts/.
- The presence of generated client/informer/lister code and deepcopy files means the API is code-generated, not handwritten.
- This matters architecturally because the control plane depends on Kubernetes codegen conventions rather than custom RPC or bespoke control channels.
13. External dependencies and boundaries
- The system depends on the Kubernetes API server, CRD support, Linux networking primitives, and likely CNI execution on nodes.
- The network implementation uses host-level routing/iptables and optional VXLAN overlay, so the trust boundary is the node OS, not just Kubernetes objects.
- In diagram terms, the main external edges are: Kubernetes API, node networking stack, and pod scheduling behavior.
14. How to draw the architecture
- Put the Kubernetes API server at the center top.
- Connect the operator binary to it via CRD watch/reconcile loops.
- Show the Tenant CRD as the desired-state input.
- Show the IPAM, routing, and backend modules as controller-owned subsystems.
- Show the node daemon/CNI path on each node as the layer that realizes bridge/VXLAN/routing configuration for tenant pods.
Main entry points: controller Controller · tenantcnid/main.go tenantcnid · tenantcni/main.go tenantcni · ipam.go IPAM
Components 18
Control plane
Operator-side reconciliation and Kubernetes API integration.
- tenantcni · Control-plane entrypoint for tenant reconciliation.
cmd/tenantcni/main.go - Controller · Handles tenant add, update, delete, and event wiring.
pkg/controller - Kube client · Shared Kubernetes client and cluster interaction helpers.
pkg/k8s/kube.go - Logging · Centralized logging helpers used by both runtimes.
pkg/log/log.go
Tenant API
Custom resource definition and generated Kubernetes accessors.
- CRD register · Registers the Tenant CRD with the API server.
pkg/crd/register.go - Tenant API · Tenant object schema and defaults for desired tenant state.
pkg/apis/jovik31.dev/v1alpha1/types.go - Clientset · Typed Kubernetes client for the Tenant API.
pkg/client/clientset/versioned/clientset.go - Informer · Shared informer factory for watching Tenant resources.
pkg/client/informers/externalversions/factory.go - Lister · Cached read access to Tenant objects.
pkg/client/listers/jovik31.dev/v1alpha1/tenant.go
Node networking
Per-node data plane and Linux networking primitives.
- tenantcnid · Node-side runtime for tenant networking setup.
cmd/tenantcnid/main.go - IPAM · Coordinates tenant, pod, and node address allocation.
pkg/network/ipam/ipam.go - IP stores · Persistent stores and locking for node, pod, and tenant allocation.
pkg/network/ipam - Bridge · Linux bridge-based tenant attachment path.
pkg/network/backend/bridge.go - VXLAN · Overlay backend for tenant traffic isolation.
pkg/network/backend/vxlan.go - Routing · Routes and iptables rules that enforce forwarding and isolation.
pkg/network/routing
Connections 21
- tenantcni → Controller: starts · Operator binary hosts reconciliation logic.
- tenantcni → Kube client: uses · Connects to the Kubernetes API.
- tenantcni → Logging: logs · Emits operator diagnostics.
- tenantcnid → Bridge: configures · Programs bridge-based networking on nodes.
- tenantcnid → VXLAN: configures · Programs overlay networking on nodes.
- tenantcnid → Routing: applies · Installs routing and firewall policy.
- tenantcnid → IPAM: allocates · Coordinates node-local and cluster-wide IP usage.
- CRD register → Tenant API: registers · Exposes Tenant as a Kubernetes resource.
- Controller → Informer: watches · Consumes Tenant change events.
- Controller → Lister: reads · Uses cached Tenant state for reconciliation.
- Controller → Clientset: writes · Creates and updates Kubernetes resources.
- Controller → IPAM: drives · Allocates and releases tenant networking state.
- Controller → Bridge: selects · Can realize tenant connectivity with bridge backend.
- Controller → VXLAN: selects · Can realize tenant connectivity with VXLAN backend.
- Controller → Routing: programs · Pushes forwarding and isolation rules.
- IPAM → IP stores: persists · Uses stores and locks for allocation consistency.
- Manifests → CRD register: deploys · Contains operator and Tenant example manifests.
- Codegen → Clientset: generates · Produces typed clients and informers.
- Codegen → Tenant API: generates · Produces deepcopy and defaulting code.
- Build → tenantcni: builds · Build target for operator binary.
- Build → tenantcnid: builds · Build target for node daemon binary.