Skip to content

Commit

Permalink
Add version subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoshkin committed Dec 4, 2018
1 parent 9a17b67 commit c7b3689
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@

IMAGE=amazon/aws-ebs-csi-driver
VERSION=0.1.0-alpha
GIT_COMMIT?=$(shell git rev-parse HEAD)
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS?="-X github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver.driverVersion=${VERSION} -X github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver.gitCommit=${GIT_COMMIT} -X github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver.buildDate=${BUILD_DATE}"

.PHONY: aws-ebs-csi-driver
aws-ebs-csi-driver:
mkdir -p bin
CGO_ENABLED=0 GOOS=linux go build -ldflags "-X github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver.vendorVersion=${VERSION}" -o bin/aws-ebs-csi-driver ./cmd/
CGO_ENABLED=0 GOOS=linux go build -ldflags ${LDFLAGS} -o bin/aws-ebs-csi-driver ./cmd/

.PHONY: test
test:
Expand Down
16 changes: 15 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,30 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/golang/glog"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/driver"
)

func main() {
var endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI Endpoint")
var (
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI Endpoint")
version = flag.Bool("version", false, "Print the version and exit.")
)
flag.Parse()

if *version {
info, err := driver.GetVersionJSON()
if err != nil {
glog.Fatalln(err)
}
fmt.Println(info)
os.Exit(0)
}

cloud, err := cloud.NewCloud()
if err != nil {
glog.Fatalln(err)
Expand Down
5 changes: 0 additions & 5 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ const (
topologyKey = "topology." + driverName + "/zone"
)

var (
// vendorVersion is the version driver and is set during build
vendorVersion string
)

type Driver struct {
endpoint string
nodeID string
Expand Down
2 changes: 1 addition & 1 deletion pkg/driver/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoReques
glog.V(4).Infof("GetPluginInfo: called with args %+v", *req)
resp := &csi.GetPluginInfoResponse{
Name: driverName,
VendorVersion: vendorVersion,
VendorVersion: driverVersion,
}

return resp, nil
Expand Down
43 changes: 43 additions & 0 deletions pkg/driver/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package driver

import (
"encoding/json"
"fmt"
"runtime"
)

// These are set during build time via -ldflags
var (
driverVersion string
gitCommit string
buildDate string
)

type VersionInfo struct {
DriverVersion string `json:"driverVersion"`
GitCommit string `json:"gitCommit"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}

func GetVersion() VersionInfo {
return VersionInfo{
DriverVersion: driverVersion,
GitCommit: gitCommit,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}

func GetVersionJSON() (string, error) {
info := GetVersion()
marshalled, err := json.MarshalIndent(&info, "", " ")
if err != nil {
return "", err
}
return string(marshalled), nil
}

0 comments on commit c7b3689

Please sign in to comment.