Maybe you will get the following error when you try to work with a go operator-sdk
project you cloned from GitHub.
*** [generate] Error 127
Here we see that simply the bin
directory with the needed controller-gen
, kustomize
and setup-envtest
files, wasn’t created by operator-sdk commands.
This blog post does address that topic for a macOS
operating system and is structured in following sections:
- Fast solution
- Reproduce the problem
- Fix the problem
1. Fast solution
In short words we need just to copy the
bin
directory from an existing operator-sdk project we have on our machine and past it into the cloned project and it will work for our cloned project.
But we will have problems, when we create new projects with that installation setup using brew install operator-sdk
.
(even when this is my preferred way π¦ because I want to avoid FATA[0009] failed to create API: unable to run post-scaffold tasks of βbase.go.kubebuilder.io/v3β: exit status 2)
I created a GitHub issue.
2. Reproduce the problem
We are using the currently available operator SDK version 19.1.0 which we installed using brew as described in the operator-sdk documentation.
Step 1: Clone a GO operator-sdk project from GitHub
git clone https://github.com/thomassuedbroecker/multi-tenancy-frontend-operator.git
cd multi-tenancy-frontend-operator/frontendOperator
Step 2: Run make generate and get the error
make generate
- Example output:
As we will see, there are files and bin folder missing. bin/controller-gen: No such file or directory
...
go: added sigs.k8s.io/yaml v1.3.0
/multi-tenancy-frontend-operator/frontendOperator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
bash: /Users/thomassuedbroecker/Downloads/dev/verify/multi-tenancy-frontend-operator/frontendOperator/bin/controller-gen: No such file or directory
make: *** [generate] Error 127
Step 3: Verify operator-sdk version
operator-sdk version
- Example output:
Ensure you have operator-sdk version: "v1.19.1"
installed.
operator-sdk version: "v1.19.1", commit: "079d8852ce5b42aa5306a1e33f7ca725ec48d0e3", kubernetes version: "v1.23", go version: "go1.18.1", GOOS: "darwin", GOARCH: "amd64"
3. Fix the problem for now
We are using an Operator SDK version that worked before, in my case I used 18.0.0 successfully some time ago. As far as I remember, golang version 1.17.6 was related to operator-sdk 18.0.0 version.
Note: If you want to install an older Operator SDK version with brew, that won’t work as there is only one brew formulae, as I found out. I hope that the brew installation will be fixed in the future.
So, we will do the following sequence to fix the problem:
- Uninstall the
operator-sdk
we installed with brew - Install
operator-sdk 18.0.0
using the binaries and install golang in versiongo 1.17.6
- Verify does the creation of a new operator project now include the
bin
and the related files
Step 1: Uninstall operator-sdk
we installed with brew
Follow the steps outlined in one of my blog posts, but only for uninstalling. The current version of the operator-sdk in brew is 1.19.1
.
YOUR_USER=YOUR_USER
sudo go clean -cache
brew uninstall operator-sdk
brew uninstall go
sudo rm -rf /usr/local/Cellar/go
sudo rm -rf /usr/local/go
sudo rm -rf /Users/$YOUR_USER/go
Step 2: Install operator-sdk 18.0.0
and goland 1.17.6 using the binariesΒΆ
Here we follow the related operator-sdk documentation.
1. Create a folder for your downloads
mkdir operator-sdk
cd operator-sdk
2. Set platform information
export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac)
export OS=$(uname | awk '{print tolower($0)}')
3. Download the binary for your platform
export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v1.18.0
curl -LO ${OPERATOR_SDK_DL_URL}/operator-sdk_${OS}_${ARCH}
4. Install the release binary in your PATH
chmod +x operator-sdk_${OS}_${ARCH} && sudo mv operator-sdk_${OS}_${ARCH} /usr/local/bin/operator-sdk
5. Download go 1.17.6
https://go.dev/dl/go1.17.6.darwin-amd64.pkg
6. Install go 1.17.6
using the downloaded file
7. Verify the installed operator-sdk and golang version
operator-sdk version
- Example output:
operator-sdk version: "v1.18.0", commit: "c9c61b6921b29d731e64cd3cc33d268215fb3b25", kubernetes version: "1.21", go version: "go1.17.7", GOOS: "darwin", GOARCH: "amd64"
3. Confirm that creating a new operator project now contains the bin and associated files
Let us just create an example project problemfix
.
Step 1: Create a new empty folder outside the cloned projectΒΆ
cd ..
mkdir fixproblem
cd fixproblem
Step 2: RunΒ operator-sdk init
operator-sdk init --domain myproblemfix.net --repo github.com/myproblemfix/myproblemfix
- Example output:
...
go: downloading github.com/kr/text v0.2.0
go: downloading gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7
go: downloading github.com/cespare/xxhash v1.1.0
Next: define a resource with:
$ operator-sdk create api
Step 2: Create an APIΒΆ
operator-sdk create api --group myproblemfix --version v1alpha1 --kind Myproblemfix --resource --controller
- Example output:
...
Next: implement your new API and generate the manifests (e.g. CRDs,CRs) with:
$ make manifests
Step 3: RunΒ make generate
make generate
make manifest
make build
Step 3: Verify the bin folder
and the needed files were createdΒΆ
fixproblem % tree
.
βββ Dockerfile
βββ Makefile
βββ PROJECT
βββ api
β βββ v1alpha1
β βββ groupversion_info.go
β βββ myproblemfix_types.go
β βββ zz_generated.deepcopy.go
βββ bin
β βββ controller-gen
β βββ kustomize
β βββ manager
βββ config
β βββ crd
β β βββ bases
β β β βββ myproblemfix.myproblemfix.net_myproblemfixes.yaml
β β βββ kustomization.yaml
β β βββ kustomizeconfig.yaml
β β βββ patches
β β βββ cainjection_in_myproblemfixes.yaml
β β βββ webhook_in_myproblemfixes.yaml
β βββ default
β β βββ kustomization.yaml
β β βββ manager_auth_proxy_patch.yaml
β β βββ manager_config_patch.yaml
β βββ manager
β β βββ controller_manager_config.yaml
β β βββ kustomization.yaml
β β βββ manager.yaml
β βββ manifests
β β βββ kustomization.yaml
β βββ prometheus
β β βββ kustomization.yaml
β β βββ monitor.yaml
β βββ rbac
β β βββ auth_proxy_client_clusterrole.yaml
β β βββ auth_proxy_role.yaml
β β βββ auth_proxy_role_binding.yaml
β β βββ auth_proxy_service.yaml
β β βββ kustomization.yaml
β β βββ leader_election_role.yaml
β β βββ leader_election_role_binding.yaml
β β βββ myproblemfix_editor_role.yaml
β β βββ myproblemfix_viewer_role.yaml
β β βββ role.yaml
β β βββ role_binding.yaml
β β βββ service_account.yaml
β βββ samples
β β βββ kustomization.yaml
β β βββ myproblemfix_v1alpha1_myproblemfix.yaml
β βββ scorecard
β βββ bases
β β βββ config.yaml
β βββ kustomization.yaml
β βββ patches
β βββ basic.config.yaml
β βββ olm.config.yaml
βββ controllers
β βββ myproblemfix_controller.go
β βββ suite_test.go
βββ go.mod
βββ go.sum
βββ hack
β βββ boilerplate.go.txt
βββ main.go
SummaryΒΆ
With that we ensure you have a working version. Now you can try to install different operator-sdk binaries if they work with the golang 1.17.6 related to operator development.
I hope this was useful to you and letβs see whatβs next?
Greetings,
Thomas
#operatorsdk, #macos, #golang, #operators