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

Commit

Permalink
Merge pull request #835 from pgagnon/nfsc-mount-options-propagation
Browse files Browse the repository at this point in the history
Propagate StorageClass MountOptions to PVs created by nfs-client-provisioner
  • Loading branch information
wongma7 committed Jul 9, 2018
2 parents a49d411 + 56acad4 commit 43c7070
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
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

0 comments on commit 43c7070

Please sign in to comment.