MCPcopy Index your code
hub / github.com/digitalocean/netbox-ip-controller

github.com/digitalocean/netbox-ip-controller @v0.4.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.3 ↗ · + Follow
276 symbols 898 edges 54 files 158 documented · 57%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

NetBox IP Controller

This controller watches Kubernetes pods and services and imports their IPs, along with some metadata such as domain names and Kubernetes labels, into NetBox.

Configuration

Controller configuration may be specified with either flags or environment variables, with flags taking precedence. For each of the flags listed below, the corresponding environment variable is all-uppercase with dashes (-) replaced with underscores (_).

Flag Default Description
netbox-api-url The URL of the NetBox API to connect to: scheme://host:port/path. Required.
netbox-token NetBox API token to use for authentication. Required.
kube-config Path to the kubeconfig file containing the address of the kube-apiserver to connect to and authentication info. The cluster you want the controller to connect to should be set as current context in the kubeconfig. Leave empty if the controller is running in-cluster. Optional.
netbox-ca-cert-path Absolute path to a file containing a PEM-encoded root certificate to verify NetBox server's certificate
kube-qps 20 Maximum number of requests per second to the kube-apiserver. Optional.
kube-burst 30 Maximum number of requests to the kube-apiserver allowed to accumulate before throttling begins. Optional.
netbox-qps 100 Average allowable requests per second to NetBox API, i.e., the rate limiter's token bucket refill rate per second
netbox-burst 1 Maximum allowable burst of requests to NetBox API, i.e. the rate limiter's token bucket size
metrics-addr :8001 Sets the address that the controller will bind to for serving metrics. Can be a full TCP address or only a port (e.g. :8081). Optional.
cluster-domain cluster.local Domain name of the cluster. Optional.
pod-ip-tags kubernetes,k8s-pod Comma-separated list of tags to add to pod IPs in NetBox. Any tags that don't yet exist will be created. Optional.
service-ip-tags kubernetes,k8s-service Comma-separated list of tags to add to service IPs in NetBox. Any tags that don't yet exist will be created. Optional.
pod-publish-labels app Comma-separated list of kubernetes pod labels to be added to the IP description in NetBox in label: label_value format. Only the IPs of the pods that have at least one of these labels set will be exported. Set to an empty list if you do not want pod IPs exported. Optional.
service-publish-labels app Comma-separated list of kubernetes service labels to be added to the IP description in NetBox in label: label_value format. Only the IPs of the services that have at least one of these labels set will be exported. Set to an empty list if you do not want service IPs exported. Optional.
dual-stack-ip false Enables registering both IPv4 and IPv6 addresses of pods and services where applicable in dual stack clusters. Optional.
ready-check-addr :5001 Sets the address that the controller manager will bind to for serving the ready check endpoint. Can be a full TCP address or only a port (e.g. :5001). Optional.
debug false Turns on debug logging. Optional.

Running locally

The most basic setup includes a NetBox and Kubernetes apiserver to connect to. The controller will be using current-context from the specified kubeconfig:

go get github.com/digitalocean/netbox-ip-controller/cmd/netbox-ip-controller
netbox-ip-controller --kube-config=/.kube/config --netbox-api-url=https://some-netbox.example.com/api --netbox-token=<your-token> \

Running integration tests locally

Integration tests can be run locally by using the integration-test make target. This sets up, executes, and cleans up the integration test. Alternatively, you can use the setup, execute, and cleanup targets individually, which can be helpful for leaving the netbox environment up after executing tests for debugging.

Install

A sample deployment for running in-cluster can be found at docs/example-deployment.yml. Note that the controller will only export the IPs of the pods and services that have at least one of --pod-publish-labels or --service-publish-labels respectively set.

If you have RBAC enabled in the cluster, you will also need docs/rbac.yml.

Docker images are automatically built and distributed for each release and can be found at digitalocean/netbox-ip-controller:<tag>. Image tags will always correspond to a release's version number.

Alternatively, you can build and host the image yourself. After cloning the repo, build and push the docker image:

docker build -t <username>/netbox-ip-controller:<tag> ./cmd/netbox-ip-controller/
docker push <username>/netbox-ip-controller:<tag>

and use <username>/netbox-ip-controller:<tag> in your deployment manifest.

Uninstall

After stopping netbox-ip-controller, the IP addresses published to NetBox by the controller will remain. You can perform cleanup by running netbox-ip-controller clean, which will delete the IPs from NetBox and remove NetBoxIP custom resource objects from the cluster. Make sure to supply the same netbox-api-url, netbox-token, and kube-config (if any) as those used by the running controller.

Contributing

Contributions are welcome and appreciated. To help us review code and resolve issues faster, please follow the guidelines.

License

Copyright 2022 DigitalOcean

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Extension points exported contracts — how you extend this code

NetBoxIPsGetter (Interface)
NetBoxIPsGetter has a method to return a NetBoxIPInterface. A group's client should implement this interface. [4 implementers]
client/clientset/versioned/typed/netbox/v1beta1/netboxip.go
Controller (Interface)
Controller is responsible for updating IPs of a single k8s resource. [3 implementers]
internal/controller/controller.go
GenericInformer (Interface)
GenericInformer is type of SharedIndexInformer which will locate and delegate to other sharedInformers based on type [2 …
client/informers/externalversions/generic.go
Client (Interface)
Client is a netbox client. [2 implementers]
internal/netbox/client.go
NetBoxIPLister (Interface)
NetBoxIPLister helps list NetBoxIPs. All objects returned here must be treated as read-only. [1 implementers]
client/listers/netbox/v1beta1/netboxip.go
NetboxV1beta1Interface (Interface)
(no doc) [2 implementers]
client/clientset/versioned/typed/netbox/v1beta1/netbox_client.go
Option (FuncType)
Option can be used to tune controller settings.
internal/controller/controller.go
NetBoxIPInformer (Interface)
NetBoxIPInformer provides access to a shared informer and lister for NetBoxIPs. [2 implementers]
client/informers/externalversions/netbox/v1beta1/netboxip.go

Core symbols most depended-on inside this repo

Error
called by 34
internal/netbox/log.go
Get
called by 24
client/listers/netbox/v1beta1/netboxip.go
Info
called by 16
internal/netbox/log.go
NetboxV1beta1
called by 9
client/clientset/versioned/clientset.go
executeRequest
called by 8
internal/netbox/client.go
NetBoxIPs
called by 7
client/listers/netbox/v1beta1/netboxip.go
Create
called by 7
client/clientset/versioned/typed/netbox/v1beta1/netboxip.go
Update
called by 7
client/clientset/versioned/typed/netbox/v1beta1/netboxip.go

Shape

Method 116
Function 96
Struct 39
Interface 17
FuncType 5
TypeAlias 3

Languages

Go100%

Modules by API surface

internal/netbox/client.go23 symbols
client/informers/externalversions/factory.go16 symbols
internal/netbox/types.go15 symbols
cmd/netbox-ip-controller/integration_test.go14 symbols
cmd/netbox-ip-controller/root.go13 symbols
client/listers/netbox/v1beta1/netboxip.go13 symbols
client/clientset/versioned/typed/netbox/v1beta1/netboxip.go13 symbols
internal/controller/controller.go11 symbols
client/clientset/versioned/typed/netbox/v1beta1/netbox_client.go10 symbols
client/clientset/versioned/clientset.go10 symbols
client/informers/externalversions/netbox/v1beta1/netboxip.go9 symbols
api/netbox/v1beta1/zz_generated.deepcopy.go9 symbols

For agents

$ claude mcp add netbox-ip-controller \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact