github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/doc/hacking.md (about) 1 # Hacking Guide 2 3 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. 4 5 ## Build and Test 6 7 To run the operator locally, make sure the env variable `KUBECONFIG` is set properly. 8 9 ````bash 10 make run 11 ```` 12 13 To run the e2e test. 14 15 ```bash 16 make test-e2e 17 ``` 18 19 To build the binary. 20 21 ```bash 22 # build all components 23 make all 24 25 # build the manager 26 make manager 27 28 # build the plugins 29 make plugins 30 ``` 31 32 If you want to test changes to the `network config daemon`, you must: 33 - build and tag an image locally with `docker build -f Dockerfile.sriov-network-config-daemon -t imagename` 34 - push the image to a registry 35 - change `hack/env.sh` value for `SRIOV_NETWORK_CONFIG_DAEMON_IMAGE` pointing _imagename_ from the registry you pushed the image to 36 37 and then `make run` 38 39 ## Adding new APIs 40 41 Refer to the operator-sdk's [instruction](https://sdk.operatorframework.io/docs/building-operators/golang/tutorial/#create-a-new-api-and-controller). 42 43 ## Updating existing APIs 44 45 1. Edit the *_types.go file to change the definitions for the Spec and Status of the Kinds. 46 47 2. Generate Go code, CRD. 48 ```bash 49 # Generate controller Go code 50 make generate 51 # Generate CRD 52 make manifests 53 # Generate go-client code (optional) 54 make update-codegen 55 ``` 56 57 3. Add feature logic code to the operator reconciliation loop or the config daemon. 58 59 4. Create tests. 60 61 ## Upgrading operator-sdk 62 63 To upgrade the generated code to a new operator-sdk version, we need to follow the instructions in [operator-sdk's migration guide](https://sdk.operatorframework.io/docs/upgrading-sdk-version/). 64 65 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: 66 67 Identify kubebuilder version referenced by operator-sdk 68 69 Identify controller-runtime version referenced by kubebuilder 70 71 Check controller-runtime's go.mod file 72 73 As a result, we can determine the versions of the k8s dependencies in the operator's go.mod. 74 75 ## Build an custom image 76 77 To build the SR-IOV network operator container image: 78 79 ```bash 80 make image 81 82 If you want to build another image (e.g. webhook or config-daemon), you'll need to do 83 the following: 84 85 ```bash 86 export DOCKERFILE=Dockerfile.sriov-network-config-daemon 87 export APP_NAME=sriov-network-config-daemon 88 make image 89 90 export DOCKERFILE=Dockerfile.webhook 91 export APP_NAME=sriov-network-webhook 92 make image 93 94 Then you'll need to push the image to a registry using e.g. `buildah push`. 95 Before deploying the Operator, you want to export these variables to use that custom image: 96 97 ```bash 98 export SRIOV_NETWORK_CONFIG_DAEMON_IMAGE=<path to custom image> 99 (...) 100 101 ## Enable Unsupported NICs 102 103 By default, unsupported NICs are not reported in `SriovNetworkNodeState` and 104 are not allowed in `SriovNetworkNodePolicy` by the webhook. 105 106 If you want to allow unsupported NICs, set the `DEV_MODE` env var to `TRUE`. 107 108 ```bash 109 export DEV_MODE=TRUE 110 ```