treewide: replace stampsrcs with embed
A rules_go maintainer suggested using embed instead of stampsrcs:
https://github.com/bazel-contrib/rules_go/issues/3507
For Kubernetes, this means we need to patch the version libraries.
Instead of creating a separate file for each variable, I put them all in
one file, which is parsed in an init function. This init function needs
to run before all other init functions, which access the variables.
Another benefit of this change is that versions are stamped in all
binaries which include Kubernetes client libraries, not just hyperkube.
Change-Id: Ib1157d3686fc35e0c4191d2fc8e165862a1973c7
Reviewed-on: https://review.monogon.dev/c/monogon/+/4208
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/third_party/com_k8s_io_component_base/version-stamp.patch b/third_party/com_k8s_io_component_base/version-stamp.patch
new file mode 100644
index 0000000..d411f0d
--- /dev/null
+++ b/third_party/com_k8s_io_component_base/version-stamp.patch
@@ -0,0 +1,55 @@
+diff --git a/version/BUILD.bazel b/version/BUILD.bazel
+index d6aeae2..978a9d3 100644
+--- a/version/BUILD.bazel
++++ b/version/BUILD.bazel
+@@ -7,6 +7,7 @@ go_library(
+ "dynamic.go",
+ "version.go",
+ ],
++ embedsrcs = ["@@//build:kubernetes_stamp"],
+ importpath = "k8s.io/component-base/version",
+ visibility = ["//visibility:public"],
+ deps = [
+diff --git a/version/base.go b/version/base.go
+index 4650011..c7250a7 100644
+--- a/version/base.go
++++ b/version/base.go
+@@ -16,6 +16,8 @@ limitations under the License.
+
+ package version
+
++import _ "embed"
++
+ // Base version information.
+ //
+ // This is the fallback data used when version information from git is not
+@@ -39,7 +41,9 @@ var (
+ // them irrelevant. (Next we'll take it out, which may muck with
+ // scripts consuming the kubectl version output - but most of
+ // these should be looking at gitVersion already anyways.)
++ //go:embed build/kubernetes_gitMajor.txt
+ gitMajor string // major version, always numeric
++ //go:embed build/kubernetes_gitMinor.txt
+ gitMinor string // minor version, numeric possibly followed by "+"
+
+ // semantic version, derived by build scripts (see
+@@ -55,11 +59,15 @@ var (
+ // NOTE: The $Format strings are replaced during 'git archive' thanks to the
+ // companion .gitattributes file containing 'export-subst' in this same
+ // directory. See also https://git-scm.com/docs/gitattributes
+- gitVersion = "v0.0.0-master+$Format:%H$"
+- gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD)
+- gitTreeState = "" // state of git tree, either "clean" or "dirty"
++ //go:embed build/kubernetes_gitVersion.txt
++ gitVersion string
++ //go:embed build/kubernetes_gitCommit.txt
++ gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
++ //go:embed build/kubernetes_gitTreeState.txt
++ gitTreeState string // state of git tree, either "clean" or "dirty"
+
+- buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
++ //go:embed build/kubernetes_buildDate.txt
++ buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
+ )
+
+ const (