Last active
February 19, 2020 19:22
-
-
Save j-griffith/0b5a5667cb44e308e9ffccac409f2d38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go | |
index 4dda40950..f9fb0bc85 100644 | |
--- a/pkg/controller/controller.go | |
+++ b/pkg/controller/controller.go | |
@@ -745,12 +745,12 @@ func removePrefixedParameters(param map[string]string) (map[string]string, error | |
// currently we provide Snapshot and PVC, the default case allows the provisioner to still create a volume | |
// so that an external controller can act upon it. Additional DataSource types can be added here with | |
// an appropriate implementation function | |
-func (p *csiProvisioner) getVolumeContentSource(options controller.ProvisionOptions) (*csi.VolumeContentSource, error) { | |
+func (p *csiProvisioner) getVolumeContentSource(options controller.ProvisionOptions, provisionerFSType string) (*csi.VolumeContentSource, error) { | |
switch options.PVC.Spec.DataSource.Kind { | |
case snapshotKind: | |
return p.getSnapshotSource(options) | |
case pvcKind: | |
- return p.getPVCSource(options) | |
+ return p.getPVCSource(options, provisionerFSType) | |
default: | |
// For now we shouldn't pass other things to this function, but treat it as a noop and extend as needed | |
return nil, nil | |
@@ -759,7 +759,7 @@ func (p *csiProvisioner) getVolumeContentSource(options controller.ProvisionOpti | |
// getPVCSource verifies DataSource.Kind of type PersistentVolumeClaim, making sure that the requested PVC is available/ready | |
// returns the VolumeContentSource for the requested PVC | |
-func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions) (*csi.VolumeContentSource, error) { | |
+func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions, provisionerFSType string) (*csi.VolumeContentSource, error) { | |
sourcePVC, err := p.client.CoreV1().PersistentVolumeClaims(options.PVC.Namespace).Get(options.PVC.Spec.DataSource.Name, metav1.GetOptions{}) | |
if err != nil { | |
return nil, fmt.Errorf("error getting PVC %s (namespace %q) from api server: %v", options.PVC.Spec.DataSource.Name, options.PVC.Namespace, err) | |
@@ -783,6 +783,12 @@ func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions) (*csi | |
return nil, fmt.Errorf("the source PVC and destination PVCs must be in the same storage class for cloning. Source is in %v, but new PVC is in %v", | |
*sourcePVC.Spec.StorageClassName, *options.PVC.Spec.StorageClassName) | |
} | |
+ | |
+ if *sourcePVC.Spec.VolumeMode != *options.PVC.Spec.VolumeMode { | |
+ return nil, fmt.Errorf("the source PVC and destination PVCs must have the same volume mode for cloning. Source is %v, but new PVC requests %v", | |
+ *sourcePVC.Spec.VolumeMode, *options.PVC.Spec.VolumeMode) | |
+ } | |
+ | |
capacity := options.PVC.Spec.Resources.Requests[v1.ResourceName(v1.ResourceStorage)] | |
requestedSize := capacity.Value() | |
if requestedSize < int64(sourcePVC.Spec.Size()) { | |
@@ -819,6 +825,10 @@ func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions) (*csi | |
return nil, fmt.Errorf("claim in dataSource not bound or invalid") | |
} | |
+ if sourcePV.Spec.CSI.FSType != provisionerFSType { | |
+ return nil, fmt.Errorf("the source PVC and destination PVCs must be of the same fs type for cloning. Source is %v, but new PVC requests %v", | |
+ sourcePV.Spec.CSI.FSType, provisionerFSType) | |
+ } | |
volumeSource := csi.VolumeContentSource_Volume{ | |
Volume: &csi.VolumeContentSource_VolumeSource{ | |
VolumeId: sourcePV.Spec.CSI.VolumeHandle, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment