Using Operator-SDK v1.27.0 (from Makefile at the time)
Goal is to run ./bin/operator-sdk create api --kind TcxNsProgram ... to add a new kind object.
As is, can't run in our repo without hitting errors.
$ ./bin/operator-sdk create api --group bpfman --version v1alpha1 --kind TcxNsProgram --resource --controller --force --namespaced=true
Error: failed to create API: unable to inject the resource to "base.go.kubebuilder.io/v3": multiple groups are not allowed by default, to enable multi-group visit https://kubebuilder.io/migration/multi-group.html- Download kubebuilder and enable
multiple groups. Not sure we wantmultiple groupsenabled, but needed it to proceed.
-
Used version from same timeframe as Operator-SDK v1.27.0. Tried a couple of versions and this seemed to work.
cd bpfman-operator/bin wget https://github.com/kubernetes-sigs/kubebuilder/releases/download/v3.8.0/kubebuilder_linux_amd64 mv kubebuilder_linux_amd64 kubebuilder chmod +x kubebuilder -
Enable
multiple groups:cd bpfman-operator $ ./bin/kubebuilder edit --multigroup=true Error: failed to edit project: unable to scaffold with "base.go.kubebuilder.io/v3": open Dockerfile: no such file or directory
So copied IngressNodeFirewall Dockerfile. Just creating a blank Dockerfile or renaming one of the existing Containerfiles didn't work. Then complained about not
main.goin root, so copied the operator main.go to root.$ cp ../../ingress-node-firewall/Dockerfile . $ cp cmd/bpfman-operator/main.go .
Re-run. Resulting command updated
PROJECTfile. I then changed therepo:manually fromrepo: github.com/bpfmantorepo: github.com/bpfman/bpfman-operator.$ ./bin/kubebuilder edit --multigroup=true $ git diff PROJECT diff --git a/PROJECT b/PROJECT index fea9a3a..24d680b 100644 --- a/PROJECT +++ b/PROJECT @@ -1,85 +1,82 @@ -# Code generated by tool. DO NOT EDIT. -# This file is used to track the info used to scaffold your project -# and allow the plugins properly work. -# More info: https://book.kubebuilder.io/reference/project-config.html domain: bpfman.io layout: - - go.kubebuilder.io/v3 +- go.kubebuilder.io/v3 +multigroup: true plugins: manifests.sdk.operatorframework.io/v2: {} scorecard.sdk.operatorframework.io/v2: {} projectName: bpfman-operator -repo: github.com/bpfman +repo: github.com/bpfman/bpfman-operator resources:
-
Rerun
operator-sdkcommand:$ ./bin/operator-sdk create api --group bpfman --version v1alpha1 --kind TcxNsProgram --resource --controller --force --namespaced=true : Error: load packages in root "/home/bmcfall/src/bpfman/bpfman-operator": err: exit status 1: stderr: go: inconsistent vendoring in /home/bmcfall/src/bpfman/bpfman-operator
Got further, but failed. To fix:
go mod tidy go mod vendor
Rerun:
$ ./bin/operator-sdk create api --group bpfman --version v1alpha1 --kind TcxNsProgram --resource --controller --force --namespaced=true
I think because multiple groups is enabled, operator-sdk is placing all the generated code in a groups subdirectory.
$ git status
On branch andre-345-interface-in-namespace
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: PROJECT
modified: config/crd/kustomization.yaml
modified: config/samples/kustomization.yaml
modified: go.mod
modified: vendor/modules.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
Dockerfile
apis/bpfman/
config/crd/bases/bpfman.bpfman.io_tcxnsprograms.yaml
config/crd/patches/cainjection_in_bpfman_tcxnsprograms.yaml
config/crd/patches/webhook_in_bpfman_tcxnsprograms.yaml
config/rbac/bpfman_tcxnsprogram_editor_role.yaml
config/rbac/bpfman_tcxnsprogram_viewer_role.yaml
config/samples/bpfman_v1alpha1_tcxnsprogram.yaml
controllers/bpfman/
main.go