Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Forcing a kubernetes version during build
Chuck Ha
Chuck Ha

Posted on

     

Forcing a kubernetes version during build

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.
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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"}
Enter fullscreen modeExit fullscreen mode

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
Enter fullscreen modeExit fullscreen mode

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"}
Enter fullscreen modeExit fullscreen mode

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

dev
  • Joined

More fromChuck Ha

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp