| ... | ... |
@@ -48,7 +48,8 @@ func main() {
|
| 48 | 48 |
Use: "version", |
| 49 | 49 |
Short: "Display version", |
| 50 | 50 |
Run: func(c *cobra.Command, args []string) {
|
| 51 |
- major, minor, git := version.Get() |
|
| 51 |
+ info := version.Get() |
|
| 52 |
+ major, minor, git := info.Major, info.Minor, info.GitCommit |
|
| 52 | 53 |
fmt.Printf("openshift version %s.%s, build %s\n", major, minor, git)
|
| 53 | 54 |
fmt.Printf("kubernetes %v\n", kubeversion.Get())
|
| 54 | 55 |
}, |
| 55 | 56 |
deleted file mode 100755 |
| ... | ... |
@@ -1,11 +0,0 @@ |
| 1 |
-#!/bin/bash |
|
| 2 |
- |
|
| 3 |
-$(dirname $0)/../third_party/src/github.com/GoogleCloudPlatform/kubernetes/hack/version-gen.sh |
|
| 4 |
- |
|
| 5 |
-# TODO: when we start making tags, switch to git describe? |
|
| 6 |
-desc=$(git rev-list --abbrev-commit --max-count=1 HEAD) |
|
| 7 |
-tab=$'\t' |
|
| 8 |
-script="6s/.*/${tab}commitFromGit = \`${desc}\`/"
|
|
| 9 |
-infile="$(dirname $0)/../pkg/version/template.go" |
|
| 10 |
-outfile="$(dirname $0)/../pkg/version/autogenerated.go" |
|
| 11 |
-sed "${script}" "${infile}" > "${outfile}"
|
| ... | ... |
@@ -1,5 +1,53 @@ |
| 1 |
+/* |
|
| 2 |
+Copyright 2014 Google Inc. All rights reserved. |
|
| 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 |
+ |
|
| 1 | 17 |
package version |
| 2 | 18 |
|
| 3 |
-func Get() (major, minor, gitCommit string) {
|
|
| 4 |
- return "0", "1", commitFromGit |
|
| 19 |
+import ( |
|
| 20 |
+ "fmt" |
|
| 21 |
+) |
|
| 22 |
+ |
|
| 23 |
+// commitFromGit is a constant representing the source version that |
|
| 24 |
+// generated this build. It should be set during build via -ldflags. |
|
| 25 |
+var commitFromGit string |
|
| 26 |
+ |
|
| 27 |
+// Info contains versioning information. |
|
| 28 |
+// TODO: Add []string of api versions supported? It's still unclear |
|
| 29 |
+// how we'll want to distribute that information. |
|
| 30 |
+type Info struct {
|
|
| 31 |
+ Major string `json:"major" yaml:"major"` |
|
| 32 |
+ Minor string `json:"minor" yaml:"minor"` |
|
| 33 |
+ GitCommit string `json:"gitCommit" yaml:"gitCommit"` |
|
| 34 |
+} |
|
| 35 |
+ |
|
| 36 |
+// Get returns the overall codebase version. It's for detecting |
|
| 37 |
+// what code a binary was built from. |
|
| 38 |
+func Get() Info {
|
|
| 39 |
+ return Info{
|
|
| 40 |
+ Major: "0", |
|
| 41 |
+ Minor: "1", |
|
| 42 |
+ GitCommit: commitFromGit, |
|
| 43 |
+ } |
|
| 44 |
+} |
|
| 45 |
+ |
|
| 46 |
+// String returns info as a human-friendly version string. |
|
| 47 |
+func (info Info) String() string {
|
|
| 48 |
+ commit := info.GitCommit |
|
| 49 |
+ if commit == "" {
|
|
| 50 |
+ commit = "(unknown)" |
|
| 51 |
+ } |
|
| 52 |
+ return fmt.Sprintf("version %s.%s, build %s", info.Major, info.Minor, commit)
|
|
| 5 | 53 |
} |