# mellanox/ib-kubernetes architecture

> Architecture diagram of the GitHub repository mellanox/ib-kubernetes, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mellanox/ib-kubernetes
- Repository: https://github.com/mellanox/ib-kubernetes

## Overview

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: [`pkg/daemon/daemon.go`](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/daemon/daemon.go) (Daemon), [`pkg/sm/plugin_loader.go`](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugin_loader.go) (Plugin Loader), [`pkg/watcher/watcher.go`](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/watcher.go) (Watcher), [`pkg/watcher/handler/pod.go`](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/handler/pod.go) (Pod Handler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_runtime["Runtime"]
  node_cmd_main["Main<br/>entrypoint<br/>[main.go]"]
  node_daemon(("Daemon<br/>orchestrator<br/>[daemon.go]"))
  node_config["Config<br/>settings<br/>[config.go]"]
end

subgraph group_grp_k8s["Kubernetes"]
  node_watcher(("Watcher<br/>event loop<br/>[watcher.go]"))
  node_pod_handler["Pod Handler<br/>pod events<br/>[pod.go]"]
  node_nad_handler["NAD Handler<br/>network defs<br/>[nad.go]"]
  node_k8s_client["K8s Client<br/>api wrapper<br/>[client.go]"]
end

subgraph group_grp_fabric["Fabric"]
  node_plugin_loader["Plugin Loader<br/>[plugin_loader.go]"]
  node_plugin_iface["Plugin API<br/>interface<br/>[plugin.go]"]
  node_noop_plugin["Noop Plugin<br/>plugin impl<br/>[noop.go]"]
  node_ufm_plugin["UFM Plugin<br/>plugin impl<br/>[ufm.go]"]
  node_http_client["HTTP Driver<br/>rest client<br/>[client.go]"]
end

subgraph group_grp_shared["Shared"]
  node_guid[("GUID Pool<br/>allocation<br/>[guid_pool.go]")]
  node_sync_map[("Sync Map<br/>state store")]
  node_errcode["Errcode<br/>errors<br/>[errcode.go]"]
end

subgraph group_grp_deploy["Deploy"]
  node_deployment["Manifests<br/>deployment<br/>[ib-kubernetes.yaml]"]
end

node_cmd_main -->|"starts"| node_daemon
node_daemon -->|"loads"| node_config
node_daemon -->|"runs"| node_watcher
node_daemon -->|"uses"| node_k8s_client
node_daemon -->|"allocates"| node_guid
node_daemon -->|"loads plugin"| node_plugin_loader
node_watcher -->|"dispatches"| node_pod_handler
node_watcher -->|"dispatches"| node_nad_handler
node_pod_handler -->|"reads"| node_k8s_client
node_nad_handler -->|"reads"| node_k8s_client
node_pod_handler -->|"requests"| node_guid
node_guid -->|"tracks"| node_sync_map
node_plugin_loader -->|"binds to"| node_plugin_iface
node_plugin_loader -->|"can load"| node_noop_plugin
node_plugin_loader -->|"can load"| node_ufm_plugin
node_ufm_plugin -->|"calls"| node_http_client
node_daemon -.->|"reports"| node_errcode
node_deployment -.->|"supplies"| node_config
node_deployment -.->|"configures"| node_plugin_loader

click node_cmd_main "https://github.com/mellanox/ib-kubernetes/blob/master/cmd/ib-kubernetes/main.go"
click node_daemon "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/daemon/daemon.go"
click node_config "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/config/config.go"
click node_watcher "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/watcher.go"
click node_pod_handler "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/handler/pod.go"
click node_nad_handler "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/handler/nad.go"
click node_k8s_client "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/k8s-client/client.go"
click node_guid "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/guid/guid_pool.go"
click node_sync_map "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/utils/synchronized_map.go"
click node_errcode "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/errcode/errcode.go"
click node_plugin_loader "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugin_loader.go"
click node_plugin_iface "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/plugin.go"
click node_noop_plugin "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/noop/noop.go"
click node_ufm_plugin "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/ufm/ufm.go"
click node_http_client "https://github.com/mellanox/ib-kubernetes/blob/master/pkg/drivers/http/client.go"
click node_deployment "https://github.com/mellanox/ib-kubernetes/blob/master/deployment/ib-kubernetes.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cmd_main,node_daemon,node_config toneBlue
class node_watcher,node_pod_handler,node_nad_handler,node_k8s_client toneAmber
class node_plugin_loader,node_plugin_iface,node_noop_plugin,node_ufm_plugin,node_http_client toneMint
class node_guid,node_sync_map,node_errcode toneRose
class node_deployment toneIndigo
```

## Components

### Runtime

Daemon entrypoint and orchestration

- [Main](https://github.com/mellanox/ib-kubernetes/blob/master/cmd/ib-kubernetes/main.go): entrypoint · Process entrypoint for the daemon · `cmd/ib-kubernetes/main.go`
- [Daemon](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/daemon/daemon.go): orchestrator · Central runtime wiring config, watches, GUIDs, and plugin calls · `pkg/daemon/daemon.go`
- [Config](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/config/config.go): settings · Runtime configuration loading and validation · `pkg/config/config.go`

### Kubernetes

API access and event watchers

- [Watcher](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/watcher.go): event loop · Resource watch loop for Kubernetes events · `pkg/watcher/watcher.go`
- [Pod Handler](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/handler/pod.go): pod events · Handles pod create/update/delete reactions · `pkg/watcher/handler/pod.go`
- [NAD Handler](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/watcher/handler/nad.go): network defs · Handles NetworkAttachmentDefinition changes · `pkg/watcher/handler/nad.go`
- [K8s Client](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/k8s-client/client.go): api wrapper · Kubernetes API access wrapper · `pkg/k8s-client/client.go`

### Fabric

Subnet-manager integration and plugins

- [Plugin Loader](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugin_loader.go): loader · Loads the subnet-manager plugin from configuration · `pkg/sm/plugin_loader.go`
- [Plugin API](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/plugin.go): interface · Boundary contract for subnet-manager implementations · `pkg/sm/plugins/plugin.go`
- [Noop Plugin](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/noop/noop.go): plugin impl · Test and development plugin implementation · `pkg/sm/plugins/noop/noop.go`
- [UFM Plugin](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/sm/plugins/ufm/ufm.go): plugin impl · Real fabric control via UFM integration · `pkg/sm/plugins/ufm/ufm.go`
- [HTTP Driver](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/drivers/http/client.go): rest client · HTTP client used by the UFM plugin · `pkg/drivers/http/client.go`

### Shared

Common helpers and state

- [GUID Pool](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/guid/guid_pool.go): allocation · GUID range and assignment management · `pkg/guid/guid_pool.go`
- [Sync Map](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/utils/synchronized_map.go): state store · Synchronized in-memory tracking used by allocation logic · `pkg/utils/synchronized_map.go`
- [Errcode](https://github.com/mellanox/ib-kubernetes/blob/master/pkg/errcode/errcode.go): errors · Shared error codes and translation · `pkg/errcode/errcode.go`

### Deploy

Manifests and runtime packaging

- [Manifests](https://github.com/mellanox/ib-kubernetes/blob/master/deployment/ib-kubernetes.yaml): deployment · Kubernetes config, secret, and workload manifests · `deployment/ib-kubernetes.yaml`

## Connections

- 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
