Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#490 from jiaxuanzhou/version
Browse files Browse the repository at this point in the history
Add version options for kube-batch
  • Loading branch information
k8s-ci-robot authored Dec 5, 2018
2 parents 3d9b393 + 92e8f36 commit e18a56b
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
BIN_DIR=_output/bin
RELEASE_VER=v0.2
REPO_PATH=github.com/kubernetes-sigs/kube-batch
GitSHA=`git rev-parse HEAD`
Date=`date "+%Y-%m-%d %H:%M:%S"`

kube-batch: init
go build -o ${BIN_DIR}/kube-batch ./cmd/kube-batch/
go build -ldflags " \
-X '${REPO_PATH}/pkg/version.GitSHA=${GitSHA}' \
-X '${REPO_PATH}/pkg/version.Built=${Date}' \
-X '${REPO_PATH}/pkg/version.Version=${RELEASE_VER}'" \
-o _output/bin/kube-batch ./cmd/kube-batch

verify: generate-code
hack/verify-gofmt.sh
Expand Down
52 changes: 52 additions & 0 deletions pkg/version/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package version

import (
"fmt"
"os"
"runtime"
)

var (
// Version shows the version of kube-batch.
Version = "Not provided."
// GitSHA shoows the git commit id of kube-batch.
GitSHA = "Not provided."
// Built shows the built time of the binary.
Built = "Not provided."
)

// PrintVersionAndExit prints versions from the array returned by Info() and exit
func PrintVersionAndExit(apiVersion string) {
for _, i := range Info(apiVersion) {
fmt.Printf("%v\n", i)
}
os.Exit(0)
}

// Info returns an array of various service versions
func Info(apiVersion string) []string {
return []string{
fmt.Sprintf("API Version: %s", apiVersion),
fmt.Sprintf("Version: %s", Version),
fmt.Sprintf("Git SHA: %s", GitSHA),
fmt.Sprintf("Built At: %s", Built),
fmt.Sprintf("Go Version: %s", runtime.Version()),
fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH),
}
}

0 comments on commit e18a56b

Please sign in to comment.