2020-09-08 20:16:17 +03:00
|
|
|
---
|
2021-03-09 13:38:09 +02:00
|
|
|
title: "Developer guide"
|
2020-09-08 20:16:17 +03:00
|
|
|
layout: default
|
2022-11-02 14:34:37 +02:00
|
|
|
sort: 5
|
2020-09-08 20:16:17 +03:00
|
|
|
---
|
|
|
|
|
2021-03-09 13:38:09 +02:00
|
|
|
# Developer guide
|
2021-09-27 15:31:49 +03:00
|
|
|
{: .no_toc}
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
## Table of contents
|
2021-09-27 15:31:49 +03:00
|
|
|
{: .no_toc .text-delta}
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
1. TOC
|
|
|
|
{:toc}
|
|
|
|
|
|
|
|
---
|
|
|
|
|
2021-03-09 13:38:09 +02:00
|
|
|
## Building from source
|
2020-09-08 20:16:17 +03:00
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
### Download the source code
|
2020-09-08 20:16:17 +03:00
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
git clone https://github.com/kubernetes-sigs/node-feature-discovery
|
|
|
|
cd node-feature-discovery
|
|
|
|
```
|
|
|
|
|
2021-03-09 13:38:09 +02:00
|
|
|
### Docker build
|
2020-09-08 20:16:17 +03:00
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
#### Build the container image
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
See [customizing the build](#customizing-the-build) below for altering the
|
|
|
|
container image registry, for example.
|
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
make
|
|
|
|
```
|
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
#### Push the container image
|
2021-02-25 13:49:02 +02:00
|
|
|
|
2020-09-08 20:16:17 +03:00
|
|
|
Optional, this example with Docker.
|
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
docker push <IMAGE_TAG>
|
|
|
|
```
|
|
|
|
|
2021-12-10 13:18:31 +01:00
|
|
|
### Docker multi-arch builds with buildx
|
|
|
|
|
|
|
|
The default set of architectures enabled for mulit-arch builds are `linux/amd64`
|
|
|
|
and `linux/arm64`. If more architectures are needed one can override the
|
|
|
|
`IMAGE_ALL_PLATFORMS` variable with a comma separated list of `OS/ARCH` tuples.
|
|
|
|
|
|
|
|
#### Build the manifest-list with a container image per arch
|
|
|
|
|
|
|
|
```bash
|
|
|
|
make image-all
|
|
|
|
```
|
|
|
|
|
|
|
|
Currently `docker` does not support loading of manifest-lists meaning the images
|
|
|
|
are not shown when executing `docker images`, see:
|
|
|
|
[buildx issue #59](https://github.com/docker/buildx/issues/59).
|
|
|
|
|
|
|
|
#### Push the manifest-list with container image per arch
|
|
|
|
|
|
|
|
```bash
|
|
|
|
make push-all
|
|
|
|
```
|
|
|
|
|
|
|
|
The resulting container image can be used in the same way on each arch by pulling
|
2022-03-29 09:47:42 +03:00
|
|
|
e.g. `node-feature-discovery:{{ site.release }}` without specifying the
|
|
|
|
architecture. The manifest-list will take care of providing the right
|
|
|
|
architecture image.
|
2021-12-10 13:18:31 +01:00
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
#### Change the job spec to use your custom image (optional)
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
To use your published image from the step above instead of the
|
2022-09-12 11:21:12 +03:00
|
|
|
`registry.k8s.io/nfd/node-feature-discovery` image, edit `image`
|
2020-09-08 20:16:17 +03:00
|
|
|
attribute in the spec template(s) to the new location
|
|
|
|
(`<registry-name>/<image-name>[:<version>]`).
|
|
|
|
|
2020-10-01 15:37:34 +03:00
|
|
|
### Deployment
|
|
|
|
|
2021-08-13 17:35:22 +03:00
|
|
|
The `yamls` makefile generates a `kustomization.yaml` matching your locally
|
|
|
|
built image and using the `deploy/overlays/default` deployment. See
|
|
|
|
[build customization](#customizing-the-build) below for configurability, e.g.
|
|
|
|
changing the deployment namespace.
|
2020-10-01 15:37:34 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
K8S_NAMESPACE=my-ns make yamls
|
2021-08-13 17:35:22 +03:00
|
|
|
kubectl apply -k .
|
2020-10-01 15:37:34 +03:00
|
|
|
```
|
|
|
|
|
2021-08-13 17:35:22 +03:00
|
|
|
You can use alternative deployment methods by modifying the auto-generated
|
2023-12-08 14:42:31 +02:00
|
|
|
kustomization file.
|
2020-10-01 15:37:34 +03:00
|
|
|
|
2021-03-09 13:38:09 +02:00
|
|
|
### Building locally
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
You can also build the binaries locally
|
2020-10-20 20:50:46 +03:00
|
|
|
|
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
make build
|
|
|
|
```
|
|
|
|
|
|
|
|
This will compile binaries under `bin/`
|
|
|
|
|
2021-03-09 13:38:09 +02:00
|
|
|
### Customizing the build
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
There are several Makefile variables that control the build process and the
|
|
|
|
name of the resulting container image. The following are targeted targeted for
|
|
|
|
build customization and they can be specified via environment variables or
|
|
|
|
makefile overrides.
|
|
|
|
|
2023-10-25 21:12:47 +02:00
|
|
|
| Variable | Description | Default value |
|
|
|
|
| -------------------------- | ----------------------------------------------------------------- | ------------- |
|
|
|
|
| HOSTMOUNT_PREFIX | Prefix of system directories for feature discovery (local builds) | / (*local builds*) /host- (*container builds*) |
|
|
|
|
| IMAGE_BUILD_CMD | Command to build the image | docker build |
|
|
|
|
| IMAGE_BUILD_EXTRA_OPTS | Extra options to pass to build command | *empty* |
|
|
|
|
| IMAGE_BUILDX_CMD | Command to build and push multi-arch images with buildx | DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build --platform=${IMAGE_ALL_PLATFORMS} --progress=auto --pull |
|
|
|
|
| IMAGE_ALL_PLATFORMS | Comma separated list of OS/ARCH tuples for mulit-arch builds | linux/amd64,linux/arm64 |
|
|
|
|
| IMAGE_PUSH_CMD | Command to push the image to remote registry | docker push |
|
|
|
|
| IMAGE_REGISTRY | Container image registry to use | registry.k8s.io/nfd |
|
|
|
|
| IMAGE_TAG_NAME | Container image tag name | <nfd version> |
|
|
|
|
| IMAGE_EXTRA_TAG_NAMES | Additional container image tag(s) to create when building image | *empty* |
|
|
|
|
| K8S_NAMESPACE | nfd-master and nfd-worker namespace | node-feature-discovery |
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
For example, to use a custom registry:
|
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
make IMAGE_REGISTRY=<my custom registry uri>
|
|
|
|
```
|
|
|
|
|
|
|
|
Or to specify a build tool different from Docker, It can be done in 2 ways:
|
2020-10-20 20:50:46 +03:00
|
|
|
|
2020-09-08 20:16:17 +03:00
|
|
|
1. via environment
|
2021-02-25 13:49:02 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
IMAGE_BUILD_CMD="buildah bud" make
|
|
|
|
```
|
|
|
|
|
2020-10-20 20:50:46 +03:00
|
|
|
1. by overriding the variable value
|
2021-02-25 13:49:02 +02:00
|
|
|
|
|
|
|
```bash
|
|
|
|
make IMAGE_BUILD_CMD="buildah bud"
|
|
|
|
```
|
2020-09-08 20:16:17 +03:00
|
|
|
|
|
|
|
### Testing
|
|
|
|
|
|
|
|
Unit tests are automatically run as part of the container image build. You can
|
2023-11-28 20:27:33 +02:00
|
|
|
also run them manually in the source code tree by running:
|
2020-10-20 20:50:46 +03:00
|
|
|
|
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
make test
|
|
|
|
```
|
|
|
|
|
|
|
|
End-to-end tests are built on top of the e2e test framework of Kubernetes, and,
|
|
|
|
they required a cluster to run them on. For running the tests on your test
|
|
|
|
cluster you need to specify the kubeconfig to be used:
|
2020-10-20 20:50:46 +03:00
|
|
|
|
|
|
|
```bash
|
2020-09-08 20:16:17 +03:00
|
|
|
make e2e-test KUBECONFIG=$HOME/.kube/config
|
|
|
|
```
|
|
|
|
|
2023-12-05 16:45:12 +01:00
|
|
|
There are several environment variables that can be used to customize the
|
|
|
|
e2e-tests:
|
|
|
|
|
|
|
|
| Variable | Description | Default value |
|
|
|
|
| -------------------------- | ----------------------------------------------------------------- | ------------- |
|
|
|
|
| KUBECONFIG | Kubeconfig for running e2e-tests | *empty* |
|
|
|
|
| E2E_TEST_CONFIG | Parameterization file of e2e-tests (see [example][e2e-config-sample]) | *empty* |
|
|
|
|
| E2E_PULL_IF_NOT_PRESENT | True-ish value makes the image pull policy IfNotPresent (to be used only in e2e tests) | false |
|
|
|
|
| E2E_TEST_FULL_IMAGE | Run e2e-test also against the Full Image tag | false |
|
|
|
|
| E2E_GINKGO_LABEL_FILTER | Ginkgo label filter to use for running e2e tests | *empty* |
|
|
|
|
| OPENSHIFT | Non-empty value enables OpenShift specific support (only affects e2e tests) | *empty* |
|
|
|
|
|
2020-09-08 20:16:17 +03:00
|
|
|
### NFD-Master
|
|
|
|
|
2024-12-12 20:25:40 +02:00
|
|
|
For development and debugging it is possible to run nfd-master as a stand-alone
|
|
|
|
binary outside the cluster. The `-no-publish` flag can be used to prevent
|
|
|
|
nfd-master making changes to the nodes. If `-no-publish` is not set, nfd-master
|
|
|
|
also requires the `NODE_NAME` environment variable to be set for cleaning up
|
|
|
|
stale annotations.
|
2020-10-20 20:50:46 +03:00
|
|
|
|
|
|
|
```bash
|
2024-12-12 20:25:40 +02:00
|
|
|
make build
|
|
|
|
NODE_NAME=<EXISTING_NODE> ./nfd-master -no-publish -kubeconfig ~/.kube/config
|
2020-09-08 20:16:17 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
### NFD-Worker
|
|
|
|
|
2024-12-12 20:25:40 +02:00
|
|
|
For development and debugging it is possible to run nfd-worker as a stand-alone
|
|
|
|
binary outside the cluster. The `-no-publish` flag can be used to prevent
|
|
|
|
nfd-worker from creating NodeFeature objects in the target cluster. If the
|
|
|
|
`-no-publish` is not set, nfd-worker also requires the `NODE_NAME` and
|
|
|
|
`KUBERNETES_NAMESPACE` environment variables to be defined to create the
|
|
|
|
NodeFeature object in the target cluster.
|
2020-10-20 20:50:46 +03:00
|
|
|
|
|
|
|
```bash
|
2024-12-12 20:25:40 +02:00
|
|
|
make build
|
|
|
|
KUBERNETES_NAMESPACE=default NODE_NAME=nonexistent-node ./bin/nfd-worker -kubeconfig ~/.kube/config
|
2020-09-08 20:16:17 +03:00
|
|
|
```
|
2020-10-20 20:50:46 +03:00
|
|
|
|
2024-12-12 20:25:40 +02:00
|
|
|
> **NOTE:** Running nfd-worker locally this way discovers and publishes
|
|
|
|
> features of the local development system you're running nfd-worker on.
|
2020-09-08 20:16:17 +03:00
|
|
|
|
2021-01-20 21:49:41 +00:00
|
|
|
### NFD-Topology-Updater
|
|
|
|
|
2024-12-12 20:25:40 +02:00
|
|
|
For development and debugging it is possible to run nfd-topology-updater as a
|
|
|
|
stand-alone binary outside the cluster. However, it requires access to the
|
|
|
|
kubelet's local pod-resources socket and the kubelet http api so in practice it
|
|
|
|
needs to be run on a host acting as a Kubernetes node and thus running
|
|
|
|
kubelet. Running kubelet with `--read-only-port=10255` (or `readOnlyPort:
|
|
|
|
10255` in config) makes it possible to connect to kubelet without auth-token
|
|
|
|
(never do this in a production cluster). Also, the `-no-publish` flag can be
|
|
|
|
used to prevent nfd-topology-updater from creating NodeResourceTopology objects
|
|
|
|
in the target cluster. If the `-no-publish` is not set, nfd-topology-updater
|
|
|
|
also requires the `NODE_NAME` and `KUBERNETES_NAMESPACE` environment variables
|
|
|
|
to be defined.
|
2021-01-20 21:49:41 +00:00
|
|
|
|
|
|
|
```bash
|
2024-12-12 20:25:40 +02:00
|
|
|
make build
|
|
|
|
KUBERNETES_NAMESPACE=default NODE_NAME=nonexistent-node ./bin/nfd-topology-updater -kubeconfig ~/.kube/config -kubelet-config-uri http://127.0.0.1:10255
|
2021-01-20 21:49:41 +00:00
|
|
|
```
|
|
|
|
|
2022-08-30 11:24:08 +03:00
|
|
|
## Running with Tilt
|
|
|
|
|
|
|
|
Another option for building NFD locally is via Tilt tool, which can build container
|
|
|
|
images, push them to a local registry and reload your Kubernetes pods automatically.
|
|
|
|
When using Tilt, you don't have to build container images and re-deploy your pods
|
|
|
|
manually but instead let the Tilt take care of it. Tiltfile is a configuration file
|
2023-02-16 22:08:00 +08:00
|
|
|
for the Tilt and is located at the root directory. To develop NFD with Tilt, follow
|
2022-08-30 11:24:08 +03:00
|
|
|
the steps below.
|
|
|
|
|
|
|
|
### Prerequisites
|
|
|
|
|
|
|
|
1. Install [Docker](https://docs.docker.com/engine/install/)
|
|
|
|
1. Setup Docker as a non-root user.
|
|
|
|
1. Install [kubectl](https://kubernetes.io/docs/tasks/tools/)
|
|
|
|
1. Install [kustomize](https://github.com/kubernetes-sigs/kustomize)
|
|
|
|
1. Install [tilt](https://docs.tilt.dev/install.html)
|
|
|
|
1. Create a local Kubernetes cluster
|
2024-09-29 02:40:36 +00:00
|
|
|
- Create image registry first
|
|
|
|
- Create a Kubernetes cluster. Please note that docker containers will be
|
|
|
|
served as controller node and worker nodes, and NFD-worker will run as a
|
|
|
|
DaemonSet in nested container. Therefore, to make sure the NFD-worker can
|
|
|
|
discover the host features, the host folders "/boot" and "/lib" should be
|
|
|
|
mounted into worker node docker containers when creating the Kubernetes
|
|
|
|
cluster.
|
|
|
|
1. Start up node feature discovery development environment
|
|
|
|
To start up your Tilt development environment, run at the root of your
|
|
|
|
local NFD codebase.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
tilt up
|
|
|
|
```
|
2022-08-30 11:24:08 +03:00
|
|
|
|
2024-09-29 02:40:36 +00:00
|
|
|
Tilt will start a web interface in the localhost and port 10350. From the
|
|
|
|
web interface, you are able to see how NFD worker and master are
|
|
|
|
progressing, watch their build and runtime logs. Once your code changes are
|
|
|
|
saved locally, Tilt will notice it and re-build the container image from
|
|
|
|
the current code, push the image to the registry and re-deploy NFD pods
|
|
|
|
with the latest container image.
|
2022-08-30 11:24:08 +03:00
|
|
|
|
|
|
|
### Environment variables
|
|
|
|
|
|
|
|
To override environment variables used in the Tiltfile during image build,
|
|
|
|
export them in your current terminal before starting Tilt.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
export IMAGE_TAG_NAME="v1"
|
|
|
|
tilt up
|
|
|
|
```
|
|
|
|
|
|
|
|
This will override the default value(`master`) of `IMAGE_TAG_NAME` variable defined
|
|
|
|
in the Tiltfile.
|
|
|
|
|
2020-09-08 20:16:17 +03:00
|
|
|
## Documentation
|
|
|
|
|
2020-11-02 10:48:17 +02:00
|
|
|
All documentation resides under the
|
2021-02-25 13:49:02 +02:00
|
|
|
[docs](https://github.com/kubernetes-sigs/node-feature-discovery/tree/{{site.release}}/docs)
|
2020-11-02 10:48:17 +02:00
|
|
|
directory in the source tree. It is designed to be served as a html site by
|
|
|
|
[GitHub Pages](https://pages.github.com/).
|
2020-10-01 09:25:52 +03:00
|
|
|
|
2023-12-01 15:55:45 +02:00
|
|
|
Building the documentation is containerized to fix the build
|
2020-10-01 09:25:52 +03:00
|
|
|
environment. The recommended way for developing documentation is to run:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
make site-serve
|
|
|
|
```
|
|
|
|
|
|
|
|
This will build the documentation in a container and serve it under
|
|
|
|
[localhost:4000/](http://localhost:4000/) making it easy to verify the results.
|
|
|
|
Any changes made to the `docs/` will automatically re-trigger a rebuild and are
|
2023-11-28 20:27:33 +02:00
|
|
|
reflected in the served content and can be inspected with a browser refresh.
|
2020-10-01 09:25:52 +03:00
|
|
|
|
2023-12-01 15:55:45 +02:00
|
|
|
To just build the html documentation run:
|
2020-10-01 09:25:52 +03:00
|
|
|
|
|
|
|
```bash
|
|
|
|
make site-build
|
|
|
|
```
|
|
|
|
|
|
|
|
This will generate html documentation under `docs/_site/`.
|
|
|
|
|
2020-11-02 10:48:17 +02:00
|
|
|
<!-- Links -->
|
2021-01-20 21:49:41 +00:00
|
|
|
[e2e-config-sample]: https://github.com/kubernetes-sigs/node-feature-discovery/blob/{{site.release}}/test/e2e/e2e-test-config.exapmle.yaml
|
|
|
|
[podresource-api]: https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/device-plugins/#monitoring-device-plugin-resources
|
|
|
|
[feature-gate]: https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates
|