Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flag for version information output #44

Merged
merged 2 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
IMAGE=amazon/aws-efs-csi-driver
VERSION=0.1.0

FLAG_COMMIT=-X github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.commitSha=`git log --pretty=format:'%H' -n 1`
FLAG_DRIVER=-X github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/driver.vendorVersion=${VERSION} -X github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.driver=${VERSION}
FLAG_ARCH=-X github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.arch=`uname -m`
djcass44 marked this conversation as resolved.
Show resolved Hide resolved
FLAG_OS=-X github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.os=`uname -r`
FLAG_DATE=-X 'github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.buildDate=`date -u '+%Y-%m-%d %H:%M:%S'`'
FLAG_GO_VERSION=-X 'github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info.goVersion=`go version`'

LDFLAGS=-ldflags "${FLAG_DRIVER} ${FLAG_COMMIT} ${FLAG_ARCH} ${FLAG_OS} ${FLAG_DATE} ${FLAG_GO_VERSION}"

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

.PHONY: verify
verify:
Expand Down
8 changes: 8 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,24 @@ package main

import (
"flag"
"github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/info"

"github.com/kubernetes-sigs/aws-efs-csi-driver/pkg/driver"
"k8s.io/klog"
)

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

klog.InitFlags(nil)
flag.Parse()

if *version {
info.Print()
return
}

drv := driver.NewDriver(*endpoint)
if err := drv.Run(); err != nil {
klog.Fatalln(err)
Expand Down
37 changes: 37 additions & 0 deletions pkg/info/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package info
djcass44 marked this conversation as resolved.
Show resolved Hide resolved

import (
"encoding/json"
"fmt"
)

var (
commitSha = ""
driver = ""
goVersion = ""
buildDate = ""
os = ""
arch = ""
)

type Version struct {
Commit string `json:"commit"`
Driver string `json:"driver"`
GoVersion string `json:"goVersion"`
BuildDate string `json:"buildDate"`
Os string `json:"os"`
Arch string `json:"arch"`
}

func Print() {
ver := &Version{
Commit: commitSha,
Driver: driver,
GoVersion: goVersion,
BuildDate: buildDate,
Os: os,
Arch: arch,
}
ver2, _ := json.Marshal(ver)
fmt.Println(string(ver2))
}
djcass44 marked this conversation as resolved.
Show resolved Hide resolved