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 for controller-gen step is not working #2692

Closed
Cbkhare opened this issue May 17, 2022 · 14 comments
Closed

kubebuilder create api for controller-gen step is not working #2692

Cbkhare opened this issue May 17, 2022 · 14 comments
Labels
kind/bug Categorizes issue or PR as related to a bug.

Comments

@Cbkhare
Copy link

Cbkhare commented May 17, 2022

What broke? What's expected?

There are 2 problems I have observed, and I believe both of them are related to controller-gen. For some reason, controller-gen is not getting build up in $LOCALBIN (check make file)

  1. kubebuilder create api does not work.
test-operator git:(main) ✗ kubebuilder create api --group test --version v1 --kind TestCR

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/testcr_types.go
controllers/testcr_controller.go
Update dependencies:
$ go mod tidy
Running make:
$ make generate
mkdir -p /Users/mymachine/go/src/gocode/src/test-operator/bin
GOBIN=/Users/mymachine/go/src/gocode/src/test-operator/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
/Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
bash: /Users/mymachine/go/src/gocode/src/test-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:

  1. make controller-gen is not working. Though the command is executed successfully, but right after ls on. the localbin says, not such file or directory.
test-operator % make controller-gen --debug
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for i386-apple-darwin11.3.0
Reading makefiles...
Updating goal targets....
 File `controller-gen' does not exist.
   File `/Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen' does not exist.
  Must remake target `/Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen'.
GOBIN=/Users/mymachine/go/src/gocode/src/test-operator/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
  Successfully remade target file `/Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen'.
Must remake target `controller-gen'.
Successfully remade target file `controller-gen'.

test-operator % ls /Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen
ls: /Users/mymachine/go/src/gocode/src/test-operator/bin/controller-gen: No such file or directory
  • environment
test-operator % go version
go version go1.17.1 darwin/amd64

test-operator % kubebuilder version
Version: main.version{KubeBuilderVersion:"3.4.1", KubernetesVendor:"1.23.5", GitCommit:"d59d7882ce95ce5de10238e135ddff31d8ede026", BuildDate:"2022-05-06T13:58:56Z", GoOs:"darwin", GoArch:"amd64"}
  • Workaround:
    copy controller-gen from the GOPATH/bin to LOCALBIN
test-operator % cp /Users/mymachine/go/bin/controller-gen bin/.

I am not sure how much feasible it is,

Reproducing this issue

No response

KubeBuilder (CLI) Version

3.4.1

PROJECT version

version: "3"

Plugin versions

layout:
- go.kubebuilder.io/v3

Other versions

sigs.k8s.io/controller-runtime v0.11.2

go version go1.17.1 darwin/amd64

Extra Labels

No response

@Cbkhare Cbkhare added the kind/bug Categorizes issue or PR as related to a bug. label May 17, 2022
@Cbkhare Cbkhare changed the title kubebuilder create api is not working kubebuilder create api for controller-gen step is not working May 17, 2022
@camilamacedo86
Copy link
Member

Hi @ryanbrainard,

This issue seems to be introduced with the changes to replace go get with go install. Could you please give a hand on this one?

@ryanbrainard
Copy link
Contributor

Hi @ryanbrainard,

This issue seems to be introduced with the changes to replace go get with go install. Could you please give a hand on this one?

@camilamacedo86 I think you might have the wrong person. I've used this repo, but I don't think I've done anything with that.

@camilamacedo86
Copy link
Member

Sorry, it should be @ryantking :)

@jspc
Copy link

jspc commented May 17, 2022

I'm facing much the same. For anybody after me who does not have controller-gen in GOPATH, you can get it as per $ go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0

@ryantking
Copy link
Contributor

Looking into this, in the mean time GOBIN=$(pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0 should install controller-gen the way the Makefile expects. I'll push up a patch for the generation.

@ryantking
Copy link
Contributor

@Cbkhare @jspc I'm having trouble reproducing this issue:

kubebuilder/testdata/project-v3 master  
❯ rm -rf bin           

kubebuilder/testdata/project-v3 master  
❯ ls bin
"bin": No such file or directory (os error 2)

kubebuilder/testdata/project-v3 master  
❯ make controller-gen
mkdir -p /Users/rking/Projects/kubernetes-sigs/kubebuilder/testdata/project-v3/bin
GOBIN=/Users/rking/Projects/kubernetes-sigs/kubebuilder/testdata/project-v3/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0

kubebuilder/testdata/project-v3 master  2s 
❯ rm bin/controller-gen

kubebuilder/testdata/project-v3 master  
❯ ls bin

kubebuilder/testdata/project-v3 master  
❯ make controller-gen

kubebuilder/testdata/project-v3 master  
❯ make controller-gen
GOBIN=/Users/rking/Projects/kubernetes-sigs/kubebuilder/testdata/project-v3/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0

kubebuilder/testdata/project-v3 master  2s 
❯ ls bin
controller-gen

I tried this on both Linux and macOS with GNU Make 4.3.

To help out, can I get:

  1. Platform you're using.
  2. Version of go, make, and output from go env
  3. Whether you made a new project or followed the upgrade instructions.
  4. A copy and paste of the tool install section of the Makefile.

The output from the original issue looks like the Makefile correctly calls the go install command so I'm not sure why its not actually installing it.

@jaypoulz
Copy link

I am on Linux with go version go1.18.2 linux/amd64
The way I repro'd was:

#!/bin/bash
export GOBIN=$(pwd)/test-operator-sdk/bin 
rm -rf test-operator-sdk
mkdir test-operator-sdk; pushd test-operator-sdk; operator-sdk init --domain jaypoulz.me --repo github.com/jaypoulz/test-operator-sd
# Uncomment to fix # go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0
operator-sdk create api --group test --version v1 --kind Test
popd

Make version 4.3

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/jpoulin/go"
GOCACHE="/home/jpoulin/.cache/go-build"
GOENV="/home/jpoulin/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jpoulin/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jpoulin/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2839905357=/tmp/go-build -gno-record-gcc-switches"

Makefile tool install:

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
.PHONY: controller-gen
controller-gen: ## Download controller-gen locally if necessary.
        $(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.8.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
.PHONY: kustomize
kustomize: ## Download kustomize locally if necessary.
        $(call go-get-tool,$(KUSTOMIZE),sigs.k8s.io/kustomize/kustomize/v3@v3.8.7)

ENVTEST = $(shell pwd)/bin/setup-envtest
.PHONY: envtest
envtest: ## Download envtest-setup locally if necessary.
        $(call go-get-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

# 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 ;\
TMP_DIR=$$(mktemp -d) ;\
cd $$TMP_DIR ;\
go mod init tmp ;\
echo "Downloading $(2)" ;\
GOBIN=$(PROJECT_DIR)/bin go get $(2) ;\
rm -rf $$TMP_DIR ;\
}
endef

@jaypoulz
Copy link

I hit a later issue with kustomize as well:
Trying to install it manually via:
go install sigs.k8s.io/kustomize/kustomize/v3@v3.8.7
ended up hitting: golang/go#44840

Instead, I moved forward with:
go install sigs.k8s.io/kustomize/kustomize@latest

@camilamacedo86
Copy link
Member

@jaypoulz 1.18 is not supported yet.
Are you able to face the same issues using go 1.17?

@ryantking
Copy link
Contributor

Ahhhh, there's your problem. Operator SDK does not have a release yet that includes the new version of kubebuilder, which means the Makefiles still have the old way of installing tools with go get instead of go install. Installing tools with go get was removed in go 1.18, it now just adds the package to your module, only go install installs binaries. That explains why you're getting a no-op. If you install Operator SDK from master then you will be able to scaffold a project with a go 1.18-compatible Makefile. Note that Kubebuilder overall isn't confirmed to work on 1.18 yet, but the Makefile generation has been updated to be forward-compatible.

@jaypoulz
Copy link

go 1.17 seems to be working. Worth noting that the default version on fedora is 1.16, so I hit (kubernetes-sigs/controller-tools#643 first).

It may be worth making a note in the install docs about the golang version if it's possible to be burned both ways. Maybe it's there and I missed it. 😅

@ryantking
Copy link
Contributor

Fantastic! Its listed that we support go 1.17, but probably should be more explicitly called out since the error is so non-obvious.

Can you confirm this works for you and close the issue @Cbkhare

@camilamacedo86
Copy link
Member

The golang version supported is defined in the docs and release page, see: https://book.kubebuilder.io/quick-start.html#prerequisites

So I am closing this one.
However, feel free to re-open if you see that is required.

@Jerry-yz
Copy link

i have same error but when init project
kubebuilder init --domain tutorial.kubebuilder.io --repo tutorial.kubebuilder.io/project
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.7.0
Update go.mod:
$ go mod tidy
Running make:
$ make
go: creating new go.mod: module tmp
Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1
go: added github.com/fatih/color v1.7.0
go: added github.com/gobuffalo/flect v0.2.0
go: added github.com/gogo/protobuf v1.3.1
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.8
go: added github.com/mattn/go-colorable v0.1.2
go: added github.com/mattn/go-isatty v0.0.8
go: added github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: added github.com/modern-go/reflect2 v1.0.1
go: added github.com/spf13/cobra v1.0.0
go: added github.com/spf13/pflag v1.0.5
go: added golang.org/x/mod v0.2.0
go: added golang.org/x/net v0.0.0-20200226121028-0de0cce0169b
go: added golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7
go: added golang.org/x/text v0.3.2
go: added golang.org/x/tools v0.0.0-20200616195046-dc31b401abb5
go: added golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
go: added gopkg.in/inf.v0 v0.9.1
go: added gopkg.in/yaml.v2 v2.2.8
go: added gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966
go: added k8s.io/api v0.18.2
go: added k8s.io/apiextensions-apiserver v0.18.2
go: added k8s.io/apimachinery v0.18.2
go: added k8s.io/klog v1.0.0
go: added k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89
go: added sigs.k8s.io/controller-tools v0.4.1
go: added sigs.k8s.io/structured-merge-diff/v3 v3.0.0
go: added sigs.k8s.io/yaml v1.2.0
/home/yzhen/learn/project/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
/bin/sh: 1: /home/yzhen/learn/project/bin/controller-gen: not found
make: *** [Makefile:62: generate] Error 127
Error: failed to initialize project with "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

No branches or pull requests

7 participants