Skip to content

Commit f595a08

Browse files
add version package
1 parent 0f62f83 commit f595a08

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

version/version.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
Copyright 2018 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package version
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
)
23+
24+
var (
25+
gitMajor string // major version, always numeric
26+
gitMinor string // minor version, numeric possibly followed by "+"
27+
gitVersion string // semantic version, derived by build scripts
28+
gitCommit string // sha1 from git, output of $(git rev-parse HEAD)
29+
gitReleaseCommit string // sha1 from git of the most recent tagged commit
30+
gitTreeState string // state of git tree, either "clean" or "dirty"
31+
buildDate string // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ')
32+
)
33+
34+
type Info struct {
35+
Major string `json:"major,omitempty"`
36+
Minor string `json:"minor,omitempty"`
37+
GitVersion string `json:"gitVersion,omitempty"`
38+
GitCommit string `json:"gitCommit,omitempty"`
39+
GitTreeState string `json:"gitTreeState,omitempty"`
40+
BuildDate string `json:"buildDate,omitempty"`
41+
GoVersion string `json:"goVersion,omitempty"`
42+
Compiler string `json:"compiler,omitempty"`
43+
Platform string `json:"platform,omitempty"`
44+
}
45+
46+
func Get() Info {
47+
return Info{
48+
Major: gitMajor,
49+
Minor: gitMinor,
50+
GitVersion: gitVersion,
51+
GitCommit: gitCommit,
52+
GitTreeState: gitTreeState,
53+
BuildDate: buildDate,
54+
GoVersion: runtime.Version(),
55+
Compiler: runtime.Compiler,
56+
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
57+
}
58+
}
59+
60+
// String returns info as a human-friendly version string.
61+
func (info Info) String() string {
62+
return info.GitVersion
63+
}

0 commit comments

Comments
 (0)