Skip to content

Commit

Permalink
Set gitTreeState, golang version, compiler and platform variables in …
Browse files Browse the repository at this point in the history
…version command
  • Loading branch information
soltysh committed Apr 24, 2019
1 parent c06ad8a commit 085f917
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions hack/lib/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function os::build::ldflags() {
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/pkg/version.minorFromGit" "${OS_GIT_MINOR}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/pkg/version.versionFromGit" "${OS_GIT_VERSION}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/pkg/version.commitFromGit" "${OS_GIT_COMMIT}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/pkg/version.gitTreeState" "${OS_GIT_TREE_STATE}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/pkg/version.buildDate" "${buildDate}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/vendor/k8s.io/kubernetes/pkg/version.gitMajor" "${KUBE_GIT_MAJOR}"))
ldflags+=($(os::build::ldflag "${OS_GO_PACKAGE}/vendor/k8s.io/kubernetes/pkg/version.gitMinor" "${KUBE_GIT_MINOR}"))
Expand Down
19 changes: 14 additions & 5 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package version

import (
"fmt"
"runtime"

"github.com/prometheus/client_golang/prometheus"

"k8s.io/apimachinery/pkg/version"
Expand All @@ -19,17 +22,23 @@ var (
minorFromGit string
// build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
buildDate string
// state of git tree, either "clean" or "dirty"
gitTreeState string
)

// Get returns the overall codebase version. It's for detecting
// what code a binary was built from.
func Get() version.Info {
return version.Info{
Major: majorFromGit,
Minor: minorFromGit,
GitCommit: commitFromGit,
GitVersion: versionFromGit,
BuildDate: buildDate,
Major: majorFromGit,
Minor: minorFromGit,
GitCommit: commitFromGit,
GitVersion: versionFromGit,
GitTreeState: gitTreeState,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

Expand Down

0 comments on commit 085f917

Please sign in to comment.