Merge "third_party/go/kubernetes: fix version reported in kubectl"
diff --git a/bzl/workspace-status.sh b/bzl/workspace-status.sh
index c039372..56a3d4d 100755
--- a/bzl/workspace-status.sh
+++ b/bzl/workspace-status.sh
@@ -14,8 +14,30 @@
   cd $1; git describe --always --match "v[0-9].*" --dirty
 }
 
+# Get Kubernetes version by doing an ugly grep. This returns something line 'v1.19.3'.
+function kube_ver() {
+  cd $1
+  grep -A 10 io_k8s_kubernetes third_party/go/repositories.bzl | grep version | head -n 1 | cut -d '"' -f 2
+}
+
+KUBE_MAJOR=$(kube_ver . | sed -e 's,v,,' | cut -d . -f 1)
+KUBE_MINOR=$(kube_ver . | sed -e 's,v,,' | cut -d . -f 2)
+KUBE_PATCH=$(kube_ver . | sed -e 's,v,,' | cut -d . -f 3)
+
 echo STABLE_BUILD_GERRIT-OAUTH-PROVIDER_LABEL $(rev .)
 echo STABLE_BUILD_OWNERS_LABEL $(rev .)
 echo STABLE_GIT_COMMIT $(git rev-parse HEAD)
 echo STABLE_GIT_VERSION $(rev .)
 echo STABLE_BUILDER $(id -un)@$(hostname -f):$(pwd)
+
+# Kubernetes compatibility - see //third_party/go/kubernetes:version.bzl.
+echo STABLE_KUBERNETES_buildDate $(date -u +'%Y-%m-%dT%H:%M:%SZ')
+echo STABLE_KUBERNETES_gitCommit $(git rev-parse HEAD)
+echo STABLE_KUBERNETES_gitMajor $KUBE_MAJOR
+echo STABLE_KUBERNETES_gitMinor $KUBE_MINOR
+if git_status=$(git status --porcelain 2>/dev/null) && [[ -z ${git_status} ]]; then
+  echo STABLE_KUBERNETES_gitTreeState clean
+else
+  echo STABLE_KUBERNETES_gitTreeState dirty
+fi
+echo STABLE_KUBERNETES_gitVersion $(kube_ver .)-hscloud-$(rev .)
diff --git a/third_party/go/kubernetes/version.bzl b/third_party/go/kubernetes/version.bzl
index 5cfb241..65bf523 100644
--- a/third_party/go/kubernetes/version.bzl
+++ b/third_party/go/kubernetes/version.bzl
@@ -1,3 +1,6 @@
+# Compatibility for version_x_defs from k8s.io/component-base & co.
+# This makes all the defs be autopopulated from //bzl:workspace-status.sh.
+
 def version_x_defs():
     stamp_pkgs = [
         "k8s.io/component-base/version",
@@ -19,5 +22,5 @@
     x_defs = {}
     for pkg in stamp_pkgs:
         for var in stamp_vars:
-            x_defs["%s.%s" % (pkg, var)] = "{%s}" % var
+            x_defs["%s.%s" % (pkg, var)] = "{STABLE_KUBERNETES_%s}" % var
     return x_defs