Skip to content

Commit ada94f0

Browse files
enhance(version): adds version flag in blobfuse csi file driver
This commit adds version flag in blobfuse csi file driver Signed-off-by: Ashish Ranjan <[email protected]>
1 parent 3d525e3 commit ada94f0

File tree

5 files changed

+93
-16
lines changed

5 files changed

+93
-16
lines changed

Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
PKG=github.com/csi-driver/blobfuse-csi-driver
1516
REGISTRY_NAME=andyzhangx
1617
IMAGE_NAME=blobfuse-csi
1718
IMAGE_VERSION=v0.1.0-alpha
1819
IMAGE_TAG=$(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_VERSION)
1920
IMAGE_TAG_LATEST=$(REGISTRY_NAME)/$(IMAGE_NAME):latest
20-
REV=$(shell git describe --long --tags --dirty)
21+
GIT_COMMIT?=$(shell git rev-parse HEAD)
22+
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
23+
LDFLAGS?="-X ${PKG}/pkg/blobfuse.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/blobfuse.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/blobfuse.buildDate=${BUILD_DATE} -s -w -extldflags '-static'"
2124

2225
.PHONY: all blobfuse blobfuse-container clean
2326

@@ -32,10 +35,10 @@ test-sanity:
3235
go test -v ./test/sanity/...
3336
blobfuse:
3437
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
35-
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/blobfuseplugin ./pkg/blobfuseplugin
38+
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -o _output/blobfuseplugin ./pkg/blobfuseplugin
3639
blobfuse-windows:
3740
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
38-
CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/blobfuseplugin.exe ./pkg/blobfuseplugin
41+
CGO_ENABLED=0 GOOS=windows go build -a -ldflags ${LDFLAGS} -o _output/blobfuseplugin.exe ./pkg/blobfuseplugin
3942
blobfuse-container: blobfuse
4043
docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/blobfuseplugin/Dockerfile .
4144
push: blobfuse-container

pkg/blobfuse/blobfuse.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
)
3030

3131
const (
32-
driverName = "blobfuse.csi.azure.com"
33-
vendorVersion = "v0.1.0-alpha"
32+
// DriverName holds the name of the csi-driver
33+
DriverName = "blobfuse.csi.azure.com"
3434
seperator = "#"
3535
volumeIDTemplate = "%s#%s#%s"
3636
fileMode = "file_mode"
@@ -51,23 +51,20 @@ type Driver struct {
5151
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
5252
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
5353
func NewDriver(nodeID string) *Driver {
54-
if nodeID == "" {
55-
klog.Fatalln("NodeID missing")
56-
return nil
57-
}
58-
5954
driver := Driver{}
60-
driver.Name = driverName
61-
driver.Version = vendorVersion
55+
driver.Name = DriverName
56+
driver.Version = driverVersion
6257
driver.NodeID = nodeID
63-
6458
return &driver
6559
}
6660

6761
// Run driver initialization
6862
func (d *Driver) Run(endpoint string) {
69-
klog.Infof("Driver: %v ", driverName)
70-
klog.Infof("Version: %s", vendorVersion)
63+
versionMeta, err := GetVersionYAML()
64+
if err != nil {
65+
klog.Fatalf("%v", err)
66+
}
67+
klog.Infof("\nDRIVER INFORMATION:\n-------------------\n%s\n\nStreaming logs below:", versionMeta)
7168

7269
cloud, err := GetCloudProvider()
7370
if err != nil {

pkg/blobfuse/version.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package blobfuse
18+
19+
import (
20+
"fmt"
21+
"runtime"
22+
"strings"
23+
24+
"sigs.k8s.io/yaml"
25+
)
26+
27+
// These are set during build time via -ldflags
28+
var (
29+
driverVersion = "N/A"
30+
gitCommit = "N/A"
31+
buildDate = "N/A"
32+
)
33+
34+
// VersionInfo holds the version information of the driver
35+
type VersionInfo struct {
36+
DriverName string `json:"Driver Name"`
37+
DriverVersion string `json:"Driver Version"`
38+
GitCommit string `json:"Git Commit"`
39+
BuildDate string `json:"Build Date"`
40+
GoVersion string `json:"Go Version"`
41+
Compiler string `json:"Compiler"`
42+
Platform string `json:"Platform"`
43+
}
44+
45+
// GetVersion returns the version information of the driver
46+
func GetVersion() VersionInfo {
47+
return VersionInfo{
48+
DriverName: DriverName,
49+
DriverVersion: driverVersion,
50+
GitCommit: gitCommit,
51+
BuildDate: buildDate,
52+
GoVersion: runtime.Version(),
53+
Compiler: runtime.Compiler,
54+
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
55+
}
56+
}
57+
58+
// GetVersionYAML returns the version information of the driver
59+
// in YAML format
60+
func GetVersionYAML() (string, error) {
61+
info := GetVersion()
62+
marshalled, err := yaml.Marshal(&info)
63+
if err != nil {
64+
return "", err
65+
}
66+
return strings.TrimSpace(string(marshalled)), nil
67+
}

pkg/blobfuseplugin/main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"flag"
21+
"fmt"
2122
"os"
2223

2324
"github.com/csi-driver/blobfuse-csi-driver/pkg/blobfuse"
@@ -31,12 +32,20 @@ func init() {
3132
var (
3233
endpoint = flag.String("endpoint", "unix://tmp/csi.sock", "CSI endpoint")
3334
nodeID = flag.String("nodeid", "", "node id")
35+
version = flag.Bool("version", false, "Print the version and exit.")
3436
)
3537

3638
func main() {
3739
klog.InitFlags(nil)
3840
flag.Parse()
39-
41+
if *version {
42+
info, err := blobfuse.GetVersionYAML()
43+
if err != nil {
44+
klog.Fatalln(err)
45+
}
46+
fmt.Println(info)
47+
os.Exit(0)
48+
}
4049
if *nodeID == "" {
4150
klog.Error("--nodeid is a required parameter")
4251
os.Exit(1)

0 commit comments

Comments
 (0)