@@ -38,18 +38,18 @@ const (
38
38
diskKind = "compute#disk"
39
39
)
40
40
41
- type ApiVersion string
41
+ type GCEAPIVersion string
42
42
43
43
const (
44
44
// V1 key type
45
- V1 ApiVersion = "v1"
45
+ GCEAPIVersionV1 GCEAPIVersion = "v1"
46
46
// Alpha key type
47
- Alpha ApiVersion = "alpha"
47
+ GCEAPIVersionAlpha GCEAPIVersion = "alpha"
48
48
)
49
49
50
50
type GCECompute interface {
51
51
// Disk Methods
52
- GetDisk (ctx context.Context , volumeKey * meta.Key , apiVersion ApiVersion ) (* CloudDisk , error )
52
+ GetDisk (ctx context.Context , volumeKey * meta.Key , gceAPIVersion GCEAPIVersion ) (* CloudDisk , error )
53
53
RepairUnderspecifiedVolumeKey (ctx context.Context , volumeKey * meta.Key ) (* meta.Key , error )
54
54
ValidateExistingDisk (ctx context.Context , disk * CloudDisk , diskType string , reqBytes , limBytes int64 , multiWriter bool ) error
55
55
InsertDisk (ctx context.Context , volKey * meta.Key , diskType string , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID , diskEncryptionKmsKey string , multiWriter bool ) error
@@ -156,19 +156,19 @@ func (cloud *CloudProvider) ListSnapshots(ctx context.Context, filter string, ma
156
156
157
157
}
158
158
159
- func (cloud * CloudProvider ) GetDisk (ctx context.Context , key * meta.Key , apiVersion ApiVersion ) (* CloudDisk , error ) {
159
+ func (cloud * CloudProvider ) GetDisk (ctx context.Context , key * meta.Key , gceAPIVersion GCEAPIVersion ) (* CloudDisk , error ) {
160
160
klog .V (5 ).Infof ("Getting disk %v" , key )
161
161
switch key .Type () {
162
162
case meta .Zonal :
163
- if apiVersion == Alpha {
163
+ if gceAPIVersion == GCEAPIVersionAlpha {
164
164
disk , err := cloud .getZonalAlphaDiskOrError (ctx , key .Zone , key .Name )
165
165
return ZonalAlphaCloudDisk (disk ), err
166
166
} else {
167
167
disk , err := cloud .getZonalDiskOrError (ctx , key .Zone , key .Name )
168
168
return ZonalCloudDisk (disk ), err
169
169
}
170
170
case meta .Regional :
171
- if apiVersion == Alpha {
171
+ if gceAPIVersion == GCEAPIVersionAlpha {
172
172
disk , err := cloud .getRegionalAlphaDiskOrError (ctx , key .Region , key .Name )
173
173
return RegionalAlphaCloudDisk (disk ), err
174
174
} else {
@@ -303,13 +303,13 @@ func convertV1DiskToAlphaDisk(v1Disk *computev1.Disk) *computealpha.Disk {
303
303
304
304
func (cloud * CloudProvider ) insertRegionalDisk (ctx context.Context , volKey * meta.Key , diskType string , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID , diskEncryptionKmsKey string , multiWriter bool ) error {
305
305
var (
306
- err error
307
- opName string
308
- apiVersion = V1
306
+ err error
307
+ opName string
308
+ gceAPIVersion = GCEAPIVersionV1
309
309
)
310
310
311
311
if multiWriter {
312
- apiVersion = Alpha
312
+ gceAPIVersion = GCEAPIVersionAlpha
313
313
}
314
314
315
315
diskToCreate := & computev1.Disk {
@@ -330,24 +330,24 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta
330
330
}
331
331
}
332
332
333
- if apiVersion == Alpha {
333
+ if gceAPIVersion == GCEAPIVersionAlpha {
334
334
var insertOp * computealpha.Operation
335
335
alphaDiskToCreate := convertV1DiskToAlphaDisk (diskToCreate )
336
336
alphaDiskToCreate .MultiWriter = multiWriter
337
337
insertOp , err = cloud .alphaService .RegionDisks .Insert (cloud .project , volKey .Region , alphaDiskToCreate ).Context (ctx ).Do ()
338
- if err = = nil {
338
+ if insertOp ! = nil {
339
339
opName = insertOp .Name
340
340
}
341
341
} else {
342
342
var insertOp * computev1.Operation
343
343
insertOp , err = cloud .service .RegionDisks .Insert (cloud .project , volKey .Region , diskToCreate ).Context (ctx ).Do ()
344
- if err = = nil {
344
+ if insertOp ! = nil {
345
345
opName = insertOp .Name
346
346
}
347
347
}
348
348
if err != nil {
349
349
if IsGCEError (err , "alreadyExists" ) {
350
- disk , err := cloud .GetDisk (ctx , volKey , V1 )
350
+ disk , err := cloud .GetDisk (ctx , volKey , GCEAPIVersionV1 )
351
351
if err != nil {
352
352
return err
353
353
}
@@ -367,7 +367,7 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta
367
367
err = cloud .waitForRegionalOp (ctx , opName , volKey .Region )
368
368
if err != nil {
369
369
if IsGCEError (err , "alreadyExists" ) {
370
- disk , err := cloud .GetDisk (ctx , volKey , V1 )
370
+ disk , err := cloud .GetDisk (ctx , volKey , GCEAPIVersionV1 )
371
371
if err != nil {
372
372
return err
373
373
}
@@ -388,13 +388,13 @@ func (cloud *CloudProvider) insertRegionalDisk(ctx context.Context, volKey *meta
388
388
389
389
func (cloud * CloudProvider ) insertZonalDisk (ctx context.Context , volKey * meta.Key , diskType string , capBytes int64 , capacityRange * csi.CapacityRange , snapshotID , diskEncryptionKmsKey string , multiWriter bool ) error {
390
390
var (
391
- err error
392
- opName string
393
- apiVersion = V1
391
+ err error
392
+ opName string
393
+ gceAPIVersion = GCEAPIVersionV1
394
394
)
395
395
396
396
if multiWriter {
397
- apiVersion = Alpha
397
+ gceAPIVersion = GCEAPIVersionAlpha
398
398
}
399
399
400
400
diskToCreate := & computev1.Disk {
@@ -414,25 +414,25 @@ func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Ke
414
414
}
415
415
}
416
416
417
- if apiVersion == Alpha {
417
+ if gceAPIVersion == GCEAPIVersionAlpha {
418
418
var insertOp * computealpha.Operation
419
419
alphaDiskToCreate := convertV1DiskToAlphaDisk (diskToCreate )
420
420
alphaDiskToCreate .MultiWriter = multiWriter
421
421
insertOp , err = cloud .alphaService .Disks .Insert (cloud .project , volKey .Zone , alphaDiskToCreate ).Context (ctx ).Do ()
422
- if err = = nil {
422
+ if insertOp ! = nil {
423
423
opName = insertOp .Name
424
424
}
425
425
} else {
426
426
var insertOp * computev1.Operation
427
427
insertOp , err = cloud .service .Disks .Insert (cloud .project , volKey .Zone , diskToCreate ).Context (ctx ).Do ()
428
- if err = = nil {
428
+ if insertOp ! = nil {
429
429
opName = insertOp .Name
430
430
}
431
431
}
432
432
433
433
if err != nil {
434
434
if IsGCEError (err , "alreadyExists" ) {
435
- disk , err := cloud .GetDisk (ctx , volKey , apiVersion )
435
+ disk , err := cloud .GetDisk (ctx , volKey , gceAPIVersion )
436
436
if err != nil {
437
437
return err
438
438
}
@@ -453,7 +453,7 @@ func (cloud *CloudProvider) insertZonalDisk(ctx context.Context, volKey *meta.Ke
453
453
454
454
if err != nil {
455
455
if IsGCEError (err , "alreadyExists" ) {
456
- disk , err := cloud .GetDisk (ctx , volKey , apiVersion )
456
+ disk , err := cloud .GetDisk (ctx , volKey , gceAPIVersion )
457
457
if err != nil {
458
458
return err
459
459
}
@@ -649,7 +649,7 @@ func (cloud *CloudProvider) WaitForAttach(ctx context.Context, volKey *meta.Key,
649
649
start := time .Now ()
650
650
return wait .Poll (5 * time .Second , 2 * time .Minute , func () (bool , error ) {
651
651
klog .V (6 ).Infof ("Polling for attach of disk %v to instance %v to complete for %v" , volKey .Name , instanceName , time .Since (start ))
652
- disk , err := cloud .GetDisk (ctx , volKey , V1 )
652
+ disk , err := cloud .GetDisk (ctx , volKey , GCEAPIVersionV1 )
653
653
if err != nil {
654
654
return false , fmt .Errorf ("GetDisk failed to get disk: %v" , err )
655
655
}
@@ -740,7 +740,7 @@ func (cloud *CloudProvider) CreateSnapshot(ctx context.Context, volKey *meta.Key
740
740
741
741
func (cloud * CloudProvider ) ResizeDisk (ctx context.Context , volKey * meta.Key , requestBytes int64 ) (int64 , error ) {
742
742
klog .V (5 ).Infof ("Resizing disk %v to size %v" , volKey , requestBytes )
743
- cloudDisk , err := cloud .GetDisk (ctx , volKey , V1 )
743
+ cloudDisk , err := cloud .GetDisk (ctx , volKey , GCEAPIVersionV1 )
744
744
if err != nil {
745
745
return - 1 , fmt .Errorf ("failed to get disk: %v" , err )
746
746
}
0 commit comments