Skip to content

Commit e561692

Browse files
committed
fix provision fail when volume size is unknown
1 parent 218d7eb commit e561692

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pkg/controller/controller.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,12 @@ func (p *csiProvisioner) Provision(options controller.VolumeOptions) (*v1.Persis
491491
volumeAttributes[k] = v
492492
}
493493
respCap := rep.GetVolume().GetCapacityBytes()
494-
if respCap < volSizeBytes {
494+
495+
//According to CSI spec CreateVolume should be able to return capacity = 0, which means it is unknown. for example NFS/FTP
496+
if respCap == 0 {
497+
respCap = volSizeBytes
498+
klog.V(3).Infof("csiClient response volume with size 0, which is not supported by apiServer, will use claim size:%d", respCap)
499+
} else if respCap < volSizeBytes {
495500
capErr := fmt.Errorf("created volume capacity %v less than requested capacity %v", respCap, volSizeBytes)
496501
delReq := &csi.DeleteVolumeRequest{
497502
VolumeId: rep.GetVolume().GetVolumeId(),

pkg/controller/controller_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ type provisioningTestcase struct {
634634
getSecretRefErr bool
635635
getCredentialsErr bool
636636
volWithLessCap bool
637+
volWithZeroCap bool
637638
expectedPVSpec *pvSpec
638639
withSecretRefs bool
639640
expectErr bool
@@ -1093,6 +1094,32 @@ func TestProvision(t *testing.T) {
10931094
}
10941095
},
10951096
},
1097+
"provision with size 0": {
1098+
volOpts: controller.VolumeOptions{
1099+
PersistentVolumeReclaimPolicy: v1.PersistentVolumeReclaimDelete,
1100+
PVName: "test-name",
1101+
PVC: createFakePVC(requestedBytes),
1102+
Parameters: map[string]string{
1103+
"fstype": "ext3",
1104+
},
1105+
},
1106+
volWithZeroCap: true,
1107+
expectedPVSpec: &pvSpec{
1108+
Name: "test-testi",
1109+
ReclaimPolicy: v1.PersistentVolumeReclaimDelete,
1110+
Capacity: v1.ResourceList{
1111+
v1.ResourceName(v1.ResourceStorage): bytesToGiQuantity(requestedBytes),
1112+
},
1113+
CSIPVS: &v1.CSIPersistentVolumeSource{
1114+
Driver: "test-driver",
1115+
VolumeHandle: "test-volume-id",
1116+
FSType: "ext3",
1117+
VolumeAttributes: map[string]string{
1118+
"storage.kubernetes.io/csiProvisionerIdentity": "test-provisioner",
1119+
},
1120+
},
1121+
},
1122+
},
10961123
}
10971124

10981125
for k, tc := range testcases {
@@ -1196,6 +1223,9 @@ func runProvisionTest(t *testing.T, k string, tc provisioningTestcase, requested
11961223
out.Volume.CapacityBytes = int64(80)
11971224
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(out, nil).Times(1)
11981225
controllerServer.EXPECT().DeleteVolume(gomock.Any(), gomock.Any()).Return(&csi.DeleteVolumeResponse{}, nil).Times(1)
1226+
} else if tc.volWithZeroCap {
1227+
out.Volume.CapacityBytes = int64(0)
1228+
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Return(out, nil).Times(1)
11991229
} else if tc.expectCreateVolDo != nil {
12001230
controllerServer.EXPECT().CreateVolume(gomock.Any(), gomock.Any()).Do(tc.expectCreateVolDo).Return(out, nil).Times(1)
12011231
} else {

0 commit comments

Comments
 (0)