Skip to content

Commit

Permalink
fix -version option: print version (#367)
Browse files Browse the repository at this point in the history
What this PR does / why we need it:
this is a bug fix. if we using following command

$ ./tf_operator -version
it will not print any version information.

Which issue(s) this PR fixes (optional, in fixes #(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
NONE

Special notes for your reviewer:
NONE @jlewi

Release note:

NONE
  • Loading branch information
Gaojin CAO authored and jlewi committed Feb 8, 2018
1 parent 5557e87 commit 57567df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
11 changes: 5 additions & 6 deletions cmd/tf_operator/app/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"fmt"
"io/ioutil"
"os"
"runtime"
"time"

"github.com/ghodss/yaml"
Expand Down Expand Up @@ -56,12 +55,12 @@ func Run(opt *options.ServerOption) error {
namespace = metav1.NamespaceDefault
}

glog.Infof("tf_operator Version: %v", version.Version)
glog.Infof("Git SHA: %s", version.GitSHA)
glog.Infof("Go Version: %s", runtime.Version())
glog.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
// To help debugging, immediately log version
glog.Infof("%+v", version.Info())

// Check if the -version flag was passed and, if so, print the version and exit.
if opt.PrintVersion {
os.Exit(0)
version.PrintVersionAndExit()
}

config, err := k8sutil.GetClusterConfig()
Expand Down
26 changes: 15 additions & 11 deletions version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,28 @@
package version

import (
"os"
"fmt"
"runtime"

log "github.com/golang/glog"
"os"
)

var (
Version = "0.3.0+git"
GitSHA = "Not provided."
)

// PrintVersion print version info
func PrintVersion(shouldExit bool) {
log.Infof("tf_operator Version: %v", Version)
log.Infof("Git SHA: %s", GitSHA)
log.Infof("Go Version: %s", runtime.Version())
log.Infof("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH)
if shouldExit {
os.Exit(0)
func PrintVersionAndExit(){
for _, i := range Info(){
fmt.Printf("%v\n", i)
}
os.Exit(0)
}

func Info() []string{
return []string{
fmt.Sprintf("Version: %v", Version),
fmt.Sprintf("Git SHA: %s", GitSHA),
fmt.Sprintf("Go Version: %s", runtime.Version()),
fmt.Sprintf("Go OS/Arch: %s/%s", runtime.GOOS, runtime.GOARCH),
}
}

0 comments on commit 57567df

Please sign in to comment.