Skip to content

Commit 62925fc

Browse files
authored
Merge pull request #47 from ashishranjan738/version
enhance(version): Add version flag in azurefile plugin
2 parents 2016b32 + 30e53a3 commit 62925fc

File tree

5 files changed

+92
-14
lines changed

5 files changed

+92
-14
lines changed

Gopkg.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
PKG=github.com/kubernetes-sigs/azurefile-csi-driver
1516
REGISTRY_NAME=andyzhangx
17+
DRIVER_NAME=file.csi.azure.com
1618
IMAGE_NAME=azurefile-csi
1719
IMAGE_VERSION=v0.2.0-alpha
1820
IMAGE_TAG=$(REGISTRY_NAME)/$(IMAGE_NAME):$(IMAGE_VERSION)
1921
IMAGE_TAG_LATEST=$(REGISTRY_NAME)/$(IMAGE_NAME):latest
2022
REV=$(shell git describe --long --tags --dirty)
23+
GIT_COMMIT?=$(shell git rev-parse HEAD)
24+
BUILD_DATE?=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
25+
LDFLAGS?="-X ${PKG}/pkg/azurefile.driverVersion=${IMAGE_VERSION} -X ${PKG}/pkg/azurefile.gitCommit=${GIT_COMMIT} -X ${PKG}/pkg/azurefile.buildDate=${BUILD_DATE} -X ${PKG}/pkg/azurefile.driverName=${DRIVER_NAME} -extldflags '-static'"
2126

2227
.PHONY: all azurefile azurefile-container clean
2328

@@ -32,10 +37,10 @@ test-sanity:
3237
go test -v ./test/sanity/...
3338
azurefile:
3439
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
35-
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-X github.com/kubernetes-sigs/azurefile-csi-driver/pkg/azurefile.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/azurefileplugin ./pkg/azurefileplugin
40+
CGO_ENABLED=0 GOOS=linux go build -a -ldflags ${LDFLAGS} -o _output/azurefileplugin ./pkg/azurefileplugin
3641
azurefile-windows:
3742
if [ ! -d ./vendor ]; then dep ensure -vendor-only; fi
38-
CGO_ENABLED=0 GOOS=windows go build -a -ldflags '-X github.com/kubernetes-sigs/azurefile-csi-driver/pkg/azurefile.vendorVersion=$(IMAGE_VERSION) -extldflags "-static"' -o _output/azurefileplugin.exe ./pkg/azurefileplugin
43+
CGO_ENABLED=0 GOOS=windows go build -a -ldflags ${LDFLAGS} -o _output/azurefileplugin.exe ./pkg/azurefileplugin
3944
azurefile-container: azurefile
4045
docker build --no-cache -t $(IMAGE_TAG) -f ./pkg/azurefileplugin/Dockerfile .
4146
push: azurefile-container

pkg/azurefile/azurefile.go

+6-11
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import (
2929
)
3030

3131
const (
32-
driverName = "file.csi.azure.com"
33-
vendorVersion = "v0.2.0-alpha"
3432
seperator = "#"
3533
volumeIDTemplate = "%s#%s#%s"
3634
fileMode = "file_mode"
@@ -51,23 +49,20 @@ type Driver struct {
5149
// NewDriver Creates a NewCSIDriver object. Assumes vendor version is equal to driver version &
5250
// does not support optional driver plugin info manifest field. Refer to CSI spec for more details.
5351
func NewDriver(nodeID string) *Driver {
54-
if nodeID == "" {
55-
klog.Fatalln("NodeID missing")
56-
return nil
57-
}
58-
5952
driver := Driver{}
6053
driver.Name = driverName
61-
driver.Version = vendorVersion
54+
driver.Version = driverVersion
6255
driver.NodeID = nodeID
63-
6456
return &driver
6557
}
6658

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

7267
cloud, err := GetCloudProvider()
7368
if err != nil {

pkg/azurefile/version.go

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 azurefile
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+
driverName = "N/A"
33+
)
34+
35+
// VersionInfo holds the version information of the driver
36+
type VersionInfo struct {
37+
DriverName string `json:"Driver Name"`
38+
DriverVersion string `json:"Driver Version"`
39+
GitCommit string `json:"Git Commit"`
40+
BuildDate string `json:"Build Date"`
41+
GoVersion string `json:"Go Version"`
42+
Compiler string `json:"Compiler"`
43+
Platform string `json:"Platform"`
44+
}
45+
46+
// GetVersion returns the version information of the driver
47+
func GetVersion() VersionInfo {
48+
return VersionInfo{
49+
DriverName: driverName,
50+
DriverVersion: driverVersion,
51+
GitCommit: gitCommit,
52+
BuildDate: buildDate,
53+
GoVersion: runtime.Version(),
54+
Compiler: runtime.Compiler,
55+
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
56+
}
57+
}
58+
59+
// GetVersionYAML returns the version information of the driver
60+
// in YAML format
61+
func GetVersionYAML() (string, error) {
62+
info := GetVersion()
63+
marshalled, err := yaml.Marshal(&info)
64+
if err != nil {
65+
return "", err
66+
}
67+
return strings.TrimSpace(string(marshalled)), nil
68+
}

pkg/azurefileplugin/main.go

+10-1
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/kubernetes-sigs/azurefile-csi-driver/pkg/azurefile"
@@ -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 := azurefile.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)