
Date: November, 19th, 2018Kubernetes: https://github.com/kubernetes/kubernetes/commit/8848740f6d0f84c2c4c5165736e12425551a6207The current release is just before v1.13.0 so the newest tag is v1.14.0-alpha.
When aKubernetes binary is built withbazel it will set a default version on the binary for you. That is, when you runkubectl version
the version is populated automatically.
However, sometimes you want a custom version, probably for testing purposes. For example, if you are testingkubeadm's upgrade feature it helps to force a version to avoid some annoying behavior.
Bazel calculates this version through a script that is defined by a flag called--workspace_status_command
. That argument is specified in the.bazelrc
file.
print-workspace-status.sh
callsa bash function and prints some version information in a very specific format that bazel uses.
If you want to customize this, you have two options.
Option 1 You can define a custom--workspace_status_command
script that generates these versions with whatever versions you want
Create this file asworkspace-status.sh
and make it executablechmod +x workspace-status.sh
.
#!/usr/bin/env bashcat<<EOFgitCommit$(git rev-parse"HEAD^{commit}")gitTreeState cleangitVersion v2.0.0gitMajor 2gitMinor 0buildDate$(date\${SOURCE_DATE_EPOCH:+"--date=@${SOURCE_DATE_EPOCH}"}\-u +'%Y-%m-%dT%H:%M:%SZ')EOF
Now runbazel build --workspace_status_command=./workspace-status.sh //cmd/kubeadm
and you can see it works when you runkubeadm version
and get this output:
kubeadm versionkubeadm version: &version.Info{Major:"2", Minor:"0", GitVersion:"v2.0.0", GitCommit:"679d4397cfdb386ebd3ae4bcb9972273b3f75ca3", GitTreeState:"clean", BuildDate:"2018-11-19T20:43:30Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"darwin/amd64"}
Option 2
You can define an environment variable,KUBE_GIT_VERSION_FILE
, that defines a file in which the versions are already specified.
Create a file calledversion.txt
and put the following contents in it:
KUBE_GIT_COMMIT=abcdKUBE_GIT_TREE_STATE="clean"KUBE_GIT_VERSION="v2.0.3"KUBE_GIT_MAJOR=2KUBE_GIT_MINOR=0
Now get that file as an environment variable withexport KUBE_GIT_VERSION_FILE=version.txt
and runbazel build //cmd/kubeadm
.
Then when you runkubeadm version
you will see:
$ kubeadm versionkubeadm version: &version.Info{Major:"2", Minor:"0", GitVersion:"v2.0.3", GitCommit:"abcd", GitTreeState:"clean", BuildDate:"2018-11-19T20:58:25Z", GoVersion:"go1.11.2", Compiler:"gc", Platform:"darwin/amd64"}
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse