From be14b936d18d9f733bdb046675c272cdc5ea9778 Mon Sep 17 00:00:00 2001 From: Ben Swartzlander Date: Thu, 11 Oct 2018 12:38:04 -0400 Subject: [PATCH] Add mount options Copy mount options from the storage class to the PV spec. --- pkg/controller/controller.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index b1e02340ec..cab02a3b6d 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -107,9 +107,6 @@ const ( var _ controller.Provisioner = &csiProvisioner{} var ( - accessType = &csi.VolumeCapability_Mount{ - Mount: &csi.VolumeCapability_MountVolume{}, - } // Each provisioner have a identify string to distinguish with others. This // identify string will be added in PV annoations under this key. provisionerIDKey = "storage.kubernetes.io/csiProvisionerIdentity" @@ -361,9 +358,27 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis return nil, err } + fsType := "" + for k, v := range options.Parameters { + switch strings.ToLower(k) { + case "fstype": + fsType = v + } + } + if len(fsType) == 0 { + fsType = defaultFSType + } + capacity := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)] volSizeBytes := capacity.Value() + accessType := &csi.VolumeCapability_Mount{ + Mount: &csi.VolumeCapability_MountVolume{ + FsType: fsType, + MountFlags: options.MountOptions, + }, + } + // Get access mode volumeCaps := make([]*csi.VolumeCapability, 0) for _, cap := range options.PVC.Spec.AccessModes { @@ -502,17 +517,6 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis return nil, capErr } - fsType := "" - for k, v := range options.Parameters { - switch strings.ToLower(k) { - case "fstype": - fsType = v - } - } - if len(fsType) == 0 { - fsType = defaultFSType - } - pv := &v1.PersistentVolume{ ObjectMeta: metav1.ObjectMeta{ Name: pvName, @@ -520,6 +524,7 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis Spec: v1.PersistentVolumeSpec{ PersistentVolumeReclaimPolicy: options.PersistentVolumeReclaimPolicy, AccessModes: options.PVC.Spec.AccessModes, + MountOptions: options.MountOptions, Capacity: v1.ResourceList{ v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(respCap), },