rules_k8s
rules_k8s copied to clipboard
Using a kubectl built from source is broken
Dependencies are out of date, and updating them results in errors like
E0203 15:07:25.311001 5 main.go:52] Error: Failed making a parser: unable to add directory "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types": unable to import "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types": cannot find package "k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types" in any of:
external/go_sdk/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types (from $GOROOT)
bazel-out/k8-fastbuild/bin/external/io_kubernetes/staging/src/k8s.io/apimachinery/pkg/util/sets/gopath/src/k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/util/sets/types (from $GOPATH)
Target @io_kubernetes//cmd/kubectl:kubectl failed to build
Looks like kubectl can no longer be built as an external repo. Will need to open an issue for them, and then once that is solved we need to have a better mechanism to update the contents of https://github.com/bazelbuild/rules_k8s/blob/master/toolchains/kubectl/defaults.bzl and regularly test this feature. See also https://github.com/bazelbuild/rules_k8s/issues/512
Is there a solution to this problem? I'm building with GKE and it doesn't seem to work
still getting this error on golang 1.16.2 / k8s 1.18.16
Related to this, we switched to using the release binaries because building from source stopped working. We immediately ran into the next problem which is that the way the kubectl toolchain is set up it only supports one architecture. We fixed this with the following patch and a separate toolchain declaration.
--- a/toolchains/kubectl/BUILD 2021-10-11 12:11:16.000000000 +0900
+++ b/toolchains/kubectl/BUILD 2021-10-11 12:12:13.000000000 +0900
@@ -19,7 +19,10 @@
licenses(["notice"]) # Apache 2.0
# kubectl toolchain type
-toolchain_type(name = "toolchain_type")
+toolchain_type(
+ name = "toolchain_type",
+ visibility = ["//visibility:public"]
+)
# Default kubectl toolchain that expects the 'kubectl' executable
# to be in the PATH
@@ -31,6 +34,10 @@
toolchain(
name = "kubectl_linux_toolchain",
+ exec_compatible_with = [
+ "@platforms//os:linux",
+ "@platforms//cpu:x86_64",
+ ],
target_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
toolchain(
name = "kubectl_osx_toolchain",
exec_compatible_with = [
"@bazel_tools//platforms:osx",
"@platforms//cpu:x86_64",
],
target_compatible_with = [
"@bazel_tools//platforms:linux",
"@bazel_tools//platforms:x86_64",
],
toolchain = "@k8s_config_osx//:toolchain",
toolchain_type = "@io_bazel_rules_k8s//toolchains/kubectl:toolchain_type",
)
Maybe it helps someone. There would be more need to make this really work across all architectures I guess.