kubernetes: Building kubectl with Bazel as an external repo dependency is not currently possible.
What would you like to be added: I would like to be able to build kubectl as a dependency of another Bazel project. Specifically, it should be possible to add to a WORKSPACE file something like:
http_archive(
name = "io_kubernetes",
sha256 = "4737d3b10b27e391924f89b5ac3aaa5470619b92b75fe1ff5210cc30c56e2e53",
strip_prefix = "kubernetes-1.10.10",
urls = ["https://github.com/kubernetes/kubernetes/archive/v1.10.10.tar.gz"]
)
load_something_something_kubernetes(...)
and then do
bazel build @io_kubernetes//cmd/kubectl:kubectl
(note the load_something_something_kubernetes does not exist today)
Why is this needed:
This would enable using kubectl as an external dependency of rules_k8s (https://github.com/bazelbuild/rules_k8s) project. This is very desirable as it would enable building kubectl from source (https://github.com/bazelbuild/rules_k8s/issues/227) and use that as the binary to use to execute k8s commands. We often get requests from rules_k8s users that this would be a very desirable feature.
More notes below expanding on what issues I found when I tried to build kubectl as an external dep:
I found the following issues:
-
the build depends on an
@org_golang_x_toolsrepo. I could not find out where this is being pulled (perhaps in a repository_rule?), however, I could hack around this by copying it from the kubernetes project directly. I also needed to add manually to my WORKSPACE ahttp_archiverule to download@io_kubernetes_build -
the repo is using genrules (e.g.
vendor/k8s.io/apimachinery/pkg/util/sets/BUILD:23) which are running go binaries produced by other build steps, but are not referencing these properly when used in an external repo. I got this error message:
import "./vendor/k8s.io/apimachinery/pkg/util/sets/types": cannot find package "./vendor/k8s.io/apimachinery/pkg/util/sets/types" in:
/usr/local/google/home/<...>/ffcac8bde6710ff680ff645bb4ae7c92/sandbox/linux-sandbox/30/execroot/io_bazel_rules_k8s/vendor/k8s.io/apimachinery/pkg/util/sets/types
fyi @fejta @chrislovecnm
/kind feature
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 15 (12 by maintainers)
Tested successfully with kubernetes-1.13.0-beta.1 (was able to build kubectl binary with kubernetes external repo) and all I needed to add to the rules_k8s workspace was:
Note my workspace already included a recent version of
rules_go.Thanks for your help @ixdy . I’m closing this issue, but I still want to pursue doing the built + released
kubectlbinaries, so pointers to where those are located are still useful.That
go_genruleissue invendor/k8s.io/apimachinery/pkg/util/setsis hopefully fixed in 1.12+ (#64122) though I haven’t tested it in an external dependency setting.A few comments here:
rules_go. You might have an easier time with a more recent release, though a number of issues would still remain.rules_gowithgo_rules_dependencies()andgo_register_toolchains(). We call those in ourWORKSPACE.kubernetes/kubernetesdirectly, and similarly we haven’t really put any effort into makingkubernetes/kubernetesa valid bazel dependency, either. We’d probably need to factor out some of the dependencies fromWORKSPACElike many projects do, and we’d also have to fix that genrule as you noted. I think @mikedanese opened a PR once to start fixing some of this, but it never merged.kubectlbinaries instead, doing something similar to howrules_godownloads the correct toolchain?kubectlintends to move to its own repo eventually, which should make this more manageable in the future.