@@ -215,7 +215,7 @@ func (cloud *FakeCloudProvider) GetDisk(ctx context.Context, volKey *meta.Key) (
215
215
return disk , nil
216
216
}
217
217
218
- func (cloud * FakeCloudProvider ) ValidateExistingDisk (ctx context.Context , resp * CloudDisk , diskType string , reqBytes , limBytes int64 ) error {
218
+ func (cloud * FakeCloudProvider ) ValidateExistingDisk (ctx context.Context , resp * CloudDisk , params common. DiskParameters , reqBytes , limBytes int64 ) error {
219
219
if resp == nil {
220
220
return fmt .Errorf ("disk does not exist" )
221
221
}
@@ -227,20 +227,12 @@ func (cloud *FakeCloudProvider) ValidateExistingDisk(ctx context.Context, resp *
227
227
reqBytes , common .GbToBytes (resp .GetSizeGb ()), limBytes )
228
228
}
229
229
230
- respType := strings .Split (resp .GetType (), "/" )
231
- typeMatch := strings .TrimSpace (respType [len (respType )- 1 ]) == strings .TrimSpace (diskType )
232
- typeDefault := diskType == "" && strings .TrimSpace (respType [len (respType )- 1 ]) == "pd-standard"
233
- if ! typeMatch && ! typeDefault {
234
- return fmt .Errorf ("disk already exists with incompatible type. Need %v. Got %v" ,
235
- diskType , respType [len (respType )- 1 ])
236
- }
237
- klog .V (4 ).Infof ("Compatible disk already exists" )
238
- return nil
230
+ return ValidateDiskParameters (resp , params )
239
231
}
240
232
241
- func (cloud * FakeCloudProvider ) InsertDisk (ctx context.Context , volKey * meta.Key , diskType string , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID , diskEncryptionKmsKey string ) error {
233
+ func (cloud * FakeCloudProvider ) InsertDisk (ctx context.Context , volKey * meta.Key , params common. DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string ) error {
242
234
if disk , ok := cloud .disks [volKey .Name ]; ok {
243
- err := cloud .ValidateExistingDisk (ctx , disk , diskType ,
235
+ err := cloud .ValidateExistingDisk (ctx , disk , params ,
244
236
int64 (capacityRange .GetRequiredBytes ()),
245
237
int64 (capacityRange .GetLimitBytes ()))
246
238
if err != nil {
@@ -255,13 +247,13 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
255
247
Name : volKey .Name ,
256
248
SizeGb : common .BytesToGb (capBytes ),
257
249
Description : "Disk created by GCE-PD CSI Driver" ,
258
- Type : cloud .GetDiskTypeURI (volKey , diskType ),
250
+ Type : cloud .GetDiskTypeURI (volKey , params . DiskType ),
259
251
SelfLink : fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , cloud .project , volKey .Zone , volKey .Name ),
260
252
SourceSnapshotId : snapshotID ,
261
253
}
262
- if diskEncryptionKmsKey != "" {
254
+ if params . DiskEncryptionKMSKey != "" {
263
255
diskToCreateGA .DiskEncryptionKey = & computev1.CustomerEncryptionKey {
264
- KmsKeyName : diskEncryptionKmsKey ,
256
+ KmsKeyName : params . DiskEncryptionKMSKey ,
265
257
}
266
258
}
267
259
diskToCreate = ZonalCloudDisk (diskToCreateGA )
@@ -270,13 +262,13 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
270
262
Name : volKey .Name ,
271
263
SizeGb : common .BytesToGb (capBytes ),
272
264
Description : "Regional disk created by GCE-PD CSI Driver" ,
273
- Type : cloud .GetDiskTypeURI (volKey , diskType ),
265
+ Type : cloud .GetDiskTypeURI (volKey , params . DiskType ),
274
266
SelfLink : fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , cloud .project , volKey .Region , volKey .Name ),
275
267
SourceSnapshotId : snapshotID ,
276
268
}
277
- if diskEncryptionKmsKey != "" {
269
+ if params . DiskEncryptionKMSKey != "" {
278
270
diskToCreateV1 .DiskEncryptionKey = & computev1.CustomerEncryptionKey {
279
- KmsKeyName : diskEncryptionKmsKey ,
271
+ KmsKeyName : params . DiskEncryptionKMSKey ,
280
272
}
281
273
}
282
274
diskToCreate = RegionalCloudDisk (diskToCreateV1 )
0 commit comments