Add additional ldflags constants for Kubernetes versioning

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>
This commit is contained in:
Filipe Brandenburger
2014-08-27 09:08:04 -07:00
parent 7785f14b32
commit b777eb19e2
3 changed files with 54 additions and 11 deletions

View File

@@ -20,26 +20,28 @@ import (
"fmt"
)
// commitFromGit is a constant representing the source version that
// generated this build. It should be set during build via -ldflags.
var commitFromGit string
// Info contains versioning information.
// TODO: Add []string of api versions supported? It's still unclear
// how we'll want to distribute that information.
type Info struct {
Major string `json:"major" yaml:"major"`
Minor string `json:"minor" yaml:"minor"`
GitCommit string `json:"gitCommit" yaml:"gitCommit"`
Major string `json:"major" yaml:"major"`
Minor string `json:"minor" yaml:"minor"`
GitVersion string `json:"gitVersion" yaml:"gitVersion"`
GitCommit string `json:"gitCommit" yaml:"gitCommit"`
GitTreeState string `json:"gitTreeState" yaml:"gitTreeState"`
}
// Get returns the overall codebase version. It's for detecting
// what code a binary was built from.
func Get() Info {
// These variables typically come from -ldflags settings and in
// their absence fallback to the settings in pkg/version/base.go
return Info{
Major: "0",
Minor: "1",
GitCommit: commitFromGit,
Major: gitMajor,
Minor: gitMinor,
GitVersion: gitVersion,
GitCommit: gitCommit,
GitTreeState: gitTreeState,
}
}