From 0be3d4b132766b89bc2821c86a6fda29a1a212dd Mon Sep 17 00:00:00 2001 From: Malte Poll Date: Wed, 16 Aug 2023 22:00:07 +0200 Subject: [PATCH] bazel: provide k8s / envtest toolchains --- WORKSPACE.bazel | 5 ++++ bazel/envtest/BUILD.bazel | 47 +++++++++++++++++++++++++++++++++++ bazel/toolchains/k8s.bzl | 52 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 104 insertions(+) create mode 100644 bazel/envtest/BUILD.bazel create mode 100644 bazel/toolchains/k8s.bzl diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 9c57c45b7..af7968da4 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -173,3 +173,8 @@ node_maintainance_operator_deps() load("//bazel/toolchains:ci_deps.bzl", "ci_deps") ci_deps() + +# k8s deps +load("//bazel/toolchains:k8s.bzl", "k8s_deps") + +k8s_deps() diff --git a/bazel/envtest/BUILD.bazel b/bazel/envtest/BUILD.bazel new file mode 100644 index 000000000..fcf30e75c --- /dev/null +++ b/bazel/envtest/BUILD.bazel @@ -0,0 +1,47 @@ +load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory") + +# tools (aka KUBEBUILDER_ASSETS) are a collection of binaries that are used by +# kubebuilder for envtests. +copy_to_directory( + name = "tools", + srcs = [ + ":etcd", + ":kube-apiserver", + ":kubectl", + ], + include_external_repositories = ["kubebuilder_tools_*"], + visibility = ["//visibility:public"], +) + +alias( + name = "etcd", + actual = select({ + "@io_bazel_rules_go//go/platform:darwin_amd64": "@kubebuilder_tools_darwin_amd64//:etcd", + "@io_bazel_rules_go//go/platform:darwin_arm64": "@kubebuilder_tools_darwin_arm64//:etcd", + "@io_bazel_rules_go//go/platform:linux_amd64": "@kubebuilder_tools_linux_amd64//:etcd", + "@io_bazel_rules_go//go/platform:linux_arm64": "@kubebuilder_tools_linux_arm64//:etcd", + }), + visibility = ["//visibility:public"], +) + +alias( + name = "kube-apiserver", + actual = select({ + "@io_bazel_rules_go//go/platform:darwin_amd64": "@kubebuilder_tools_darwin_amd64//:kube-apiserver", + "@io_bazel_rules_go//go/platform:darwin_arm64": "@kubebuilder_tools_darwin_arm64//:kube-apiserver", + "@io_bazel_rules_go//go/platform:linux_amd64": "@kubebuilder_tools_linux_amd64//:kube-apiserver", + "@io_bazel_rules_go//go/platform:linux_arm64": "@kubebuilder_tools_linux_arm64//:kube-apiserver", + }), + visibility = ["//visibility:public"], +) + +alias( + name = "kubectl", + actual = select({ + "@io_bazel_rules_go//go/platform:darwin_amd64": "@kubebuilder_tools_darwin_amd64//:kubectl", + "@io_bazel_rules_go//go/platform:darwin_arm64": "@kubebuilder_tools_darwin_arm64//:kubectl", + "@io_bazel_rules_go//go/platform:linux_amd64": "@kubebuilder_tools_linux_amd64//:kubectl", + "@io_bazel_rules_go//go/platform:linux_arm64": "@kubebuilder_tools_linux_arm64//:kubectl", + }), + visibility = ["//visibility:public"], +) diff --git a/bazel/toolchains/k8s.bzl b/bazel/toolchains/k8s.bzl new file mode 100644 index 000000000..229c23667 --- /dev/null +++ b/bazel/toolchains/k8s.bzl @@ -0,0 +1,52 @@ +"""versioned kubernetes release artifacts (dl.k8s.io)""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def k8s_deps(): + envtest_deps() + +def envtest_deps(): + http_archive( + name = "kubebuilder_tools_darwin_amd64", + strip_prefix = "kubebuilder/bin", + type = "tar.gz", + urls = [ + "https://cdn.confidential.cloud/constellation/cas/sha256/e1913674bacaa70c067e15649237e1f67d891ba53f367c0a50786b4a274ee047", + "https://kubebuilder-tools.storage.googleapis.com/kubebuilder-tools-1.27.1-darwin-amd64.tar.gz", + ], + sha256 = "e1913674bacaa70c067e15649237e1f67d891ba53f367c0a50786b4a274ee047", + build_file_content = """exports_files(["etcd", "kubectl", "kube-apiserver"], visibility = ["//visibility:public"])""", + ) + http_archive( + name = "kubebuilder_tools_darwin_arm64", + strip_prefix = "kubebuilder/bin", + type = "tar.gz", + urls = [ + "https://cdn.confidential.cloud/constellation/cas/sha256/0422632a2bbb0d4d14d7d8b0f05497a4d041c11d770a07b7a55c44bcc5e8ce66", + "https://kubebuilder-tools.storage.googleapis.com/kubebuilder-tools-1.27.1-darwin-arm64.tar.gz", + ], + sha256 = "0422632a2bbb0d4d14d7d8b0f05497a4d041c11d770a07b7a55c44bcc5e8ce66", + build_file_content = """exports_files(["etcd", "kubectl", "kube-apiserver"], visibility = ["//visibility:public"])""", + ) + http_archive( + name = "kubebuilder_tools_linux_amd64", + strip_prefix = "kubebuilder/bin", + type = "tar.gz", + urls = [ + "https://cdn.confidential.cloud/constellation/cas/sha256/f9699df7b021f71a1ab55329b36b48a798e6ae3a44d2132255fc7e46c6790d4d", + "https://kubebuilder-tools.storage.googleapis.com/kubebuilder-tools-1.27.1-linux-amd64.tar.gz", + ], + sha256 = "f9699df7b021f71a1ab55329b36b48a798e6ae3a44d2132255fc7e46c6790d4d", + build_file_content = """exports_files(["etcd", "kubectl", "kube-apiserver"], visibility = ["//visibility:public"])""", + ) + http_archive( + name = "kubebuilder_tools_linux_arm64", + strip_prefix = "kubebuilder/bin", + type = "tar.gz", + urls = [ + "https://cdn.confidential.cloud/constellation/cas/sha256/9d2803e8ca85c465b33c12b06d0b2eba3ddb64b53a468628f741e50b462c46ad", + "https://kubebuilder-tools.storage.googleapis.com/kubebuilder-tools-1.27.1-linux-arm64.tar.gz", + ], + sha256 = "9d2803e8ca85c465b33c12b06d0b2eba3ddb64b53a468628f741e50b462c46ad", + build_file_content = """exports_files(["etcd", "kubectl", "kube-apiserver"], visibility = ["//visibility:public"])""", + )