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},
)
diff --git a/metropolis/node/kubernetes/hyperkube/kubernetes_version_def.bzl b/metropolis/node/kubernetes/hyperkube/kubernetes_version_def.bzl
deleted file mode 100644
index ddd1347..0000000
--- a/metropolis/node/kubernetes/hyperkube/kubernetes_version_def.bzl
+++ /dev/null
@@ -1,48 +0,0 @@
-# Copyright 2020 The Monogon Project Authors.
-#
-# SPDX-License-Identifier: Apache-2.0
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# This reimplements k8s.io/kubernetes-compatible version_x_defs, while namespacing
-# stamp variables with KUBERNETES_*.
-# The generated build defs then are defines by the workspace status script, see
-# //build/print-workspace-status.sh.
-
-def version_x_defs():
- stamp_pkgs = [
- "k8s.io/component-base/version",
- "k8s.io/client-go/pkg/version",
- ]
-
- stamp_vars = [
- "buildDate",
- "gitCommit",
- "gitTreeState",
- ]
-
- stable_stamp_vars = [
- "gitMajor",
- "gitMinor",
- "gitVersion",
- ]
-
- # Generate the cross-product.
- x_defs = {}
- for pkg in stamp_pkgs:
- for var in stamp_vars:
- x_defs["%s.%s" % (pkg, var)] = "{KUBERNETES_%s}" % var
- for pkg in stamp_pkgs:
- for var in stable_stamp_vars:
- x_defs["%s.%s" % (pkg, var)] = "{STABLE_KUBERNETES_%s}" % var
- return x_defs