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

Build failure when run in kubernetes-sig/controller-tools #924

Closed
ob opened this issue Oct 1, 2020 · 2 comments
Closed

Build failure when run in kubernetes-sig/controller-tools #924

ob opened this issue Oct 1, 2020 · 2 comments

Comments

@ob
Copy link
Contributor

ob commented Oct 1, 2020

I was trying to build kubernetes-sigs/controller-tools using bazel 3.5.0, and followed the instructions on the main README from Gazelle.

What version of gazelle are you using?

0.22.1

What version of rules_go are you using?

0.24.3

What version of Bazel are you using?

3.5.0

Does this issue reproduce with the latest releases of all the above?

Yeah.

What operating system and processor architecture are you using?

ProductName:    Mac OS X
ProductVersion: 10.15.7
BuildVersion:   19H2

What did you do?

$ git clone git@github.com:kubernetes-sigs/controller-tools.git
$ cd controller-tools

Create WORKSPACE and BUILD.bazel files as per the main README.

$ bazel run //:gazelle
$ bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=deps.bzl%go_dependencies
$ bazel build //cmd/...
INFO: Invocation ID: 901741d9-c8be-4b47-87ed-ea9ab7200bcc
ERROR: /Users/obonilla/tmp/controller-tools/cmd/controller-gen/BUILD.bazel:3:11: no such package '@io_k8s_sigs_controller_tools//pkg/crd': The repository '@io_k8s_sigs_controller_tools' could not be resolved and referenced by '//cmd/controller-gen:controller-gen_lib'
ERROR: /Users/obonilla/tmp/controller-tools/cmd/controller-gen/BUILD.bazel:3:11: no such package '@io_k8s_sigs_controller_tools//pkg/genall/help': The repository '@io_k8s_sigs_controller_tools' could not be resolved and referenced by '//cmd/controller-gen:controller-gen_lib'
ERROR: Analysis of target '//cmd/controller-gen:controller-gen_lib' failed; build aborted: Analysis failed
INFO: Elapsed time: 0.149s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (2 packages loaded, 0 targets configured)

What did you expect to see?

A successful build.

What did you see instead?

ERROR: /Users/obonilla/tmp/controller-tools/cmd/controller-gen/BUILD.bazel:3:11: no such package '@io_k8s_sigs_controller_tools//pkg/genall/help': The repository '@io_k8s_sigs_controller_tools' could not be resolved and referenced by '//cmd/controller-gen:controller-gen_lib'
@jayconrod
Copy link
Contributor

What did you write for the # gazelle:prefix directive in BUILD.bazel? It should be:

# gazelle:prefix sigs.k8s.io/controller-tools

The prefix should match the module path in go.mod. I guess the Go extension should probably be changed to read a prefix from go.mod automatically so that would no longer be necessary.

Also, try running bazel run //:gazelle again after update-repos. The update-repos command can affect the output of a normal run of Gazelle. The README should be updated to fix that.

After that, I see an error like:

ERROR: /private/var/tmp/_bazel_jayconrod/b32a2121ffa75e02622b4c8a64487730/external/io_k8s_apimachinery/pkg/apis/meta/v1/BUILD.bazel:15:17: no such package '@io_k8s_apimachinery//k8s.io/apimachinery/pkg/runtime': BUILD file not found in directory 'k8s.io/apimachinery/pkg/runtime' of external repository @io_k8s_apimachinery. Add a BUILD file to a directory to mark it as a package. and referenced by '@io_k8s_apimachinery//pkg/apis/meta/v1:v1_go_proto'

This happens because Kubernetes uses proto import paths that don't match the module root directory. There are ways to adjust the import prefix in go_repository, but it's probably better to disable proto rule generation entirely. You can do that by running update-repos with -build_file_proto_mode=disable_global. This will add build_file_proto_mode = "disable_global" to imported go_repository rules. You'll also need to add # gazelle:proto disable_global to your root build file.

@ob
Copy link
Contributor Author

ob commented Oct 3, 2020

Thanks, I think I've made it work by disabling proto mode like you suggested.

@ob ob closed this as completed Oct 3, 2020
ob added a commit to ob/bazel-gazelle that referenced this issue Oct 3, 2020
This is from feedback from [this comment](bazel-contrib#924 (comment))
jayconrod pushed a commit that referenced this issue Oct 6, 2020
This is from feedback from [this comment](#924 (comment))
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