Skip to content
This repository has been archived by the owner on Oct 21, 2020. It is now read-only.

Propagate StorageClass MountOptions to PVs created by nfs-client-provisioner #835

Merged
merged 3 commits into from
Jul 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions lib/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,17 @@ func (ctrl *ProvisionController) provisionClaimOperation(claim *v1.PersistentVol
}
}

mountOptions, err := ctrl.fetchMountOptions(claimClass)
if err != nil {
return err
}

options := VolumeOptions{
PersistentVolumeReclaimPolicy: reclaimPolicy,
PVName: pvName,
PVC: claim,
Parameters: parameters,
PVName: pvName,
PVC: claim,
MountOptions: mountOptions,
Parameters: parameters,
}

ctrl.eventRecorder.Event(claim, v1.EventTypeNormal, "Provisioning", fmt.Sprintf("External provisioner is provisioning volume for claim %q", claimToClaimKey(claim)))
Expand Down Expand Up @@ -1381,6 +1387,25 @@ func (ctrl *ProvisionController) fetchReclaimPolicy(storageClassName string) (v1
return v1.PersistentVolumeReclaimDelete, fmt.Errorf("Cannot convert object to StorageClass: %+v", classObj)
}

func (ctrl *ProvisionController) fetchMountOptions(storageClassName string) ([]string, error) {
classObj, found, err := ctrl.classes.GetByKey(storageClassName)
if err != nil {
return nil, err
}
if !found {
return nil, fmt.Errorf("StorageClass %q not found", storageClassName)
}

switch class := classObj.(type) {
case *storage.StorageClass:
return class.MountOptions, nil
case *storagebeta.StorageClass:
return class.MountOptions, nil
}

return nil, fmt.Errorf("Cannot convert object to StorageClass: %+v", classObj)
}

// supportsBlock returns whether a provisioner supports block volume.
// Provisioners that implement BlockProvisioner interface and return true to SupportsBlock
// will be regarded as supported for block volume.
Expand Down
4 changes: 4 additions & 0 deletions lib/controller/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ type VolumeOptions struct {
// PV.Name of the appropriate PersistentVolume. Used to generate cloud
// volume name.
PVName string

// PV mount options. Not validated - mount of the PVs will simply fail if one is invalid.
MountOptions []string

// PVC is reference to the claim that lead to provisioning of a new PV.
// Provisioners *must* create a PV that would be matched by this PVC,
// i.e. with required capacity, accessMode, labels matching PVC.Selector and
Expand Down
1 change: 1 addition & 0 deletions nfs-client/cmd/nfs-client-provisioner/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (p *nfsProvisioner) 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): options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)],
},
Expand Down