Skip to content

Latest commit

 

History

History
110 lines (72 loc) · 3.11 KB

File metadata and controls

110 lines (72 loc) · 3.11 KB

Hacking Guide

The sriov network operator relies on operator-sdk and kubebuilder to scaffold and generate code and manifests. We keeps upgrading sdk version for the operator. Now the operator is compliance with operator-sdk 1.9.0 and go.kubebuilder.io/v3.

Build and Test

To run the operator locally, make sure the env variable KUBECONFIG is set properly.

make run

To run the e2e test.

make test-e2e

To build the binary.

# build all components
make all

# build the manager
make manager

# build the plugins
make plugins

If you want to test changes to the network config daemon, you must:

  • build and tag an image locally with docker build -f Dockerfile.sriov-network-config-daemon -t imagename
  • push the image to a registry
  • change hack/env.sh value for SRIOV_NETWORK_CONFIG_DAEMON_IMAGE pointing imagename from the registry you pushed the image to

and then make run

Adding new APIs

Refer to the operator-sdk's instruction.

Updating existing APIs

  1. Edit the *_types.go file to change the definitions for the Spec and Status of the Kinds.

  2. Generate Go code, CRD.

    # Generate controller Go code
    make generate
    # Generate CRD
    make manifests
    # Generate go-client code (optional)
    make update-codegen
  3. Add feature logic code to the operator reconciliation loop or the config daemon.

  4. Create tests.

Upgrading operator-sdk

To upgrade the generated code to a new operator-sdk version, we need to follow the instructions in operator-sdk's migration guide.

In addition, we must ensure that the k8s dependencies in the operator's go.mod match the selected version of operator-sdk. For example, for operator-sdk v0.19.x, check the k8s dependencies:

Identify kubebuilder version referenced by operator-sdk

Identify controller-runtime version referenced by kubebuilder

Check controller-runtime's go.mod file

As a result, we can determine the versions of the k8s dependencies in the operator's go.mod.

Build an custom image

To build the SR-IOV network operator container image:

```bash
make image

If you want to build another image (e.g. webhook or config-daemon), you'll need to do the following:

```bash
export DOCKERFILE=Dockerfile.sriov-network-config-daemon
export APP_NAME=sriov-network-config-daemon
make image

export DOCKERFILE=Dockerfile.webhook
export APP_NAME=sriov-network-webhook
make image

Then you'll need to push the image to a registry using e.g. buildah push. Before deploying the Operator, you want to export these variables to use that custom image:

```bash
export SRIOV_NETWORK_CONFIG_DAEMON_IMAGE=<path to custom image>
(...)

Enable Unsupported NICs

By default, unsupported NICs are not reported in SriovNetworkNodeState and are not allowed in SriovNetworkNodePolicy by the webhook.

If you want to allow unsupported NICs, set the DEV_MODE env var to TRUE.

export DEV_MODE=TRUE