How mellanox/ib-kubernetes works
1. What the system is
ib-kubernetes is a node-level Kubernetes daemon for InfiniBand workloads. It runs alongside the cluster and bridges Kubernetes pod lifecycle events with InfiniBand fabric configuration, especially GUID and PKey management for pods annotated for InfiniBand use.
2. Process entrypoint and control plane
The binary starts in cmd/ib-kubernetes/main.go and hands off to the daemon layer in pkg/daemon. That daemon is the central orchestrator: it wires configuration, Kubernetes watches, GUID allocation, and subnet-manager plugin calls into one runtime.
3. Kubernetes-facing boundary
pkg/k8s-client wraps Kubernetes API access, while pkg/watcher owns the event loop for resource changes. The watcher has dedicated handlers for Pods and NetworkAttachmentDefinitions (pkg/watcher/handler/pod.go and nad.go), which indicates the system reacts to both workload events and network definition changes.
4. Primary data flow
On pod create/update/delete, the daemon reads the pod’s network annotation, resolves the referenced network CRD/NAD, and extracts the InfiniBand-related parameters. For pods marked with the mellanox.infiniband.app annotation, it computes or reuses a GUID and associates it with the requested PKey so the pod’s InfiniBand network can be configured correctly.
5. GUID management subsystem
pkg/guid implements GUID pool logic, including the configured GUID range boundaries. This is an internal allocation state machine that ensures the daemon can hand out unique GUIDs and track assignments over time, likely coordinated through a synchronized in-memory map from pkg/utils.
6. Subnet manager plugin boundary
The fabric-management side is abstracted behind a plugin interface in pkg/sm/plugins/plugin.go and a plugin loader in pkg/sm/plugin_loader.go. The daemon loads a plugin dynamically from a configured path, so the fabric integration is a runtime-pluggable boundary rather than hardcoded logic.
7. Available plugin implementations
There are two shipped plugins under pkg/sm/plugins: noop for testing/development and ufm for real fabric control. This makes the architecture explicitly extensible: Kubernetes event handling stays stable while the subnet-manager integration can vary by environment.
8. External fabric integration
The UFM plugin uses the HTTP client in pkg/drivers/http to talk to Mellanox UFM’s REST API. Authentication and TLS material come from a Kubernetes Secret, so the external trust boundary is UFM over HTTP/S, with credentials and certificate data injected at deployment time.
9. Configuration and deployment model
Runtime configuration is Kubernetes-native: a ConfigMap supplies daemon settings like plugin name, plugin path, periodic update interval, and GUID pool range; a Secret supplies UFM credentials/certificate. The manifests under deployment/ suggest it is deployed as cluster infrastructure, typically as a daemonized workload.
10. Supporting code and build boundaries
pkg/errcode, pkg/ib-utils, and pkg/utils provide shared helpers and error handling, while the mocks directories and Ginkgo-style suite files show the project is test-heavy around these boundaries. Build and release are container-oriented (Dockerfile, Makefile, GitHub Actions workflows), but those affect packaging rather than the runtime architecture.
Main entry points: daemon.go Daemon · plugin_loader.go Plugin Loader · watcher.go Watcher · pod.go Pod Handler
Components 16
Runtime
Daemon entrypoint and orchestration
Kubernetes
API access and event watchers
- Watcher · Resource watch loop for Kubernetes events
pkg/watcher/watcher.go - Pod Handler · Handles pod create/update/delete reactions
pkg/watcher/handler/pod.go - NAD Handler · Handles NetworkAttachmentDefinition changes
pkg/watcher/handler/nad.go - K8s Client · Kubernetes API access wrapper
pkg/k8s-client/client.go
Fabric
Subnet-manager integration and plugins
- Plugin Loader · Loads the subnet-manager plugin from configuration
pkg/sm/plugin_loader.go - Plugin API · Boundary contract for subnet-manager implementations
pkg/sm/plugins/plugin.go - Noop Plugin · Test and development plugin implementation
pkg/sm/plugins/noop/noop.go - UFM Plugin · Real fabric control via UFM integration
pkg/sm/plugins/ufm/ufm.go - HTTP Driver · HTTP client used by the UFM plugin
pkg/drivers/http/client.go
Shared
Common helpers and state
Deploy
Manifests and runtime packaging
- Manifests · Kubernetes config, secret, and workload manifests
deployment/ib-kubernetes.yaml
Connections 19
- Main → Daemon: starts · Main hands off control to daemon orchestration
- Daemon → Config: loads · Daemon reads runtime settings
- Daemon → Watcher: runs · Daemon starts the Kubernetes event loop
- Daemon → K8s Client: uses · Daemon coordinates Kubernetes API access through the client
- Daemon → GUID Pool: allocates · Daemon assigns and reuses GUIDs for pods
- Daemon → Plugin Loader: loads plugin · Daemon loads the configured subnet-manager plugin
- Watcher → Pod Handler: dispatches · Pod events flow into pod handler
- Watcher → NAD Handler: dispatches · Network-definition events flow into NAD handler
- Pod Handler → K8s Client: reads · Pod handling depends on Kubernetes object lookups
- NAD Handler → K8s Client: reads · NAD handling depends on Kubernetes object lookups
- Pod Handler → GUID Pool: requests · Pod handling requests GUID assignment or reuse
- GUID Pool → Sync Map: tracks · Pool state is maintained in synchronized memory
- Plugin Loader → Plugin API: binds to · Loader instantiates implementations behind the interface
- Plugin Loader → Noop Plugin: can load · Development/test plugin implementation
- Plugin Loader → UFM Plugin: can load · Production plugin implementation
- UFM Plugin → HTTP Driver: calls · UFM integration uses REST over HTTP
- Daemon → Errcode: reports · Centralized error handling and codes
- Manifests → Config: supplies · ConfigMap and Secret provide runtime settings
- Manifests → Plugin Loader: configures · Deployment selects plugin path and name