How netbox-community/netbox-operator works
Main components
• Kubernetes Cluster: This is where the operator runs and where the custom resources (CRs) are created.
• NetBox Operator (Controller): The core of the application, with its code located in the cmd/ and internal/controller directories. This component continuously watches and reconciles the custom resources.
• Custom Resource Definitions (CRDs): Found under the api/v1 and config/crd directories, these define resources like IpAddress, IpAddressClaim, Prefix, and PrefixClaim.
• NetBox API Integration: This logic is encapsulated in the pkg/netbox directory (api, models, utils) which handles all interaction with a remote NetBox instance.
• External NetBox Service: The actual NetBox instance (or instances) to which the operator connects to assign and manage IP addresses and prefixes.
• Supporting components:
• Configuration layers and manifests in the config directories (default, manager, RBAC, samples, etc.) that define how the operator is deployed.
• CI/CD and testing tooling (provided by GitHub workflows, tests, and kind cluster sample configurations) to ensure proper deployment and functionality.
Relationships and interactions
• The operator running inside the Kubernetes cluster listens for changes on Custom Resources (e.g. PrefixClaim, IpAddressClaim).
• On detecting a new, updated, or deleted CR, the operator’s reconciliation loop engages.
• There is an API gateway within the operator that communicates with the NetBox instance using the NetBox API client (pkg/netbox/api). These calls allow the operator to create, update, or delete network resources in NetBox.
• The CRDs communicate both with the Kubernetes API and the operator’s business logic that integrates with the NetBox API.
• There is also an important restoration path that uses custom fields (like preserveInNetbox and netboxOperatorRestorationHash) to ensure that state can be recovered if necessary.
Architectural patterns and design principles
• Operator Pattern: This is visible in the reconciliation loop and custom resource handling present in the internal/controller and cmd/main.go files.
• Separation of concerns: There is a clear separation between Kubernetes API interactions, NetBox API communications, and controller logic.
• Modularity and testability: The project uses packages (e.g., pkg/netbox, internal/controller) to separate responsibilities, along with extensive tests in the tests/e2e directory.
• Extensibility: With support for both IP addresses and prefixes (and their “claims”), the system design anticipates mixed usage scenarios and provides configuration samples and guides for advanced users.