Now it is possible to push these variables through ldflags:
- gitMajor
- gitMinor
- gitVersion (from latest annotated tag, output of git describe)
- gitCommit (renamed commitFromGit, intended to have the full sha1)
- gitTreeState (either "clean" or "dirty")
These are spawned into its separate source file, since they are meant to
be updated separately when a new version is released.
Also use the notation vX.Y+ for when git information is not present.
(This is consistent with the kernel build, e.g. Linux 3.15+ means its
version is >= 3.15 and < 3.16.)
v2: Added comments to the individual fields in pkg/version/base.go
Tested:
- Built it and checked the -version output:
$ hack/build-go.sh
$ output/go/bin/kubelet -version
Kubernetes version 0.1+, build c328679ef8aa
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
because it causes a runtime panic if a binary which has its own implementation
of "-version" flag tries to reuse a package library which indirectly depend on
"pkg/version".
e.g. If such an user-defined binary tires to link "pkg/api" or "pkg/client",
the binary fails with a runtime panic "flag redefined: version".
Detect whether the tree is dirty and append a "-dirty" indication to the
git commit (common practice with other repos, e.g. kernel, docker.)
Properly handle the case where a git tree is not found (e.g. building
from archive.)
In the sed expression, look for the variable to be updated
(commitFromGit) instead of hardcoding a line number.
Tested:
- Built from a dirty tree:
$ output/go/bin/kubelet -version
Kubernetes version 0.1, build 2d784c684c75-dirty
- Built from a clean tree:
$ output/go/bin/kubelet -version
Kubernetes version 0.1, build 505f23a31172
- Built from an archive:
$ hack/build-go.sh
WARNING: unable to find git commit, falling back to commitFromGit = `(none)`
$ output/go/bin/kubelet -version
Kubernetes version 0.1, build (none)
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Tested: Passed -version argument to kubelet (and all other binaries):
$ output/go/bin/kubecfg -version
Kubernetes version 0.1, build 6454a541fd56
Signed-off-by: Filipe Brandenburger <filbranden@google.com>