Repository: kubernetes-csi/csi-driver-smb
Pull request #317 (2021-06-30 12:23:37)

fix: incorrect display driverName when using alternative driver name
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/release.md#issue-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
6. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

**What type of PR is this?**
/kind bug

**What this PR does / why we need it**:
fix: incorrect display driverName when using alternative driver name

**Which issue(s) this PR fixes**:
<!-- 
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Requirements**:
- [ ] uses [conventional commit messages](https://www.conventionalcommits.org/)
  <!-- Common commit types:
        build: Build 🏭
        chore: Maintenance 🔧
        ci: Continuous Integration 💜
        docs: Documentation 📘
        feat: Features 🌈
        fix: Bug Fixes 🐞
        perf: Performance Improvements 🚀
        refactor: Code Refactoring 💎
        revert: Revert Change ◀️
        style: Code Style 🎶
        security: Security Fix 🛡️
        test: Testing 💚 -->
- [ ] includes documentation
- [ ] adds unit tests
- [ ] tested upgrade from previous version

**Special notes for your reviewer**:


**Release note**:
```
fix: incorrect display driverName when using alternative driver name
```



Patch:
diff --git a/pkg/smb/smb.go b/pkg/smb/smb.go
index f659d3ed9..ca87e818a 100644
--- a/pkg/smb/smb.go
+++ b/pkg/smb/smb.go
@@ -56,7 +56,7 @@ func NewDriver(nodeID, driverName string) *Driver {
 
 // Run driver initialization
 func (d *Driver) Run(endpoint, kubeconfig string, testMode bool) {
-	versionMeta, err := GetVersionYAML()
+	versionMeta, err := GetVersionYAML(d.Name)
 	if err != nil {
 		klog.Fatalf("%v", err)
 	}
diff --git a/pkg/smb/version.go b/pkg/smb/version.go
index dbd75cd97..a4a264e0b 100644
--- a/pkg/smb/version.go
+++ b/pkg/smb/version.go
@@ -43,9 +43,14 @@ type VersionInfo struct {
 }
 
 // GetVersion returns the version information of the driver
-func GetVersion() VersionInfo {
+func GetVersion(driverName string) VersionInfo {
+	displayDriverName := DefaultDriverName
+	if driverName != "" {
+		displayDriverName = driverName
+	}
+
 	return VersionInfo{
-		DriverName:    DefaultDriverName,
+		DriverName:    displayDriverName,
 		DriverVersion: driverVersion,
 		GitCommit:     gitCommit,
 		BuildDate:     buildDate,
@@ -57,8 +62,8 @@ func GetVersion() VersionInfo {
 
 // GetVersionYAML returns the version information of the driver
 // in YAML format
-func GetVersionYAML() (string, error) {
-	info := GetVersion()
+func GetVersionYAML(driverName string) (string, error) {
+	info := GetVersion(driverName)
 	marshalled, err := yaml.Marshal(&info)
 	if err != nil {
 		return "", err
diff --git a/pkg/smbplugin/main.go b/pkg/smbplugin/main.go
index 2d48b3875..4a016ad60 100644
--- a/pkg/smbplugin/main.go
+++ b/pkg/smbplugin/main.go
@@ -47,7 +47,7 @@ var (
 func main() {
 	flag.Parse()
 	if *version {
-		info, err := smb.GetVersionYAML()
+		info, err := smb.GetVersionYAML(*driverName)
 		if err != nil {
 			klog.Fatalln(err)
 		}


Test patch:
diff --git a/pkg/smb/version_test.go b/pkg/smb/version_test.go
index 5a9aed4d9..8c3802c9b 100644
--- a/pkg/smb/version_test.go
+++ b/pkg/smb/version_test.go
@@ -27,7 +27,7 @@ import (
 )
 
 func TestGetVersion(t *testing.T) {
-	version := GetVersion()
+	version := GetVersion("")
 
 	expected := VersionInfo{
 		DriverName:    DefaultDriverName,
@@ -46,11 +46,11 @@ func TestGetVersion(t *testing.T) {
 }
 
 func TestGetVersionYAML(t *testing.T) {
-	resp, err := GetVersionYAML()
+	resp, err := GetVersionYAML("")
 	if err != nil {
 		t.Fatalf("Unexpected error: %v", err)
 	}
-	versionInfo := GetVersion()
+	versionInfo := GetVersion("")
 	marshalled, _ := yaml.Marshal(&versionInfo)
 	expected := strings.TrimSpace(string(marshalled))