diff --git a/cmd/tf_operator/app/server.go b/cmd/tf_operator/app/server.go index 8b7f9e2094..60a6413bc7 100644 --- a/cmd/tf_operator/app/server.go +++ b/cmd/tf_operator/app/server.go @@ -18,7 +18,6 @@ import ( "fmt" "io/ioutil" "os" - "runtime" "time" "github.com/ghodss/yaml" @@ -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() diff --git a/version/version.go b/version/version.go index d0d5fb6a6e..3a43f62e70 100644 --- a/version/version.go +++ b/version/version.go @@ -13,10 +13,9 @@ package version import ( - "os" + "fmt" "runtime" - - log "github.com/golang/glog" + "os" ) var ( @@ -24,13 +23,18 @@ var ( 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), } }