rules_k8s icon indicating copy to clipboard operation
rules_k8s copied to clipboard

Using a kubectl built from source is broken

Open nlopezgi opened this issue 5 years ago • 3 comments

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

nlopezgi avatar Feb 04 '20 15:02 nlopezgi

Is there a solution to this problem? I'm building with GKE and it doesn't seem to work

marco3211 avatar May 01 '20 18:05 marco3211

still getting this error on golang 1.16.2 / k8s 1.18.16

sgammon avatar Apr 09 '21 17:04 sgammon

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.

codesuki avatar Oct 11 '21 03:10 codesuki