m/n/k/hyperkube: avoid unnecessary rebuilds
Previously, hyperkube was rebuilt each time a commit was made in the
monorepo. This change stops this by reading the variables from a
filtered stamp file instead. Now, only this filtered file is rebuilt
each time, which is very fast compared to linking hyperkube.
Previously, volatile status variables were used for gitTreeState and
buildDate. But the volatile status is bad for reproducibility, as it
makes Bazel intentionally use stale caches. Instead, these variables
are now only defined in release builds, and left unstamped during
development. These variables are available at the /version endpoint of
the apiserver, so there may be some utility in defining them for release
builds, but they are not needed during development.
The buildDate is now taken from the commit date instead of
SOURCE_DATE_EPOCH, which simplifies the build process as we don't need
to define that variable anymore.
Previously, KUBERNETES_gitCommit was referenced but not defined by the
status script. It is now defined as the monorepo commit, which is more
useful than leaving it blank.
Change-Id: I6228888507e400ca1f53167ee9d4f132f5711a45
Reviewed-on: https://review.monogon.dev/c/monogon/+/4167
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/metropolis/node/kubernetes/hyperkube/BUILD.bazel b/metropolis/node/kubernetes/hyperkube/BUILD.bazel
index 9fb4c22..3930eb8 100644
--- a/metropolis/node/kubernetes/hyperkube/BUILD.bazel
+++ b/metropolis/node/kubernetes/hyperkube/BUILD.bazel
@@ -1,5 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
-load(":kubernetes_version_def.bzl", "version_x_defs")
go_library(
name = "hyperkube_lib",
@@ -18,9 +17,24 @@
],
)
+stamp_pkgs = [
+ "k8s.io/component-base/version",
+ "k8s.io/client-go/pkg/version",
+]
+
+stamp_vars = [
+ "gitMajor",
+ "gitMinor",
+ "gitVersion",
+ "gitCommit",
+ "gitTreeState",
+ "buildDate",
+]
+
go_binary(
name = "hyperkube",
embed = [":hyperkube_lib"],
+ stampsrcs = ["//build:stabler_status"],
visibility = ["//metropolis/node:__pkg__"],
- x_defs = version_x_defs(),
+ x_defs = {"%s.%s" % (pkg, var): "{STABLER_KUBERNETES_%s}" % var for pkg in stamp_pkgs for var in stamp_vars},
)