Repository: kubernetes-sigs/azurefile-csi-driver
Pull request #214 (2020-03-20 05:13:12)

fix: volumeid compatibility issue
<!--  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**:
PR(https://github.com/kubernetes-sigs/azurefile-csi-driver/pull/189) introduced a volumeid compatibility issue, this PR is to fix that issue.

**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 #

**Special notes for your reviewer**:
cc @aelmanaa

**Release note**:
```
fix: volumeid compatibility issue
```


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/azurefile-csi-driver/pull/214#" title="Author self-approved">andyzhangx</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fazurefile-csi-driver).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/azurefile-csi-driver/blob/master/OWNERS)~~ [andyzhangx]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go
index 7d6cc4b7a..64d098122 100644
--- a/pkg/azurefile/azurefile.go
+++ b/pkg/azurefile/azurefile.go
@@ -189,10 +189,14 @@ func (d *Driver) getFileSvcClient(accountName, accountKey string) (*azs.FileServ
 // output: rg, f5713de20cde511e8ba4900, pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41, diskname.vhd
 func getFileShareInfo(id string) (string, string, string, string, error) {
 	segments := strings.Split(id, separator)
-	if len(segments) < 4 {
-		return "", "", "", "", fmt.Errorf("error parsing volume id: %q, should at least contain three #", id)
+	if len(segments) < 3 {
+		return "", "", "", "", fmt.Errorf("error parsing volume id: %q, should at least contain two #", id)
 	}
-	return segments[0], segments[1], segments[2], segments[3], nil
+	var diskName string
+	if len(segments) > 3 {
+		diskName = segments[3]
+	}
+	return segments[0], segments[1], segments[2], diskName, nil
 }
 
 // check whether mountOptions contains file_mode, dir_mode, vers, if not, append default mode


Test patch:
diff --git a/pkg/azurefile/azurefile_test.go b/pkg/azurefile/azurefile_test.go
index 59036cb3c..4c939f314 100644
--- a/pkg/azurefile/azurefile_test.go
+++ b/pkg/azurefile/azurefile_test.go
@@ -88,13 +88,21 @@ func TestGetFileShareInfo(t *testing.T) {
 			diskName:          "diskname.vhd",
 			expectedError:     nil,
 		},
+		{
+			id:                "rg#f5713de20cde511e8ba4900#pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
+			resourceGroupName: "rg",
+			accountName:       "f5713de20cde511e8ba4900",
+			fileShareName:     "pvc-file-dynamic-17e43f84-f474-11e8-acd0-000d3a00df41",
+			diskName:          "",
+			expectedError:     nil,
+		},
 		{
 			id:                "rg#f5713de20cde511e8ba4900",
 			resourceGroupName: "",
 			accountName:       "",
 			fileShareName:     "",
 			diskName:          "",
-			expectedError:     fmt.Errorf("error parsing volume id: \"rg#f5713de20cde511e8ba4900\", should at least contain three #"),
+			expectedError:     fmt.Errorf("error parsing volume id: \"rg#f5713de20cde511e8ba4900\", should at least contain two #"),
 		},
 		{
 			id:                "rg",
@@ -102,7 +110,7 @@ func TestGetFileShareInfo(t *testing.T) {
 			accountName:       "",
 			fileShareName:     "",
 			diskName:          "",
-			expectedError:     fmt.Errorf("error parsing volume id: \"rg\", should at least contain three #"),
+			expectedError:     fmt.Errorf("error parsing volume id: \"rg\", should at least contain two #"),
 		},
 		{
 			id:                "",
@@ -110,7 +118,7 @@ func TestGetFileShareInfo(t *testing.T) {
 			accountName:       "",
 			fileShareName:     "",
 			diskName:          "",
-			expectedError:     fmt.Errorf("error parsing volume id: \"\", should at least contain three #"),
+			expectedError:     fmt.Errorf("error parsing volume id: \"\", should at least contain two #"),
 		},
 	}