@@ -80,31 +80,34 @@ func (cloud *FakeCloudProvider) GetDefaultZone() string {
80
80
return cloud .zone
81
81
}
82
82
83
- func (cloud * FakeCloudProvider ) RepairUnderspecifiedVolumeKey (ctx context.Context , volumeKey * meta.Key ) (* meta.Key , error ) {
83
+ func (cloud * FakeCloudProvider ) RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (string , * meta.Key , error ) {
84
+ if project == common .UnspecifiedValue {
85
+ project = cloud .project
86
+ }
84
87
switch volumeKey .Type () {
85
88
case meta .Zonal :
86
89
if volumeKey .Zone != common .UnspecifiedValue {
87
- return volumeKey , nil
90
+ return project , volumeKey , nil
88
91
}
89
92
for name , d := range cloud .disks {
90
93
if name == volumeKey .Name {
91
94
volumeKey .Zone = d .GetZone ()
92
- return volumeKey , nil
95
+ return project , volumeKey , nil
93
96
}
94
97
}
95
- return nil , notFoundError ()
98
+ return "" , nil , notFoundError ()
96
99
case meta .Regional :
97
100
if volumeKey .Region != common .UnspecifiedValue {
98
- return volumeKey , nil
101
+ return project , volumeKey , nil
99
102
}
100
103
r , err := common .GetRegionFromZones ([]string {cloud .zone })
101
104
if err != nil {
102
- return nil , fmt .Errorf ("failed to get region from zones: %v" , err )
105
+ return "" , nil , fmt .Errorf ("failed to get region from zones: %v" , err )
103
106
}
104
107
volumeKey .Region = r
105
- return volumeKey , nil
108
+ return project , volumeKey , nil
106
109
default :
107
- return nil , fmt .Errorf ("Volume key %v not zonal nor regional" , volumeKey .Name )
110
+ return "" , nil , fmt .Errorf ("Volume key %v not zonal nor regional" , volumeKey .Name )
108
111
}
109
112
}
110
113
@@ -212,7 +215,7 @@ func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string
212
215
}
213
216
214
217
// Disk Methods
215
- func (cloud * FakeCloudProvider ) GetDisk (ctx context.Context , volKey * meta.Key , api GCEAPIVersion ) (* CloudDisk , error ) {
218
+ func (cloud * FakeCloudProvider ) GetDisk (ctx context.Context , project string , volKey * meta.Key , api GCEAPIVersion ) (* CloudDisk , error ) {
216
219
disk , ok := cloud .disks [volKey .Name ]
217
220
if ! ok {
218
221
return nil , notFoundError ()
@@ -249,7 +252,7 @@ func (cloud *FakeCloudProvider) ValidateExistingDisk(ctx context.Context, resp *
249
252
return ValidateDiskParameters (resp , params )
250
253
}
251
254
252
- func (cloud * FakeCloudProvider ) InsertDisk (ctx context.Context , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , multiWriter bool ) error {
255
+ func (cloud * FakeCloudProvider ) InsertDisk (ctx context.Context , project string , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , multiWriter bool ) error {
253
256
if disk , ok := cloud .disks [volKey .Name ]; ok {
254
257
err := cloud .ValidateExistingDisk (ctx , disk , params ,
255
258
int64 (capacityRange .GetRequiredBytes ()),
@@ -264,7 +267,7 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
264
267
Name : volKey .Name ,
265
268
SizeGb : common .BytesToGbRoundUp (capBytes ),
266
269
Description : "Disk created by GCE-PD CSI Driver" ,
267
- Type : cloud .GetDiskTypeURI (volKey , params .DiskType ),
270
+ Type : cloud .GetDiskTypeURI (project , volKey , params .DiskType ),
268
271
SourceSnapshotId : snapshotID ,
269
272
Status : cloud .mockDiskStatus ,
270
273
Labels : params .Labels ,
@@ -277,10 +280,10 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
277
280
switch volKey .Type () {
278
281
case meta .Zonal :
279
282
computeDisk .Zone = volKey .Zone
280
- computeDisk .SelfLink = fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , cloud . project , volKey .Zone , volKey .Name )
283
+ computeDisk .SelfLink = fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , volKey .Zone , volKey .Name )
281
284
case meta .Regional :
282
285
computeDisk .Region = volKey .Region
283
- computeDisk .SelfLink = fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , cloud . project , volKey .Region , volKey .Name )
286
+ computeDisk .SelfLink = fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , volKey .Region , volKey .Name )
284
287
default :
285
288
return fmt .Errorf ("could not create disk, key was neither zonal nor regional, instead got: %v" , volKey .String ())
286
289
}
@@ -289,16 +292,16 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
289
292
return nil
290
293
}
291
294
292
- func (cloud * FakeCloudProvider ) DeleteDisk (ctx context.Context , volKey * meta.Key ) error {
295
+ func (cloud * FakeCloudProvider ) DeleteDisk (ctx context.Context , project string , volKey * meta.Key ) error {
293
296
if _ , ok := cloud .disks [volKey .Name ]; ! ok {
294
297
return notFoundError ()
295
298
}
296
299
delete (cloud .disks , volKey .Name )
297
300
return nil
298
301
}
299
302
300
- func (cloud * FakeCloudProvider ) AttachDisk (ctx context.Context , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string ) error {
301
- source := cloud .GetDiskSourceURI (volKey )
303
+ func (cloud * FakeCloudProvider ) AttachDisk (ctx context.Context , project string , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string ) error {
304
+ source := cloud .GetDiskSourceURI (project , volKey )
302
305
303
306
attachedDiskV1 := & computev1.AttachedDisk {
304
307
DeviceName : volKey .Name ,
@@ -315,7 +318,7 @@ func (cloud *FakeCloudProvider) AttachDisk(ctx context.Context, volKey *meta.Key
315
318
return nil
316
319
}
317
320
318
- func (cloud * FakeCloudProvider ) DetachDisk (ctx context.Context , deviceName , instanceZone , instanceName string ) error {
321
+ func (cloud * FakeCloudProvider ) DetachDisk (ctx context.Context , project , deviceName , instanceZone , instanceName string ) error {
319
322
instance , ok := cloud .instances [instanceName ]
320
323
if ! ok {
321
324
return fmt .Errorf ("Failed to get instance %v" , instanceName )
@@ -332,31 +335,31 @@ func (cloud *FakeCloudProvider) DetachDisk(ctx context.Context, deviceName, inst
332
335
return nil
333
336
}
334
337
335
- func (cloud * FakeCloudProvider ) GetDiskTypeURI (volKey * meta.Key , diskType string ) string {
338
+ func (cloud * FakeCloudProvider ) GetDiskTypeURI (project string , volKey * meta.Key , diskType string ) string {
336
339
switch volKey .Type () {
337
340
case meta .Zonal :
338
- return cloud .getZonalDiskTypeURI (volKey .Zone , diskType )
341
+ return cloud .getZonalDiskTypeURI (project , volKey .Zone , diskType )
339
342
case meta .Regional :
340
- return cloud .getRegionalDiskTypeURI (volKey .Region , diskType )
343
+ return cloud .getRegionalDiskTypeURI (project , volKey .Region , diskType )
341
344
default :
342
345
return fmt .Sprintf ("could not get disk type uri, key was neither zonal nor regional, instead got: %v" , volKey .String ())
343
346
}
344
347
}
345
348
346
- func (cloud * FakeCloudProvider ) getZonalDiskTypeURI (zone , diskType string ) string {
347
- return fmt .Sprintf (diskTypeURITemplateSingleZone , cloud . project , zone , diskType )
349
+ func (cloud * FakeCloudProvider ) getZonalDiskTypeURI (project , zone , diskType string ) string {
350
+ return fmt .Sprintf (diskTypeURITemplateSingleZone , project , zone , diskType )
348
351
}
349
352
350
- func (cloud * FakeCloudProvider ) getRegionalDiskTypeURI (region , diskType string ) string {
351
- return fmt .Sprintf (diskTypeURITemplateRegional , cloud . project , region , diskType )
353
+ func (cloud * FakeCloudProvider ) getRegionalDiskTypeURI (project , region , diskType string ) string {
354
+ return fmt .Sprintf (diskTypeURITemplateRegional , project , region , diskType )
352
355
}
353
356
354
- func (cloud * FakeCloudProvider ) WaitForAttach (ctx context.Context , volKey * meta.Key , instanceZone , instanceName string ) error {
357
+ func (cloud * FakeCloudProvider ) WaitForAttach (ctx context.Context , project string , volKey * meta.Key , instanceZone , instanceName string ) error {
355
358
return nil
356
359
}
357
360
358
361
// Regional Disk Methods
359
- func (cloud * FakeCloudProvider ) GetReplicaZoneURI (zone string ) string {
362
+ func (cloud * FakeCloudProvider ) GetReplicaZoneURI (project , zone string ) string {
360
363
return ""
361
364
}
362
365
@@ -375,7 +378,7 @@ func (cloud *FakeCloudProvider) GetInstanceOrError(ctx context.Context, instance
375
378
}
376
379
377
380
// Snapshot Methods
378
- func (cloud * FakeCloudProvider ) GetSnapshot (ctx context.Context , snapshotName string ) (* computev1.Snapshot , error ) {
381
+ func (cloud * FakeCloudProvider ) GetSnapshot (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
379
382
snapshot , ok := cloud .snapshots [snapshotName ]
380
383
if ! ok {
381
384
return nil , notFoundError ()
@@ -384,7 +387,7 @@ func (cloud *FakeCloudProvider) GetSnapshot(ctx context.Context, snapshotName st
384
387
return snapshot , nil
385
388
}
386
389
387
- func (cloud * FakeCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* computev1.Snapshot , error ) {
390
+ func (cloud * FakeCloudProvider ) CreateSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string ) (* computev1.Snapshot , error ) {
388
391
if snapshot , ok := cloud .snapshots [snapshotName ]; ok {
389
392
return snapshot , nil
390
393
}
@@ -394,13 +397,13 @@ func (cloud *FakeCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta
394
397
DiskSizeGb : int64 (DiskSizeGb ),
395
398
CreationTimestamp : Timestamp ,
396
399
Status : "UPLOADING" ,
397
- SelfLink : cloud .getGlobalSnapshotURI (snapshotName ),
400
+ SelfLink : cloud .getGlobalSnapshotURI (project , snapshotName ),
398
401
}
399
402
switch volKey .Type () {
400
403
case meta .Zonal :
401
- snapshotToCreate .SourceDisk = cloud .getZonalDiskSourceURI (volKey .Name , volKey .Zone )
404
+ snapshotToCreate .SourceDisk = cloud .getZonalDiskSourceURI (project , volKey .Name , volKey .Zone )
402
405
case meta .Regional :
403
- snapshotToCreate .SourceDisk = cloud .getRegionalDiskSourceURI (volKey .Name , volKey .Region )
406
+ snapshotToCreate .SourceDisk = cloud .getRegionalDiskSourceURI (project , volKey .Name , volKey .Region )
404
407
default :
405
408
return nil , fmt .Errorf ("could not create snapshot, disk key was neither zonal nor regional, instead got: %v" , volKey .String ())
406
409
}
@@ -409,7 +412,7 @@ func (cloud *FakeCloudProvider) CreateSnapshot(ctx context.Context, volKey *meta
409
412
return snapshotToCreate , nil
410
413
}
411
414
412
- func (cloud * FakeCloudProvider ) ResizeDisk (ctx context.Context , volKey * meta.Key , requestBytes int64 ) (int64 , error ) {
415
+ func (cloud * FakeCloudProvider ) ResizeDisk (ctx context.Context , project string , volKey * meta.Key , requestBytes int64 ) (int64 , error ) {
413
416
disk , ok := cloud .disks [volKey .Name ]
414
417
if ! ok {
415
418
return - 1 , notFoundError ()
@@ -424,7 +427,7 @@ func (cloud *FakeCloudProvider) ResizeDisk(ctx context.Context, volKey *meta.Key
424
427
}
425
428
426
429
// Snapshot Methods
427
- func (cloud * FakeCloudProvider ) DeleteSnapshot (ctx context.Context , snapshotName string ) error {
430
+ func (cloud * FakeCloudProvider ) DeleteSnapshot (ctx context.Context , project , snapshotName string ) error {
428
431
delete (cloud .snapshots , snapshotName )
429
432
return nil
430
433
}
@@ -434,7 +437,7 @@ func (cloud *FakeCloudProvider) ValidateExistingSnapshot(resp *computev1.Snapsho
434
437
return fmt .Errorf ("disk does not exist" )
435
438
}
436
439
437
- diskSource := cloud .GetDiskSourceURI (volKey )
440
+ diskSource := cloud .GetDiskSourceURI (cloud . project , volKey )
438
441
if resp .SourceDisk != diskSource {
439
442
return status .Error (codes .AlreadyExists , fmt .Sprintf ("snapshot already exists with same name but with a different disk source %s, expected disk source %s" , diskSource , resp .SourceDisk ))
440
443
}
@@ -443,37 +446,37 @@ func (cloud *FakeCloudProvider) ValidateExistingSnapshot(resp *computev1.Snapsho
443
446
return nil
444
447
}
445
448
446
- func (cloud * FakeCloudProvider ) GetDiskSourceURI (volKey * meta.Key ) string {
449
+ func (cloud * FakeCloudProvider ) GetDiskSourceURI (project string , volKey * meta.Key ) string {
447
450
switch volKey .Type () {
448
451
case meta .Zonal :
449
- return cloud .getZonalDiskSourceURI (volKey .Name , volKey .Zone )
452
+ return cloud .getZonalDiskSourceURI (project , volKey .Name , volKey .Zone )
450
453
case meta .Regional :
451
- return cloud .getRegionalDiskSourceURI (volKey .Name , volKey .Region )
454
+ return cloud .getRegionalDiskSourceURI (project , volKey .Name , volKey .Region )
452
455
default :
453
456
return ""
454
457
}
455
458
}
456
459
457
- func (cloud * FakeCloudProvider ) getZonalDiskSourceURI (diskName , zone string ) string {
460
+ func (cloud * FakeCloudProvider ) getZonalDiskSourceURI (project , diskName , zone string ) string {
458
461
return BasePath + fmt .Sprintf (
459
462
diskSourceURITemplateSingleZone ,
460
- cloud . project ,
463
+ project ,
461
464
zone ,
462
465
diskName )
463
466
}
464
467
465
- func (cloud * FakeCloudProvider ) getRegionalDiskSourceURI (diskName , region string ) string {
468
+ func (cloud * FakeCloudProvider ) getRegionalDiskSourceURI (project , diskName , region string ) string {
466
469
return BasePath + fmt .Sprintf (
467
470
diskSourceURITemplateRegional ,
468
- cloud . project ,
471
+ project ,
469
472
region ,
470
473
diskName )
471
474
}
472
475
473
- func (cloud * FakeCloudProvider ) getGlobalSnapshotURI (snapshotName string ) string {
476
+ func (cloud * FakeCloudProvider ) getGlobalSnapshotURI (project , snapshotName string ) string {
474
477
return BasePath + fmt .Sprintf (
475
478
snapshotURITemplateGlobal ,
476
- cloud . project ,
479
+ project ,
477
480
snapshotName )
478
481
}
479
482
@@ -490,11 +493,11 @@ type FakeBlockingCloudProvider struct {
490
493
// Upon starting a CreateSnapshot, it passes a chan 'executeCreateSnapshot' into readyToExecute, then blocks on executeCreateSnapshot.
491
494
// The test calling this function can block on readyToExecute to ensure that the operation has started and
492
495
// allowed the CreateSnapshot to continue by passing a struct into executeCreateSnapshot.
493
- func (cloud * FakeBlockingCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* computev1.Snapshot , error ) {
496
+ func (cloud * FakeBlockingCloudProvider ) CreateSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string ) (* computev1.Snapshot , error ) {
494
497
executeCreateSnapshot := make (chan struct {})
495
498
cloud .ReadyToExecute <- executeCreateSnapshot
496
499
<- executeCreateSnapshot
497
- return cloud .FakeCloudProvider .CreateSnapshot (ctx , volKey , snapshotName )
500
+ return cloud .FakeCloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName )
498
501
}
499
502
500
503
func notFoundError () * googleapi.Error {
0 commit comments