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 218d7eb commit e561692
Show file tree
Hide file tree
Showing 2 changed files with 36 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 @@ -491,7 +491,12 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
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
30 changes: 30 additions & 0 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ type provisioningTestcase struct {
getSecretRefErr bool
getCredentialsErr bool
volWithLessCap bool
volWithZeroCap bool
expectedPVSpec *pvSpec
withSecretRefs bool
expectErr bool
Expand Down Expand Up @@ -1093,6 +1094,32 @@ func TestProvision(t *testing.T) {
}
},
},
"provision with size 0": {
volOpts: controller.VolumeOptions{
PersistentVolumeReclaimPolicy: v1.PersistentVolumeReclaimDelete,
PVName: "test-name",
PVC: createFakePVC(requestedBytes),
Parameters: map[string]string{
"fstype": "ext3",
},
},
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 @@ -1196,6 +1223,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 e561692

Please sign in to comment.