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

Fix or update build files when syncing #49

Closed
jayconrod opened this issue Feb 28, 2018 · 8 comments
Closed

Fix or update build files when syncing #49

jayconrod opened this issue Feb 28, 2018 · 8 comments

Comments

@jayconrod
Copy link

A build failure was originally reported in bazel-contrib/rules_go#1356. It appears that Bazel BUILD files in api, apimachinery, and client-go refer to non-existent packages.

Steps to reproduce

  • In an empty workspace, create an empty BUILD file and a WORKSPACE file like below:
http_archive(
    name = "io_bazel_rules_go",
    sha256 = "4b14d8dd31c6dbaf3ff871adcd03f28c3274e42abc855cb8fb4d01233c0154dc",
    url = "https://github.com/bazelbuild/rules_go/releases/download/0.10.1/rules_go-0.10.1.tar.gz",
)

http_archive(
    name = "bazel_gazelle",
    sha256 = "6228d9618ab9536892aa69082c063207c91e777e51bd3c5544c9c060cafe1bd8",
    url = "https://github.com/bazelbuild/bazel-gazelle/releases/download/0.10.0/bazel-gazelle-0.10.0.tar.gz",
)

load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")

go_rules_dependencies()

go_register_toolchains()

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

gazelle_dependencies()

load("@bazel_gazelle//:def.bzl", "go_repository")

git_repository(
    name = "io_k8s_api",
    remote = "https://github.com/kubernetes/api",
    tag = "kubernetes-1.9.3",
)

git_repository(
    name = "io_k8s_apimachinery",
    remote = "https://github.com/kubernetes/apimachinery",
    tag = "kubernetes-1.9.3",
)

git_repository(
    name = "io_k8s_client_go",
    remote = "https://github.com/kubernetes/client-go",
    tag = "v6.0.0",
)
  • Run this command:
$ bazel build @io_k8s_client_go//kubernetes/typed/core/v1:go_default_library
ERROR: /usr/local/google/home/jayconrod/.cache/bazel/_bazel_jayconrod/533bcca7b8c77451fbaf7e2a9f7692b3/external/io_k8s_client_go/kubernetes/typed/core/v1/BUILD:8:1: no such package '@io_k8s_client_go//vendor/k8s.io/apimachinery/pkg/types': BUILD file not found on package path and referenced by '@io_k8s_client_go//kubernetes/typed/core/v1:go_default_library'.
ERROR: Analysis of target '@io_k8s_client_go//kubernetes/typed/core/v1:go_default_library' failed; build aborted: no such package '@io_k8s_client_go//vendor/k8s.io/apimachinery/pkg/types': BUILD file not found on package path.

Analysis

The BUILD file for the package @io_k8s_client_go//kubernetes/typed/core/v1 refers to rules in //vendor/k8s.io/.... That directory doesn't exist in this repository.

I suspect this bot may have copied the source files from k/k without updating the build files. Not sure what the right answer is. If the bot removes build files during sync, it may be possible to regenerate them correctly with Gazelle via go_repository. If the bot updates build files using Gazelle during sync, all dependencies will need to be vendored or declared using external repositories in WORKSPACE.

@jayconrod
Copy link
Author

cc @ixdy @jmhodges

@sttts
Copy link
Contributor

sttts commented Feb 28, 2018

Just to make sure we are talking about the same thing: this is about using client-go in an external project that builds with bazel?

@jmhodges
Copy link

Yep, that's what we're talking about. (I'm a non-Googler who is trying to do this)

@ixdy
Copy link
Member

ixdy commented Feb 28, 2018

My first take was that we hadn't encountered this issue before because most kubernetes extensions use go vendoring, and gazelle generally fixes the BUILD rules appropriately.

But then I read https://github.com/kubernetes/client-go/blob/d902e7da4bfa28d901dca2cb81b76e40ee7703ae/INSTALL.md and learned that it's recommended you go get -u k8s.io/api-machinery/... to get the necessary dependencies. So it's decidedly different from the main kubernetes/kubernetes repo.

I guess one approach which would fix this for bazel would be to add the necessary dependencies to the bazel WORKSPACE for the published repos as @jmhodges did above, along with rewriting the BUILD rules during publishing so they're internally consistent. This likely wouldn't change anything for non-bazel consumers, though maintenance becomes more tricky. I'm also not sure how to make this interoperate well with kubernetes/kubernetes, where we don't currently have any go dependencies in the bazel WORKSPACE.

@ixdy
Copy link
Member

ixdy commented Feb 28, 2018

as @jmhodges points out in bazel-contrib/rules_go#1356, it's also a bit weird that we publish BUILD files but not WORKSPACE files for the published repositories.

maybe we should at least remove the BUILD files from the published repos until we have a better story for making them consumable downstream.

@sttts
Copy link
Contributor

sttts commented Mar 1, 2018

Without deeper understanding of bazel, removing the BUILD files sounds fine.

@jmhodges
Copy link

jmhodges commented Mar 2, 2018

Would love to see that BUILD file deletion happen!

@sttts
Copy link
Contributor

sttts commented Mar 2, 2018

#50 needs a review. https://github.com/sttts/client-go is the output of the bot with that patch.

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

4 participants