rules_kubectl
Bazel rules for a hermetic kubectl.
@kubectl//:kubectlruns the host platform's binary from the directorybazel runwas invoked in.@rules_kubectl//kubectl:toolchain_typeis the toolchain type rules consume to runkubectlin an action.@rules_kubectl//kubectl:current_toolchainexposes the resolved binary togenruleand friends as theKUBECTL(execpath) andKUBECTL_RLOCATIONPATH(rlocationpath) make variables.
Rules
kubectl_toolchain
load("@rules_kubectl//kubectl:defs.bzl", "kubectl_toolchain")
kubectl_toolchain(name, kubectl, version)
A kubectl toolchain.
Rules consume it through @rules_kubectl//kubectl:toolchain_type:
def _impl(ctx):
toolchain = ctx.toolchains["@rules_kubectl//kubectl:toolchain_type"]
ctx.actions.run(
executable = toolchain.kubectl,
...
)
The ToolchainInfo carries kubectl (the binary File) and version (a string, possibly empty).
@rules_kubectl//kubectl:current_toolchain exposes the binary through two make variables: KUBECTL is its execpath, for use in actions, and KUBECTL_RLOCATIONPATH is its rlocationpath, for looking it up in runfiles.
genrule(
name = "pods",
outs = ["pods.txt"],
cmd = "$(KUBECTL) version --client > $@",
toolchains = ["@rules_kubectl//kubectl:current_toolchain"],
)
sh_test(
name = "pods_test",
srcs = ["pods_test.sh"],
data = ["@rules_kubectl//kubectl:current_toolchain"],
env = {"KUBECTL": "$(KUBECTL_RLOCATIONPATH)"},
toolchains = ["@rules_kubectl//kubectl:current_toolchain"],
)
ATTRIBUTES