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

error 'build constraints exclude all Go files' when performing: go run controller-gen/main.go on golang1.12 container #396

Closed
RamLavi opened this issue Jan 29, 2020 · 2 comments

Comments

@RamLavi
Copy link

RamLavi commented Jan 29, 2020

I am getting the following error when my container (base image is FROM golang:1.12.0 or 1.12.+) performs the following command via one of the Makefile sections: go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd. The error I get is:

go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd
-: build constraints exclude all Go files in /go/src/github.com/k8snetworkplumbingwg/kubemacpool
Error: not all generators ran successfully
run `controller-gen crd -w` to see all available markers, or `controller-gen crd -h` for usage
exit status 1

(btw if I change the image back to golang 1.11.9 then the issue does not occur.)

I think the issue is related to the fact that controller-gen is installed via build constraint //+build, as this was insinuated in the following links: golang/go#31661 and golang/go#29268 (comment).

Do you have any idea how to handle it?

Environment:

GOARCH="amd64"
GOBIN=""
GOCACHE="/.cache/go-build"
GOEXE=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/go/src/github.com/k8snetworkplumbingwg/kubemacpool/go.mod"
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-build569404837=/tmp/go-build -gno-record-gcc-switches"

Go Version:
go version go1.12.15 linux/amd64

@RamLavi
Copy link
Author

RamLavi commented Jan 29, 2020

well, this seemed to do the trick:

go run vendor/sigs.k8s.io/controller-tools/cmd/controller-gen/main.go crd rbac:roleName=kubemacpool paths=./pkg/... output:crd:dir=config/ output:stdout

@RamLavi RamLavi closed this as completed Jan 29, 2020
@cnfatal
Copy link

cnfatal commented May 20, 2021

ensure file hack/tools.go content, there must a new empty line after the// +build tools comment

// +build tools

/*
...license...
*/

// This package imports things required by build scripts, to force `go mod` to see them as dependencies
package tools

import _ "k8s.io/code-generator"

not

// +build tools
package tools

import _ "k8s.io/code-generator"

IDK why, but it's works ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants