<!DOCTYPE html><htmllang="en"dir="auto"><head><metacharset="utf-8"><metaname="viewport"content="width=device-width, initial-scale=1, maximum-scale=5, user-scalable=no"><metaname="description"content="Developer guide Table of contents Building from source Download the source code Docker build Docker multi-arch builds with buildx Deployment Buildi..."><metaname="revised"content=""><metaname="author"content="Kubernetes SIGs"><metaname="generator"content="rundocs/jekyll-rtd-theme v2.0.10"><metaname="theme-color"content="#2980b9"><title>Developer guide · Node Feature Discovery</title><metaname="twitter:title"content="Developer guide · Node Feature Discovery"><metaname="twitter:description"content="Developer guide Table of contents Building from source Download the source code Docker build Docker multi-arch builds with buildx Deployment Buildi..."><metaname="twitter:card"content="summary"><metaname="twitter:site"content="@Kubernetes SIGs"><metaname="twitter:url"content="https://kubernetes-sigs.github.com/node-feature-discovery/v0.13/developer-guide/"><metaname="twitter:creator"content="@rundocs/jekyll-rtd-theme v2.0.10"><metaproperty="og:title"content="Developer guide · Node Feature Discovery"><metaproperty="og:description"content="Developer guide Table of contents Building from source Download the source code Docker build Docker multi-arch builds with buildx Deployment Buildi..."><metaproperty="og:locale"content="en"><metaproperty="og:url"content="https://kubernetes-sigs.github.com/node-feature-discovery/v0.13/developer-guide/"><metaproperty="og:type"content="article"><metaproperty="article:author"content="Kubernetes SIGs"><metaproperty="article:published_time"content="2016-07-23T00:07:52-05:00"><metaproperty="article:modified_time"content="2023-04-22T01:54:35-05:00"><scripttype="application/ld+json">{"@context":"https://schema.org","@type":"Article","mainEntityOfPage":{"@type":"WebPage","@id":"https://kubernetes-sigs.github.com/node-feature-discovery/v0.13/developer-guide/"},"headline":"Developer guide · Node Feature Discovery","image":[],"author":{"@type":"Person","name":"Kubernetes SIGs"},"datePublished":"2016-07-23T00:07:52-05:00","dateModified":"2023-04-22T01:54:35-05:00","publisher":{"@type":"Organization","name":"Kubernetes SIGs","logo":{"@type":"ImageObject","url":"https://avatars.githubusercontent.com/u/36015203?v=4"}},"description":"Developer guide Table of contents Building from source Download the source code Docker build Docker multi-arch builds with buildx Deployment Buildi..."}</script><linkrel="dns-prefetch"href="https://cdn.jsdelivr.net"><linkrel="canonical"href="https://kubernetes-sigs.github.com/node-feature-discovery/v0.13/developer-guide/"><linkrel="icon"type="image/svg+xml"href="/node-feature-discovery/v0.13/assets/images/favicon.svg"><linkrel="icon"type="image/png"href="/node-feature-discovery/v0.13/assets/images/favicon-16x16.png"sizes="16x16"><linkrel="icon"type="image/png"href="/node-feature-discovery/v0.13/assets/images/favicon-32x32.png"sizes="32x32"><linkrel="icon"type="image/png"href="/node-feature-discovery/v0.13/assets/images/favicon-96x96.png"sizes="96x96"><linkrel="mask-icon"href="/node-feature-discovery/v0.13/assets/images/favicon.svg"color="#2980b9"><linkrel="apple-touch-icon"href="/node-feature-discovery/v0.13/assets/images/apple-touch-icon-300x300.jpg"><linkrel="stylesheet"href="https://cdn.jsdelivr.net/gh/rundocs/jekyll-rtd-theme@2.0.10/assets/css/theme.min.css"><style>@media(min-width:1280px){.content-wrap{max-width:1200px}}</style><script>window.ui={title:"Node Feature Discovery",baseurl:"/node-feature-discovery/v0.13",i18n:{search_results:"Search Results",search_results_found:"Search finished, found # page(s) matching the search query.",search_results_not_found:"Your search did not match any documents, please make sure that all characters are spelled correctly!"}};</script></head><bodyclass="container"><divclass="sid
</code></pre></div></div><h3id="docker-build">Docker build</h3><h4id="build-the-container-image">Build the container image</h4><p>See <ahref="#customizing-the-build">customizing the build</a> below for altering the container image registry, for example.</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make
</code></pre></div></div><h4id="push-the-container-image">Push the container image</h4><p>Optional, this example with Docker.</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>docker push <IMAGE_TAG>
</code></pre></div></div><h3id="docker-multi-arch-builds-with-buildx">Docker multi-arch builds with buildx</h3><p>The default set of architectures enabled for mulit-arch builds are <codeclass="language-plaintext highlighter-rouge notranslate">linux/amd64</code> and <codeclass="language-plaintext highlighter-rouge notranslate">linux/arm64</code>. If more architectures are needed one can override the <codeclass="language-plaintext highlighter-rouge notranslate">IMAGE_ALL_PLATFORMS</code> variable with a comma separated list of <codeclass="language-plaintext highlighter-rouge notranslate">OS/ARCH</code> tuples.</p><h4id="build-the-manifest-list-with-a-container-image-per-arch">Build the manifest-list with a container image per arch</h4><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make image-all
</code></pre></div></div><p>Currently <codeclass="language-plaintext highlighter-rouge notranslate">docker</code> does not support loading of manifest-lists meaning the images are not shown when executing <codeclass="language-plaintext highlighter-rouge notranslate">docker images</code>, see: <ahref="https://github.com/docker/buildx/issues/59">buildx issue #59</a>.</p><h4id="push-the-manifest-list-with-container-image-per-arch">Push the manifest-list with container image per arch</h4><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make push-all
</code></pre></div></div><p>The resulting container image can be used in the same way on each arch by pulling e.g. <codeclass="language-plaintext highlighter-rouge notranslate">node-feature-discovery:v0.13.0</code> without specifying the architecture. The manifest-list will take care of providing the right architecture image.</p><h4id="change-the-job-spec-to-use-your-custom-image-optional">Change the job spec to use your custom image (optional)</h4><p>To use your published image from the step above instead of the <codeclass="language-plaintext highlighter-rouge notranslate">registry.k8s.io/nfd/node-feature-discovery</code> image, edit <codeclass="language-plaintext highlighter-rouge notranslate">image</code> attribute in the spec template(s) to the new location (<codeclass="language-plaintext highlighter-rouge notranslate"><registry-name>/<image-name>[:<version>]</code>).</p><h3id="deployment">Deployment</h3><p>The <codeclass="language-plaintext highlighter-rouge notranslate">yamls</code> makefile generates a <codeclass="language-plaintext highlighter-rouge notranslate">kustomization.yaml</code> matching your locally built image and using the <codeclass="language-plaintext highlighter-rouge notranslate">deploy/overlays/default</code> deployment. See <ahref="#customizing-the-build">build customization</a> below for configurability, e.g. changing the deployment namespace.</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nv">K8S_NAMESPACE</span><spanclass="o">=</span>my-ns make yamls
</code></pre></div></div><p>You can use alternative deployment methods by modifying the auto-generated kustomization file. For example, deploying worker and master in the same pod by pointing to <codeclass="language-plaintext highlighter-rouge notranslate">deployment/overlays/default-combined</code>.</p><h3id="building-locally">Building locally</h3><p>You can also build the binaries locally</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make build
</code></pre></div></div><p>This will compile binaries under <codeclass="language-plaintext highlighter-rouge notranslate">bin/</code></p><h3id="customizing-the-build">Customizing the build</h3><p>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.</p><table><thead><tr><th>Variable</th><th>Description</th><th>Default value</th></tr></thead><tbody><tr><td>HOSTMOUNT_PREFIX</td><td>Prefix of system directories for feature discovery (local builds)</td><td>/ (<em>local builds</em>) /host- (<em>container builds</em>)</td></tr><tr><td>IMAGE_BUILD_CMD</td><td>Command to build the image</td><td>docker build</td></tr><tr><td>IMAGE_BUILD_EXTRA_OPTS</td><td>Extra options to pass to build command</td><td><em>empty</em></td></tr><tr><td>IMAGE_BUILDX_CMD</td><td>Command to build and push multi-arch images with buildx</td><td>DOCKER_CLI_EXPERIMENTAL=enabled docker buildx build –platform=${IMAGE_ALL_PLATFORMS} –progress=auto –pull</td></tr><tr><td>IMAGE_ALL_PLATFORMS</td><td>Comma separated list of OS/ARCH tuples for mulit-arch builds</td><td>linux/amd64,linux/arm64</td></tr><tr><td>IMAGE_PUSH_CMD</td><td>Command to push the image to remote registry</td><td>docker push</td></tr><tr><td>IMAGE_REGISTRY</td><td>Container image registry to use</td><td>registry.k8s.io/nfd</td></tr><tr><td>IMAGE_TAG_NAME</td><td>Container image tag name</td><td><nfd version></td></tr><tr><td>IMAGE_EXTRA_TAG_NAMES</td><td>Additional container image tag(s) to create when building image</td><td><em>empty</em></td></tr><tr><td>K8S_NAMESPACE</td><td>nfd-master and nfd-worker namespace</td><td>node-feature-discovery</td></tr><tr><td>KUBECONFIG</td><td>Kubeconfig for running e2e-tests</td><td><em>empty</em></td></tr><tr><td>E2E_TEST_CONFIG</td><td>Parameterization file of e2e-tests (see <ahref="https://github.com/kubernetes-sigs/node-feature-discovery/blob/v0.13.0/test/e2e/e2e-test-config.exapmle.yaml">example</a>)</td><td><em>empty</em></td></tr><tr><td>E2E_PULL_IF_NOT_PRESENT</td><td>True-ish value makes the image pull policy IfNotPresent (to be used only in e2e tests)</td><td>false</td></tr><tr><td>OPENSHIFT</td><td>Non-empty value enables OpenShift specific support (currently only effective in e2e tests)</td><td><em>empty</em></td></tr></tbody></table><p>For example, to use a custom registry:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make <spanclass="nv">IMAGE_REGISTRY</span><spanclass="o">=</span><my custom registry uri>
</code></pre></div></div><p>Or to specify a build tool different from Docker, It can be done in 2 ways:</p><ol><li><p>via environment</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nv">IMAGE_BUILD_CMD</span><spanclass="o">=</span><spanclass="s2">"buildah bud"</span> make
</code></pre></div></div></li><li><p>by overriding the variable value</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code> make <spanclass="nv">IMAGE_BUILD_CMD</span><spanclass="o">=</span><spanclass="s2">"buildah bud"</span>
</code></pre></div></div></li></ol><h3id="testing">Testing</h3><p>Unit tests are automatically run as part of the container image build. You can also run them manually in the source code tree by simply running:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make <spanclass="nb">test</span>
</code></pre></div></div><p>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:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make e2e-test <spanclass="nv">KUBECONFIG</span><spanclass="o">=</span><spanclass="nv">$HOME</span>/.kube/config
</code></pre></div></div><h2id="running-locally">Running locally</h2><p>You can run NFD locally, either directly on your host OS or in containers for testing and development purposes. This may be useful e.g. for checking features-detection.</p><h3id="nfd-master">NFD-Master</h3><p>When running as a standalone container labeling is expected to fail because Kubernetes API is not available. Thus, it is recommended to use <codeclass="language-plaintext highlighter-rouge notranslate">-no-publish</code> command line flag. E.g.</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nv">$ </span><spanclass="nb">export </span><spanclass="nv">NFD_CONTAINER_IMAGE</span><spanclass="o">=</span>registry.k8s.io/nfd/node-feature-discovery:v0.13.0
<spanclass="nv">$ </span>docker run <spanclass="nt">--rm</span><spanclass="nt">--name</span><spanclass="o">=</span>nfd-test <spanclass="k">${</span><spanclass="nv">NFD_CONTAINER_IMAGE</span><spanclass="k">}</span> nfd-master <spanclass="nt">-no-publish</span>
2019/02/01 14:48:21 gRPC server serving on port: 8080
</code></pre></div></div><h3id="nfd-worker">NFD-Worker</h3><p>In order to run nfd-worker as a "stand-alone" container against your standalone nfd-master you need to run them in the same network namespace:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nv">$ </span>docker run <spanclass="nt">--rm</span><spanclass="nt">--network</span><spanclass="o">=</span>container:nfd-test <spanclass="k">${</span><spanclass="nv">NFD_CONTAINER_IMAGE</span><spanclass="k">}</span> nfd-worker
</code></pre></div></div><p>If you just want to try out feature discovery without connecting to nfd-master, pass the <codeclass="language-plaintext highlighter-rouge notranslate">-no-publish</code> flag to nfd-worker.</p><p><strong>NOTE</strong> Some feature sources need certain directories and/or files from the host mounted inside the NFD container. Thus, you need to provide Docker with the correct <codeclass="language-plaintext highlighter-rouge notranslate">--volume</code> options in order for them to work correctly when run stand-alone directly with <codeclass="language-plaintext highlighter-rouge notranslate">docker run</code>. See the <ahref="https://github.com/kubernetes-sigs/node-feature-discovery/blob/v0.13.0/deployment/components/common/worker-mounts.yaml">default deployment</a> for up-to-date information about the required volume mounts.</p><h3id="nfd-topology-updater">NFD-Topology-Updater</h3><p>In order to run nfd-topology-updater as a "stand-alone" container against your standalone nfd-master you need to run them in the same network namespace:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nv">$ </span>docker run <spanclass="nt">--rm</span><spanclass="nt">--network</span><spanclass="o">=</span>container:nfd-test <spanclass="k">${</span><spanclass="nv">NFD_CONTAINER_IMAGE</span><spanclass="k">}</span> nfd-topology-updater
</code></pre></div></div><p>If you just want to try out feature discovery without connecting to nfd-master, pass the <codeclass="language-plaintext highlighter-rouge notranslate">-no-publish</code> flag to nfd-topology-updater.</p><p>NOTE:</p><p>NFD topology updater needs certain directories and/or files from the host mounted inside the NFD container. Thus, you need to provide Docker with the correct <codeclass="language-plaintext highlighter-rouge notranslate">--volume</code> options in order for them to work correctly when run stand-alone directly with <codeclass="language-plaintext highlighter-rouge notranslate">docker run</code>. See the <ahref="https://github.com/kubernetes-sigs/node-feature-discovery/blob/v0.13.0/deployment/components/topology-updater/topologyupdater-mounts.yaml">template spec</a> for up-to-date information about the required volume mounts.</p><p><ahref="https://kubernetes.io/docs/concepts/extend-kubernetes/compute-storage-net/device-plugins/#monitoring-device-plugin-resources">PodResource API</a> is a prerequisite for nfd-topology-updater. Preceding Kubernetes v1.23, the <codeclass="language-plaintext highlighter-rouge notranslate">kubelet</code> must be started with the following flag: <codeclass="language-plaintext highlighter-rouge notranslate">--feature-gates=KubeletPodResourcesGetAllocatable=true</code>. Starting Kubernetes v1.23, the <codeclass="language-plaintext highlighter-rouge notranslate">GetAllocatableResources</code> is enabled by default through <codeclass="language-plaintext highlighter-rouge notranslate">KubeletPodResourcesGetAllocatable</code><ahref="https://kubernetes.io/docs/reference/command-line-tools-reference/feature-gates">feature gate</a>.</p><h2id="running-with-tilt">Running with Tilt</h2><p>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 for the Tilt and is located at the root directory. To develop NFD with Tilt, follow the steps below.</p><h3id="prerequisites">Prerequisites</h3><ol><li>Install <ahref="https://docs.docker.com/engine/install/">Docker</a></li><li>Setup Docker as a non-root user.</li><li>Install <ahref="https://kubernetes.io/docs/tasks/tools/">kubectl</a></li><li>Install <ahref="https://github.com/kubernetes-sigs/kustomize">kustomize</a></li><li>Install <ahref="https://docs.tilt.dev/install.html">tilt</a></li><li>Create a local Kubernetes cluster</li></ol><p>To start up your Tilt development environment, just run</p><divclass="language-shell highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>tilt up
</code></pre></div></div><p>at the root of your local NFD codebase. 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.</p><h3id="environment-variables">Environment variables</h3><p>To override environment variables used in the Tiltfile during image build, export them in your current terminal before starting Tilt.</p><divclass="language-shell highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code><spanclass="nb">export </span><spanclass="nv">IMAGE_TAG_NAME</span><spanclass="o">=</span><spanclass="s2">"v1"</span>
tilt up
</code></pre></div></div><p>This will override the default value(<codeclass="language-plaintext highlighter-rouge notranslate">master</code>) of <codeclass="language-plaintext highlighter-rouge notranslate">IMAGE_TAG_NAME</code> variable defined in the Tiltfile.</p><h2id="documentation">Documentation</h2><p>All documentation resides under the <ahref="https://github.com/kubernetes-sigs/node-feature-discovery/tree/v0.13.0/docs">docs</a> directory in the source tree. It is designed to be served as a html site by <ahref="https://pages.github.com/">GitHub Pages</a>.</p><p>Building the documentation is containerized in order to fix the build environment. The recommended way for developing documentation is to run:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make site-serve
</code></pre></div></div><p>This will build the documentation in a container and serve it under <ahref="http://localhost:4000/">localhost:4000/</a> making it easy to verify the results. Any changes made to the <codeclass="language-plaintext highlighter-rouge notranslate">docs/</code> will automatically re-trigger a rebuild and are reflected in the served content and can be inspected with a simple browser refresh.</p><p>In order to just build the html documentation run:</p><divclass="language-bash highlighter-rouge notranslate"><divclass="highlight"><preclass="highlight"><code>make site-build