Home > Back-end >  Generating Controller Gen with Kubebuilder
Generating Controller Gen with Kubebuilder

Time:03-29

I am trying to build out my Custom Resource project in Kubebuilder but it seems like I am missing my controller gen whenever I build it out. I keep getting the error:

/Users/*****/Kubernetes/postgres-writer-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
bash: /Users/****/Kubernetes/postgres-writer-operator/bin/controller-gen: No such file or directory
make: *** [generate] Error 127
Error: failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2
Usage:
  kubebuilder create api [flags]

I am new to Kubernetes and am following the tutorial below: enter image description here

Then the next step was to run bootstrapper for my custom resource PostgresWriter and attach it to the operator.

kubebuilder create api \
--group demo \
--version v1 \
--kind PostgresWriter \
--resource true \
--controller true \
--namespaced true

This resulted in the error listed above. How do I generate my controller gen using kubebuilder? Is there a step I am missing here?

FYI by go version is 1.18.

CodePudding user response:

I faced a similar issue and resetting my go version to v1.17.* helped me resolve the issue.

Step 1: Uninstall go by finding out where go is located $ which go
Step 2: Remove any go related paths from PATH environment variable
Step 3: Re install go using the pkg in this link.

Try all your kubebuilder steps once again after go installation is complete.

CodePudding user response:

Not a perfect solution, this should work with the latest go version but it doesn't, so I had to downgrade the go version to 1.17 and then it worked

Summarizing what I learned from this article on downgrading your go version. https://blog.notmyhostna.me/posts/downgrade-go-installed-with-homebrew/

Install version 1.17 go

brew install [email protected]

You will still see that the version didn't change, so you need to unlink the current version by running

brew unlink go

Now you can link the 1.17 version of Go, so when you do go version you'll get 1.17.

brew link --force [email protected]

Voila! You should now see that your current version is 1.17 and you'll be able to successfully run Kubebuilder.

  • Related