From a75f92aabc471c8eae6f1b2626b0d0e951324f4d Mon Sep 17 00:00:00 2001
From: Matthew Wong <mawong@redhat.com>
Date: Tue, 16 Oct 2018 15:09:26 -0400
Subject: [PATCH] Override mountOptions parameter with sc.mountOptions

---
 nfs/deploy/kubernetes/class.yaml | 4 ++--
 nfs/docs/usage.md                | 2 +-
 nfs/pkg/volume/provision.go      | 4 +++-
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/nfs/deploy/kubernetes/class.yaml b/nfs/deploy/kubernetes/class.yaml
index 6ea74350d..582d0f1c6 100644
--- a/nfs/deploy/kubernetes/class.yaml
+++ b/nfs/deploy/kubernetes/class.yaml
@@ -3,5 +3,5 @@ apiVersion: storage.k8s.io/v1
 metadata:
   name: example-nfs
 provisioner: example.com/nfs
-parameters:
-  mountOptions: "vers=4.1"  # TODO: reconcile with StorageClass.mountOptions
+mountOptions:
+  - vers=4.1
diff --git a/nfs/docs/usage.md b/nfs/docs/usage.md
index 4c50116f9..33a4f910e 100644
--- a/nfs/docs/usage.md
+++ b/nfs/docs/usage.md
@@ -7,7 +7,7 @@ Edit the `provisioner` field in `deploy/kubernetes/class.yaml` to be the provisi
 ### Parameters
 * `gid`: `"none"` or a [supplemental group](http://kubernetes.io/docs/user-guide/security-context/) like `"1001"`. NFS shares will be created with permissions such that pods running with the supplemental group can read & write to the share, but non-root pods without the supplemental group cannot. Pods running as root can read & write to shares regardless of the setting here, unless the `rootSquash` parameter is set true. If set to `"none"`, anybody root or non-root can write to the share. Default (if omitted) `"none"`.
 * `rootSquash`: `"true"` or `"false"`. Whether to squash root users by adding the NFS Ganesha root_id_squash or kernel root_squash option to each export. Default `"false"`.
-* `mountOptions`: a comma separated list of [mount options](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#mount-options) for every PV of this class to be mounted with. The list is inserted directly into every PV's mount options annotation/field without any validation. Default blank `""`.
+* **Deprecated. Use StorageClass.mountOptions instead.** `mountOptions`: a comma separated list of [mount options](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#mount-options) for every PV of this class to be mounted with. The list is inserted directly into every PV's mount options annotation/field without any validation. Default blank `""`.
 
 Name the `StorageClass` however you like; the name is how claims will request this class. Create the class.
  
diff --git a/nfs/pkg/volume/provision.go b/nfs/pkg/volume/provision.go
index ad4253340..26fef265c 100644
--- a/nfs/pkg/volume/provision.go
+++ b/nfs/pkg/volume/provision.go
@@ -210,7 +210,8 @@ func (p *nfsProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
 	if volume.supGroup != 0 {
 		annotations[VolumeGidAnnotationKey] = strconv.FormatUint(volume.supGroup, 10)
 	}
-	if volume.mountOptions != "" {
+	// Only use legacy mount options annotation if StorageClass.MountOptions is empty
+	if volume.mountOptions != "" && options.MountOptions == nil {
 		annotations[MountOptionAnnotation] = volume.mountOptions
 	}
 	annotations[annProvisionerID] = string(p.identity)
@@ -234,6 +235,7 @@ func (p *nfsProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
 					ReadOnly: false,
 				},
 			},
+			MountOptions: options.MountOptions,
 		},
 	}
 
-- 
GitLab