Skip to content

Commit

Permalink
use volume ID for creating PVC from PVC
Browse files Browse the repository at this point in the history
as per the CSI spec we need to pass parent
volume_id while creating a volume from another volume

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
  • Loading branch information
Madhu-1 committed Jul 2, 2019
1 parent 27750ab commit 7f6b7e2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
11 changes: 10 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -671,9 +671,18 @@ func (p *csiProvisioner) getPVCSource(options controller.ProvisionOptions) (*csi
return nil, fmt.Errorf("error, new PVC request must be greater than or equal in size to the specified PVC data source, requested %v but source is %v", requestedSize, sourcePVC.Spec.Size())
}

sourcePV, err := p.client.CoreV1().PersistentVolumes().Get(sourcePVC.Spec.VolumeName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("error getting PV %s from api server: %v", sourcePVC.Spec.VolumeName, err)
}

if sourcePV.Spec.CSI == nil {
return nil, fmt.Errorf("error getting volume source from persistantVolumeClaim:persistanceVolume %s:%s", sourcePVC.Name, sourcePVC.Spec.VolumeName)
}

volumeSource := csi.VolumeContentSource_Volume{
Volume: &csi.VolumeContentSource_VolumeSource{
VolumeId: sourcePVC.Spec.VolumeName,
VolumeId: sourcePV.Spec.CSI.VolumeHandle,
},
}
klog.V(5).Infof("VolumeContentSource_Volume %+v", volumeSource)
Expand Down
37 changes: 28 additions & 9 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2146,6 +2146,7 @@ func TestProvisionFromPVC(t *testing.T) {
var requestedBytes int64 = 1000
invalidSCName := "invalid-sc"
srcName := "fake-pvc"
pvName := "test-testi"
deletePolicy := v1.PersistentVolumeReclaimDelete

type pvSpec struct {
Expand All @@ -2171,7 +2172,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand All @@ -2193,7 +2194,7 @@ func TestProvisionFromPVC(t *testing.T) {
},
pvcStatusReady: true,
expectedPVSpec: &pvSpec{
Name: "test-testi",
Name: pvName,
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
AccessModes: []v1.PersistentVolumeAccessMode{v1.ReadWriteOnce},
Capacity: v1.ResourceList{
Expand All @@ -2216,7 +2217,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand Down Expand Up @@ -2247,7 +2248,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand Down Expand Up @@ -2279,7 +2280,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand Down Expand Up @@ -2311,7 +2312,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand Down Expand Up @@ -2343,7 +2344,7 @@ func TestProvisionFromPVC(t *testing.T) {
ReclaimPolicy: &deletePolicy,
Parameters: map[string]string{},
},
PVName: "test-name",
PVName: pvName,
PVC: &v1.PersistentVolumeClaim{
ObjectMeta: metav1.ObjectMeta{
UID: "testid",
Expand Down Expand Up @@ -2394,8 +2395,26 @@ func TestProvisionFromPVC(t *testing.T) {
clientSet = fakeclientset.NewSimpleClientset()

// Create a fake claim as our PVC DataSource
claim := fakeClaim(srcName, "fake-claim-uid", "1Gi", "test-pv", v1.ClaimBound, nil)
clientSet = fakeclientset.NewSimpleClientset(claim)
claim := fakeClaim(srcName, "fake-claim-uid", "1Gi", pvName, v1.ClaimBound, nil)

pv := &v1.PersistentVolume{
ObjectMeta: metav1.ObjectMeta{
Name: pvName,
},
Spec: v1.PersistentVolumeSpec{
PersistentVolumeSource: v1.PersistentVolumeSource{
CSI: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "ext3",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
},
}
clientSet = fakeclientset.NewSimpleClientset(claim, pv)

pluginCaps, controllerCaps := provisionFromPVCCapabilities()
if !tc.cloneSupport {
Expand Down

0 comments on commit 7f6b7e2

Please sign in to comment.