Add Version flag to cephcsi

This will be helpful if someone wants
to check the cephcsi version

output
```
docker run quay.io/cephcsi/cephcsi:v1.2.1 --version
Cephcsi Version: v1.2.1
Git Commit: 4b871366327d63e27fc1abfb699f0faaf0fc16b9
GoVersion: go1.12.5
Compiler: gc
Platform: linux/amd64
```

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2019-11-06 10:22:07 +05:30 committed by mergify[bot]
parent 8e117db80d
commit dfc3562e29
2 changed files with 14 additions and 0 deletions

View File

@ -18,8 +18,10 @@ package main
import ( import (
"flag" "flag"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"time" "time"
"github.com/ceph/ceph-csi/pkg/cephfs" "github.com/ceph/ceph-csi/pkg/cephfs"
@ -75,6 +77,8 @@ func init() {
flag.StringVar(&conf.HistogramOption, "histogramoption", "0.5,2,6", flag.StringVar(&conf.HistogramOption, "histogramoption", "0.5,2,6",
"Histogram option for grpc metrics, should be comma separated value, ex:= 0.5,2,6 where start=0.5 factor=2, count=6") "Histogram option for grpc metrics, should be comma separated value, ex:= 0.5,2,6 where start=0.5 factor=2, count=6")
flag.BoolVar(&conf.Version, "version", false, "Print cephcsi version information")
klog.InitFlags(nil) klog.InitFlags(nil)
if err := flag.Set("logtostderr", "true"); err != nil { if err := flag.Set("logtostderr", "true"); err != nil {
klog.Exitf("failed to set logtostderr flag: %v", err) klog.Exitf("failed to set logtostderr flag: %v", err)
@ -101,6 +105,15 @@ func getDriverName() string {
} }
func main() { func main() {
if conf.Version {
fmt.Println("Cephcsi Version:", util.DriverVersion)
fmt.Println("Git Commit:", util.GitCommit)
fmt.Println("Go Version:", runtime.Version())
fmt.Println("Compiler:", runtime.Compiler)
fmt.Printf("Platform: %s/%s\n", runtime.GOOS, runtime.GOARCH)
os.Exit(0)
}
klog.Infof("Driver version: %s and Git version: %s", util.DriverVersion, util.GitCommit) klog.Infof("Driver version: %s and Git version: %s", util.DriverVersion, util.GitCommit)
var cp util.CachePersister var cp util.CachePersister

View File

@ -97,6 +97,7 @@ type Config struct {
IsControllerServer bool // if set to true start provisoner server IsControllerServer bool // if set to true start provisoner server
IsNodeServer bool // if set to true start node server IsNodeServer bool // if set to true start node server
Version bool // cephcsi version
// rbd related flag // rbd related flag
Containerized bool // whether run as containerized Containerized bool // whether run as containerized