Skip to content

Commit

Permalink
fix provision fail when volume size is unknown
Browse files Browse the repository at this point in the history
  • Loading branch information
hoyho committed Jul 10, 2019
1 parent ef48386 commit 9201a2e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,12 @@ func (p *csiProvisioner) Provision(options controller.ProvisionOptions) (*v1.Per
volumeAttributes[k] = v
}
respCap := rep.GetVolume().GetCapacityBytes()
if respCap < volSizeBytes {

//According to CSI spec CreateVolume should be able to return capacity = 0, which means it is unknown. for example NFS/FTP
if respCap == 0 {
respCap = volSizeBytes
klog.V(3).Infof("csiClient response volume with size 0, which is not supported by apiServer, will use claim size:%d", respCap)
} else if respCap < volSizeBytes {
capErr := fmt.Errorf("created volume capacity %v less than requested capacity %v", respCap, volSizeBytes)
delReq := &csi.DeleteVolumeRequest{
VolumeId: rep.GetVolume().GetVolumeId(),
Expand Down
32 changes: 32 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ type provisioningTestcase struct {
getSecretRefErr bool
getCredentialsErr bool
volWithLessCap bool
volWithZeroCap bool
expectedPVSpec *pvSpec
withSecretRefs bool
expectErr bool
Expand Down Expand Up @@ -1262,6 +1263,34 @@ func TestProvision(t *testing.T) {
}
},
},
"provision with size 0": {
volOpts: controller.ProvisionOptions{
StorageClass: &storagev1.StorageClass{
Parameters: map[string]string{
"fstype": "ext3",
},
ReclaimPolicy: &deletePolicy,
},
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
},
volWithZeroCap: true,
expectedPVSpec: &pvSpec{
Name: "test-testi",
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
Capacity: v1.ResourceList{
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
},
CSIPVS: &v1.CSIPersistentVolumeSource{
Driver: "test-driver",
VolumeHandle: "test-volume-id",
FSType: "ext3",
VolumeAttributes: map[string]string{
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
},
},
},
},
}

for k, tc := range testcases {
Expand Down Expand Up @@ -1372,6 +1401,9 @@ func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requested
out.Volume.CapacityBytes = int64(80)
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(out, nil).Times(1)
controllerServer.EXPECT().DeleteVolume(gomock.Any(), gomock.Any()).Return(&csi.DeleteVolumeResponse{}, nil).Times(1)
} else if tc.volWithZeroCap {
out.Volume.CapacityBytes = int64(0)
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(out, nil).Times(1)
} else if tc.expectCreateVolDo != nil {
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Do(tc.expectCreateVolDo).Return(out, nil).Times(1)
} else {
Expand Down

0 comments on commit 9201a2e

Please sign in to comment.