Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"kubebuilder create api" does not work with Go 1.18 #2543

Closed
rbrownwsws opened this issue Mar 17, 2022 · 7 comments
Closed

"kubebuilder create api" does not work with Go 1.18 #2543

rbrownwsws opened this issue Mar 17, 2022 · 7 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@rbrownwsws
Copy link

What broke? What's expected?

I have just tried to create a new kubebuilder project using Go 1.18

Calling kubebuilder create api in a new kubebuilder project fails with an error because "controller-gen" cannot be found.

"kubebuilder create api" output
$ kubebuilder create api --group example.co.uk --kind Issuer --version v1alpha1
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
api/v1alpha1/issuer_types.go
controllers/issuer_controller.go
Update dependencies:
$ go mod tidy
Running make:
$ make generate
go: creating new go.mod: module tmp
Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
go: downloading sigs.k8s.io/controller-tools v0.8.0
go: downloading github.com/spf13/cobra v1.2.1
go: downloading github.com/fatih/color v1.12.0
go: downloading golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff
go: downloading github.com/gobuffalo/flect v0.2.3
go: downloading github.com/mattn/go-colorable v0.1.8
go: downloading github.com/mattn/go-isatty v0.0.12
go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.1.2
go: downloading github.com/google/go-cmp v0.5.6
go: downloading github.com/inconshreveable/mousetrap v1.0.0
go: downloading golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e
go: downloading golang.org/x/mod v0.4.2
go: added github.com/fatih/color v1.12.0
go: added github.com/go-logr/logr v1.2.0
go: added github.com/gobuffalo/flect v0.2.3
go: added github.com/gogo/protobuf v1.3.2
go: added github.com/google/go-cmp v0.5.6
go: added github.com/google/gofuzz v1.1.0
go: added github.com/inconshreveable/mousetrap v1.0.0
go: added github.com/json-iterator/go v1.1.12
go: added github.com/mattn/go-colorable v0.1.8
go: added github.com/mattn/go-isatty v0.0.12
go: added github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: added github.com/modern-go/reflect2 v1.0.2
go: added github.com/spf13/cobra v1.2.1
go: added github.com/spf13/pflag v1.0.5
go: added golang.org/x/mod v0.4.2
go: added golang.org/x/net v0.0.0-20210825183410-e898025ed96a
go: added golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e
go: added golang.org/x/text v0.3.7
go: added golang.org/x/tools v0.1.6-0.20210820212750-d4cc65f0b2ff
go: added golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
go: added gopkg.in/inf.v0 v0.9.1
go: added gopkg.in/yaml.v2 v2.4.0
go: added gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
go: added k8s.io/api v0.23.0
go: added k8s.io/apiextensions-apiserver v0.23.0
go: added k8s.io/apimachinery v0.23.0
go: added k8s.io/klog/v2 v2.30.0
go: added k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b
go: added sigs.k8s.io/controller-tools v0.8.0
go: added sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6
go: added sigs.k8s.io/structured-merge-diff/v4 v4.1.2
go: added sigs.k8s.io/yaml v1.3.0
/mnt/c/Users/rbrow/Documents/example-project/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
bash: /mnt/c/Users/rbrow/Documents/example-project/bin/controller-gen: No such file or directory
make: *** [Makefile:48: 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]

Examples:
  # Create a frigates API with Group: ship, Version: v1beta1 and Kind: Frigate
  kubebuilder create api --group ship --version v1beta1 --kind Frigate

  # Edit the API Scheme
  nano api/v1beta1/frigate_types.go

  # Edit the Controller
  nano controllers/frigate/frigate_controller.go

  # Edit the Controller Test
  nano controllers/frigate/frigate_controller_test.go

  # Generate the manifests
  make manifests

  # Install CRDs into the Kubernetes cluster using kubectl apply
  make install

  # Regenerate code and run against the Kubernetes cluster configured by ~/.kube/config
  make run


Flags:
      --controller           if set, generate the controller without prompting the user (default true)
      --force                attempt to create resource even if it already exists
      --group string         resource Group
  -h, --help                 help for api
      --kind string          resource Kind
      --make make generate   if true, run make generate after generating files (default true)
      --namespaced           resource is namespaced (default true)
      --plural string        resource irregular plural form
      --resource             if set, generate the resource without prompting the user (default true)
      --version string       resource Version

Global Flags:
      --plugins strings   plugin keys to be used for this subcommand execution

2022/03/17 03:46:05 failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2

This seems to be related to the deprecation of 'go get' for installing executables

Changing go-get-tool to use go install instead of go get in the generated Makefile seems to have fixed this for me:

# go-get-tool will 'go get' any package $2 and install it to $1.
PROJECT_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
define go-get-tool
@[ -f $(1) ] || { \
set -e ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go install $(2) ;\
}
endef

From a quick peek at PR #2383 there may also be other problems in kubebuilder related to the use of go get

Reproducing this issue

No response

KubeBuilder (CLI) Version

Version: main.version{KubeBuilderVersion:"3.3.0", KubernetesVendor:"1.23.1", GitCommit:"47859bf2ebf96a64db69a2f7074ffdec7f15c1ec", BuildDate:"2022-01-18T17:03:29Z", GoOs:"linux", GoArch:"amd64"}

PROJECT version

No response

Plugin versions

No response

Other versions

go version go1.18 linux/amd64

Extra Labels

No response

@rbrownwsws rbrownwsws added the kind/bug Categorizes issue or PR as related to a bug. label Mar 17, 2022
@camilamacedo86
Copy link
Member

#2543

Go 1.18 is not supported.
It would be able to work with 1.18 when we began to support it.
See: #2530

@rbrownwsws
Copy link
Author

Ah, I from a quick skim of #2530 I had assumed that Go versions >=1.17 were meant to be supported and I didn't notice #2527 because I was only looking through open issues.

I've only done a little bit of work on my project so far but nothing seems obviously broken after my change to the Makefile. I'm going to see if I can get away with using Go 1.18 for now instead of downgrading to 1.17.x.

I will leave it up to you to decide if you want to close this issue.

@camilamacedo86
Copy link
Member

If you use the master branch it probably will work see: #2486

@Vaxuite
Copy link

Vaxuite commented Mar 22, 2022

Do you have any plans to create a release so upstream dependencies can also be tagged (operator-sdk) so we can update to go 1.18?

@camilamacedo86
Copy link
Member

HI @Vaxuite,

Could you try:

  • Install KB from the source ( clone this repo and run make install to generate the bin from the source )
  • Then, test it ( use --forced to run the command using go 1.18 ) to check if it will work or not

I raised an issue for we work on the required changes for we began to support it: #2559. WDYT? Would you like to work on this one?

@rashmigottipati
Copy link
Contributor

Closing this issue in favor of #2559

@3deep5me
Copy link

Hello,
I ran into the same Issue but with Kubebuilder 3.5 and go 1.18.3 during the tutorial. I tried it on two separate systems.
Any Ideas?

manuel@dev:~/projects/go/project$ kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.12.1
Update dependencies:
$ go mod tidy
Next: define a resource with:
$ kubebuilder create api
manuel@dev:~/projects/go/project$ kubebuilder create api --group batch --version v1 --kind CronJob
Create Resource [y/n]
y
Create Controller [y/n]
y
Writing kustomize manifests for you to edit...
Writing scaffold for you to edit...
api/v1/cronjob_types.go
controllers/cronjob_controller.go
Update dependencies:
$ go mod tidy
Running make:
$ make generate
mkdir -p /home/manuel/projects/go/project/bin
GOBIN=/home/manuel/projects/go/project/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.9.0
/home/manuel/projects/go/project/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
/usr/local/go/src/net/cgo_linux.go:12:8: no such package located
Error: not all generators ran successfully
run `controller-gen object:headerFile=hack/boilerplate.go.txt paths=./... -w` to see all available markers, or `controller-gen object:headerFile=hack/boilerplate.go.txt paths=./... -h` for usage
make: *** [Makefile:48: generate] Error 1
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]
.
.
.

2022/07/10 18:38:05 failed to create API: unable to run post-scaffold tasks of "base.go.kubebuilder.io/v3": exit status 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants