Repository: kubernetes-sigs/azurefile-csi-driver
Pull request #445 (2020-09-29 08:29:08)

chore: field name refactor
<!--  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 cleanup

**What this PR does / why we need it**:
chore: field name refactor

**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**:
```
none
```


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/445#" 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":[]} -->
k8s-ci-robot: @andyzhangx: The following test **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-azurefile-csi-driver-e2e-vmss | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e-vmss/1310859144164544512) | `/test pull-azurefile-csi-driver-e2e-vmss`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=azurefile-csi-driver&pr=445). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Aandyzhangx). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/azurefile-csi-driver/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @andyzhangx: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-azurefile-csi-driver-e2e-vmss | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e-vmss/1310859144164544512) | `/test pull-azurefile-csi-driver-e2e-vmss`
pull-azurefile-csi-driver-e2e | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e/1310859144151961600) | `/test pull-azurefile-csi-driver-e2e`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=azurefile-csi-driver&pr=445). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Aandyzhangx). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/azurefile-csi-driver/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->
k8s-ci-robot: @andyzhangx: The following tests **failed**, say `/retest` to rerun all failed tests:

Test name | Commit | Details | Rerun command
--- | --- | --- | ---
pull-azurefile-csi-driver-e2e-vmss | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e-vmss/1310859144164544512) | `/test pull-azurefile-csi-driver-e2e-vmss`
pull-azurefile-csi-driver-e2e | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e/1310859144151961600) | `/test pull-azurefile-csi-driver-e2e`
pull-azurefile-csi-driver-e2e-windows | d04d516c6be8b7de2bed7868f391debef60f1e07 | [link](https://prow.k8s.io/view/gs/kubernetes-jenkins/pr-logs/pull/kubernetes-sigs_azurefile-csi-driver/445/pull-azurefile-csi-driver-e2e-windows/1310859144198098944) | `/test pull-azurefile-csi-driver-e2e-windows`

[Full PR test history](https://prow.k8s.io/pr-history?org=kubernetes-sigs&repo=azurefile-csi-driver&pr=445). [Your PR dashboard](https://prow.k8s.io/pr?query=is%3Apr%20state%3Aopen%20author%3Aandyzhangx). Please help us cut down on flakes by [linking to](https://git.k8s.io/community/contributors/devel/sig-testing/flaky-tests.md#filing-issues-for-flaky-tests) an [open issue](https://github.com/kubernetes-sigs/azurefile-csi-driver/issues?q=is:issue+is:open) when you hit one in your PR.

<details>

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md).  If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository. I understand the commands that are listed [here](https://go.k8s.io/bot-commands).
</details>
<!-- test report -->

Patch:
diff --git a/Makefile b/Makefile
index e1f83978e..b0601944d 100755
--- a/Makefile
+++ b/Makefile
@@ -158,4 +158,6 @@ create-example-deployment:
 	kubectl apply -f deploy/example/storageclass-azurefile-csi.yaml
 	kubectl apply -f deploy/example/deployment.yaml
 	kubectl apply -f deploy/example/daemonset.yaml
-	kubectl apply -f deploy/example/statefulset.yaml
\ No newline at end of file
+	kubectl apply -f deploy/example/statefulset.yaml
+	kubectl apply -f deploy/example/windows/deployment.yaml
+	kubectl apply -f deploy/example/windows/statefulset.yaml
\ No newline at end of file
diff --git a/deploy/example/windows/deployment.yaml b/deploy/example/windows/deployment.yaml
index bc6f54c9c..8cb6675d2 100644
--- a/deploy/example/windows/deployment.yaml
+++ b/deploy/example/windows/deployment.yaml
@@ -14,7 +14,7 @@ spec:
 apiVersion: apps/v1
 kind: Deployment
 metadata:
-  name: busybox-azurefile
+  name: busybox-azurefile-win
   labels:
     app: busybox
 spec:
diff --git a/deploy/example/windows/statefulset.yaml b/deploy/example/windows/statefulset.yaml
index d6cd92a8a..3da7cf8a2 100644
--- a/deploy/example/windows/statefulset.yaml
+++ b/deploy/example/windows/statefulset.yaml
@@ -2,11 +2,11 @@
 apiVersion: apps/v1
 kind: StatefulSet
 metadata:
-  name: busybox-azurefile
+  name: busybox-azurefile-win
   labels:
     app: busybox
 spec:
-  serviceName: busybox-azurefile
+  serviceName: busybox-azurefile-win
   replicas: 1
   template:
     metadata:
diff --git a/pkg/azurefile/azurefile.go b/pkg/azurefile/azurefile.go
index a3f92324c..ea5bfffac 100644
--- a/pkg/azurefile/azurefile.go
+++ b/pkg/azurefile/azurefile.go
@@ -75,6 +75,11 @@ const (
 	fsTypeField              = "fstype"
 	protocolField            = "protocol"
 	tagsField                = "tags"
+	storageAccountField      = "storageaccount"
+	storageAccountTypeField  = "storageaccounttype"
+	skuNameField             = "skuname"
+	resourceGroupField       = "resourcegroup"
+	locationField            = "location"
 	secretNamespaceField     = "secretnamespace"
 	storeAccountKeyField     = "storeaccountkey"
 	storeAccountKeyFalse     = "false"
diff --git a/pkg/azurefile/controllerserver.go b/pkg/azurefile/controllerserver.go
index 1d3359194..aa5285696 100644
--- a/pkg/azurefile/controllerserver.go
+++ b/pkg/azurefile/controllerserver.go
@@ -76,15 +76,15 @@ func (d *Driver) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest)
 	// the values to the cloud provider.
 	for k, v := range parameters {
 		switch strings.ToLower(k) {
-		case "skuname":
+		case skuNameField:
 			sku = v
-		case "storageaccounttype":
+		case storageAccountTypeField:
 			sku = v
-		case "location":
+		case locationField:
 			location = v
-		case "storageaccount":
+		case storageAccountField:
 			account = v
-		case "resourcegroup":
+		case resourceGroupField:
 			resourceGroup = v
 		case shareNameField:
 			fileShareName = v


Test patch:
diff --git a/deploy/example/e2e_usage.md b/deploy/example/e2e_usage.md
index 9ac4f570e..d4334d46f 100644
--- a/deploy/example/e2e_usage.md
+++ b/deploy/example/e2e_usage.md
@@ -1,7 +1,7 @@
 ## CSI driver example
 > refer to [driver parameters](../../docs/driver-parameters.md) for more detailed usage
 
-### AzureFile Dynamic Provisioning
+### Dynamic Provisioning
 #### Option#1: create storage account by CSI driver
  - Create storage class
 ```console
diff --git a/pkg/azurefile/controllerserver_test.go b/pkg/azurefile/controllerserver_test.go
index c7b340777..d6eb7a92d 100644
--- a/pkg/azurefile/controllerserver_test.go
+++ b/pkg/azurefile/controllerserver_test.go
@@ -150,10 +150,10 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"location":           "loc",
-					"storageaccount":     "",
-					"resourcegroup":      "rg",
+					skuNameField:         "premium",
+					locationField:        "loc",
+					storageAccountField:  "",
+					resourceGroupField:   "rg",
 					shareNameField:       "",
 					diskNameField:        "diskname",
 					fsTypeField:          "",
@@ -218,17 +218,17 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"storageaccounttype": "stoacctype",
-					"location":           "loc",
-					"storageaccount":     "",
-					"resourcegroup":      "rg",
-					shareNameField:       "",
-					diskNameField:        "diskname",
-					fsTypeField:          "",
-					storeAccountKeyField: "storeaccountkey",
-					secretNamespaceField: "secretnamespace",
-					"defaultparam":       "defaultvalue",
+					skuNameField:            "premium",
+					storageAccountTypeField: "stoacctype",
+					locationField:           "loc",
+					storageAccountField:     "",
+					resourceGroupField:      "rg",
+					shareNameField:          "",
+					diskNameField:           "diskname",
+					fsTypeField:             "",
+					storeAccountKeyField:    "storeaccountkey",
+					secretNamespaceField:    "secretnamespace",
+					"defaultparam":          "defaultvalue",
 				}
 
 				req := &csi.CreateVolumeRequest{
@@ -343,17 +343,17 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"storageaccounttype": "stoacctype",
-					"location":           "loc",
-					"storageaccount":     "stoacc",
-					"resourcegroup":      "rg",
-					shareNameField:       "",
-					diskNameField:        "diskname",
-					fsTypeField:          "",
-					storeAccountKeyField: "storeaccountkey",
-					secretNamespaceField: "secretnamespace",
-					"defaultparam":       "defaultvalue",
+					skuNameField:            "premium",
+					storageAccountTypeField: "stoacctype",
+					locationField:           "loc",
+					storageAccountField:     "stoacc",
+					resourceGroupField:      "rg",
+					shareNameField:          "",
+					diskNameField:           "diskname",
+					fsTypeField:             "",
+					storeAccountKeyField:    "storeaccountkey",
+					secretNamespaceField:    "secretnamespace",
+					"defaultparam":          "defaultvalue",
 				}
 
 				req := &csi.CreateVolumeRequest{
@@ -417,17 +417,17 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"storageaccounttype": "stoacctype",
-					"location":           "loc",
-					"storageaccount":     "stoacc",
-					"resourcegroup":      "rg",
-					shareNameField:       "",
-					diskNameField:        "diskname",
-					fsTypeField:          "",
-					storeAccountKeyField: "storeaccountkey",
-					secretNamespaceField: "secretnamespace",
-					"defaultparam":       "defaultvalue",
+					skuNameField:            "premium",
+					storageAccountTypeField: "stoacctype",
+					locationField:           "loc",
+					storageAccountField:     "stoacc",
+					resourceGroupField:      "rg",
+					shareNameField:          "",
+					diskNameField:           "diskname",
+					fsTypeField:             "",
+					storeAccountKeyField:    "storeaccountkey",
+					secretNamespaceField:    "secretnamespace",
+					"defaultparam":          "defaultvalue",
 				}
 
 				req := &csi.CreateVolumeRequest{
@@ -489,15 +489,15 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"storageaccounttype": "stoacctype",
-					"location":           "loc",
-					"storageaccount":     "stoacc",
-					"resourcegroup":      "rg",
-					fsTypeField:          "ext4",
-					storeAccountKeyField: "storeaccountkey",
-					secretNamespaceField: "default",
-					"defaultparam":       "defaultvalue",
+					skuNameField:            "premium",
+					storageAccountTypeField: "stoacctype",
+					locationField:           "loc",
+					storageAccountField:     "stoacc",
+					resourceGroupField:      "rg",
+					fsTypeField:             "ext4",
+					storeAccountKeyField:    "storeaccountkey",
+					secretNamespaceField:    "default",
+					"defaultparam":          "defaultvalue",
 				}
 
 				req := &csi.CreateVolumeRequest{
@@ -576,17 +576,17 @@ func TestCreateVolume(t *testing.T) {
 				}
 
 				allParam := map[string]string{
-					"skuname":            "premium",
-					"storageaccounttype": "stoacctype",
-					"location":           "loc",
-					"storageaccount":     "stoacc",
-					"resourcegroup":      "rg",
-					shareNameField:       "",
-					diskNameField:        "diskname",
-					fsTypeField:          "",
-					storeAccountKeyField: "storeaccountkey",
-					secretNamespaceField: "default",
-					"defaultparam":       "defaultvalue",
+					skuNameField:            "premium",
+					storageAccountTypeField: "stoacctype",
+					locationField:           "loc",
+					storageAccountField:     "stoacc",
+					resourceGroupField:      "rg",
+					shareNameField:          "",
+					diskNameField:           "diskname",
+					fsTypeField:             "",
+					storeAccountKeyField:    "storeaccountkey",
+					secretNamespaceField:    "default",
+					"defaultparam":          "defaultvalue",
 				}
 
 				req := &csi.CreateVolumeRequest{
diff --git a/test/e2e/dynamic_provisioning_test.go b/test/e2e/dynamic_provisioning_test.go
index 899e79fa9..4b2a5419c 100644
--- a/test/e2e/dynamic_provisioning_test.go
+++ b/test/e2e/dynamic_provisioning_test.go
@@ -49,7 +49,7 @@ var _ = ginkgo.Describe("Dynamic Provisioning", func() {
 
 	ginkgo.BeforeEach(func() {
 		checkPodsRestart := testCmd{
-			command:  "sh",
+			command:  "bash",
 			args:     []string{"test/utils/check_driver_pods_restart.sh"},
 			startLog: "Check driver pods if restarts ...",
 			endLog:   "Check successfully",
diff --git a/test/e2e/pre_provisioning_test.go b/test/e2e/pre_provisioning_test.go
index 5b554e2dc..857d12eed 100644
--- a/test/e2e/pre_provisioning_test.go
+++ b/test/e2e/pre_provisioning_test.go
@@ -50,7 +50,7 @@ var _ = ginkgo.Describe("Pre-Provisioned", func() {
 
 	ginkgo.BeforeEach(func() {
 		checkPodsRestart := testCmd{
-			command:  "sh",
+			command:  "bash",
 			args:     []string{"test/utils/check_driver_pods_restart.sh"},
 			startLog: "Check driver pods if restarts ...",
 			endLog:   "Check successfully",
diff --git a/test/utils/check_driver_pods_restart.sh b/test/utils/check_driver_pods_restart.sh
index b06af8ce7..28c8b34cd 100644
--- a/test/utils/check_driver_pods_restart.sh
+++ b/test/utils/check_driver_pods_restart.sh
@@ -1,3 +1,5 @@
+#!/bin/bash
+
 # Copyright 2020 The Kubernetes Authors.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -12,20 +14,39 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-#!/bin/bash
-
 set -e
 
+function get_array() {
+    for value in ${1}
+    do
+        arr[${#arr[@]}]=$value
+    done
+    echo ${arr[*]}
+}
+
+NS=kube-system
+CONTAINER=azurefile
+
 echo "check the driver pods if restarts ..."
-restarts=$(kubectl get pods -n kube-system | grep azurefile | awk '{print $4}')
-for num in $restarts
-do
-    if [ "$num" -ne "0" ]
+original_pods=$(kubectl get pods -n kube-system | grep azurefile | awk '{print $1}')
+original_restarts=$(kubectl get pods -n kube-system | grep azurefile | awk '{print $4}')
+
+processed_pods=($(get_array "${original_pods[@]}"))
+processed_restarts=($(get_array "${original_restarts[@]}"))
+
+for ((i=0; i<${#processed_restarts[@]}; i++)); do
+    if [ "${processed_restarts[$i]}" -ne "0" ]
     then
         echo "there is a driver pod which has restarted"
-        # disable pods restart check temporarily since there is driver restart in MSI enabled cluster
-        # exit 3
+	    #disable pods restart check temporarily since there is driver restart in MSI enabled cluster
+        #exit 3
+        kubectl describe po ${processed_pods[$i]} -n kube-system
+        echo "======================================================================================"
+        echo "print previous azurefile cotnainer logs since there is a restart"
+        kubectl logs ${processed_pods[$i]} -c azurefile -p -n kube-system
+        echo "======================================================================================"
     fi
 done
+
 echo "no driver pods have restarted"
-echo "======================================================================================"
+echo "======================================================================================"
\ No newline at end of file