@@ -22,8 +22,7 @@ import (
22
22
23
23
"github.com/GoogleCloudPlatform/k8s-cloud-provider/pkg/cloud/meta"
24
24
csi "github.com/container-storage-interface/spec/lib/go/csi"
25
- computebeta "google.golang.org/api/compute/v0.beta"
26
- compute "google.golang.org/api/compute/v1"
25
+ computev1 "google.golang.org/api/compute/v1"
27
26
"google.golang.org/api/googleapi"
28
27
"google.golang.org/grpc/codes"
29
28
"google.golang.org/grpc/status"
@@ -43,8 +42,8 @@ type FakeCloudProvider struct {
43
42
zone string
44
43
45
44
disks map [string ]* CloudDisk
46
- instances map [string ]* compute .Instance
47
- snapshots map [string ]* compute .Snapshot
45
+ instances map [string ]* computev1 .Instance
46
+ snapshots map [string ]* computev1 .Snapshot
48
47
}
49
48
50
49
var _ GCECompute = & FakeCloudProvider {}
@@ -54,8 +53,8 @@ func CreateFakeCloudProvider(project, zone string, cloudDisks []*CloudDisk) (*Fa
54
53
project : project ,
55
54
zone : zone ,
56
55
disks : map [string ]* CloudDisk {},
57
- instances : map [string ]* compute .Instance {},
58
- snapshots : map [string ]* compute .Snapshot {},
56
+ instances : map [string ]* computev1 .Instance {},
57
+ snapshots : map [string ]* computev1 .Snapshot {},
59
58
}
60
59
for _ , d := range cloudDisks {
61
60
fcp .disks [d .GetName ()] = d
@@ -95,9 +94,9 @@ func (cloud *FakeCloudProvider) ListZones(ctx context.Context, region string) ([
95
94
return []string {cloud .zone , "country-region-fakesecondzone" }, nil
96
95
}
97
96
98
- func (cloud * FakeCloudProvider ) ListSnapshots (ctx context.Context , filter string , maxEntries int64 , pageToken string ) ([]* compute .Snapshot , string , error ) {
97
+ func (cloud * FakeCloudProvider ) ListSnapshots (ctx context.Context , filter string , maxEntries int64 , pageToken string ) ([]* computev1 .Snapshot , string , error ) {
99
98
var sourceDisk string
100
- snapshots := []* compute .Snapshot {}
99
+ snapshots := []* computev1 .Snapshot {}
101
100
if len (filter ) > 0 {
102
101
filterSplits := strings .Fields (filter )
103
102
if len (filterSplits ) != 3 || filterSplits [0 ] != "sourceDisk" {
@@ -141,7 +140,7 @@ func (cloud *FakeCloudProvider) ListSnapshots(ctx context.Context, filter string
141
140
max = rem
142
141
}
143
142
144
- results := []* compute .Snapshot {}
143
+ results := []* computev1 .Snapshot {}
145
144
j := startingToken
146
145
for i := 0 ; i < max ; i ++ {
147
146
results = append (results , snapshots [j ])
@@ -200,7 +199,7 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
200
199
var diskToCreate * CloudDisk
201
200
switch volKey .Type () {
202
201
case meta .Zonal :
203
- diskToCreateGA := & compute .Disk {
202
+ diskToCreateGA := & computev1 .Disk {
204
203
Name : volKey .Name ,
205
204
SizeGb : common .BytesToGb (capBytes ),
206
205
Description : "Disk created by GCE-PD CSI Driver" ,
@@ -209,13 +208,13 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
209
208
SourceSnapshotId : snapshotID ,
210
209
}
211
210
if diskEncryptionKmsKey != "" {
212
- diskToCreateGA .DiskEncryptionKey = & compute .CustomerEncryptionKey {
211
+ diskToCreateGA .DiskEncryptionKey = & computev1 .CustomerEncryptionKey {
213
212
KmsKeyName : diskEncryptionKmsKey ,
214
213
}
215
214
}
216
215
diskToCreate = ZonalCloudDisk (diskToCreateGA )
217
216
case meta .Regional :
218
- diskToCreateBeta := & computebeta .Disk {
217
+ diskToCreateV1 := & computev1 .Disk {
219
218
Name : volKey .Name ,
220
219
SizeGb : common .BytesToGb (capBytes ),
221
220
Description : "Regional disk created by GCE-PD CSI Driver" ,
@@ -224,11 +223,11 @@ func (cloud *FakeCloudProvider) InsertDisk(ctx context.Context, volKey *meta.Key
224
223
SourceSnapshotId : snapshotID ,
225
224
}
226
225
if diskEncryptionKmsKey != "" {
227
- diskToCreateBeta .DiskEncryptionKey = & computebeta .CustomerEncryptionKey {
226
+ diskToCreateV1 .DiskEncryptionKey = & computev1 .CustomerEncryptionKey {
228
227
KmsKeyName : diskEncryptionKmsKey ,
229
228
}
230
229
}
231
- diskToCreate = RegionalCloudDisk (diskToCreateBeta )
230
+ diskToCreate = RegionalCloudDisk (diskToCreateV1 )
232
231
default :
233
232
return fmt .Errorf ("could not create disk, key was neither zonal nor regional, instead got: %v" , volKey .String ())
234
233
}
@@ -248,7 +247,7 @@ func (cloud *FakeCloudProvider) DeleteDisk(ctx context.Context, volKey *meta.Key
248
247
func (cloud * FakeCloudProvider ) AttachDisk (ctx context.Context , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string ) error {
249
248
source := cloud .GetDiskSourceURI (volKey )
250
249
251
- attachedDiskV1 := & compute .AttachedDisk {
250
+ attachedDiskV1 := & computev1 .AttachedDisk {
252
251
DeviceName : volKey .Name ,
253
252
Kind : diskKind ,
254
253
Mode : readWrite ,
@@ -309,12 +308,12 @@ func (cloud *FakeCloudProvider) GetReplicaZoneURI(zone string) string {
309
308
}
310
309
311
310
// Instance Methods
312
- func (cloud * FakeCloudProvider ) InsertInstance (instance * compute .Instance , instanceZone , instanceName string ) {
311
+ func (cloud * FakeCloudProvider ) InsertInstance (instance * computev1 .Instance , instanceZone , instanceName string ) {
313
312
cloud .instances [instanceName ] = instance
314
313
return
315
314
}
316
315
317
- func (cloud * FakeCloudProvider ) GetInstanceOrError (ctx context.Context , instanceZone , instanceName string ) (* compute .Instance , error ) {
316
+ func (cloud * FakeCloudProvider ) GetInstanceOrError (ctx context.Context , instanceZone , instanceName string ) (* computev1 .Instance , error ) {
318
317
instance , ok := cloud .instances [instanceName ]
319
318
if ! ok {
320
319
return nil , notFoundError ()
@@ -323,7 +322,7 @@ func (cloud *FakeCloudProvider) GetInstanceOrError(ctx context.Context, instance
323
322
}
324
323
325
324
// Snapshot Methods
326
- func (cloud * FakeCloudProvider ) GetSnapshot (ctx context.Context , snapshotName string ) (* compute .Snapshot , error ) {
325
+ func (cloud * FakeCloudProvider ) GetSnapshot (ctx context.Context , snapshotName string ) (* computev1 .Snapshot , error ) {
327
326
snapshot , ok := cloud .snapshots [snapshotName ]
328
327
if ! ok {
329
328
return nil , notFoundError ()
@@ -332,33 +331,23 @@ func (cloud *FakeCloudProvider) GetSnapshot(ctx context.Context, snapshotName st
332
331
return snapshot , nil
333
332
}
334
333
335
- func (cloud * FakeCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* compute .Snapshot , error ) {
334
+ func (cloud * FakeCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* computev1 .Snapshot , error ) {
336
335
if snapshot , ok := cloud .snapshots [snapshotName ]; ok {
337
336
return snapshot , nil
338
337
}
339
338
340
- var snapshotToCreate * compute.Snapshot
339
+ snapshotToCreate := & computev1.Snapshot {
340
+ Name : snapshotName ,
341
+ DiskSizeGb : int64 (DiskSizeGb ),
342
+ CreationTimestamp : Timestamp ,
343
+ Status : "UPLOADING" ,
344
+ SelfLink : cloud .getGlobalSnapshotURI (snapshotName ),
345
+ }
341
346
switch volKey .Type () {
342
347
case meta .Zonal :
343
- snapshotToCreateGA := & compute.Snapshot {
344
- Name : snapshotName ,
345
- DiskSizeGb : int64 (DiskSizeGb ),
346
- CreationTimestamp : Timestamp ,
347
- Status : "UPLOADING" ,
348
- SelfLink : cloud .getGlobalSnapshotURI (snapshotName ),
349
- SourceDisk : cloud .getZonalDiskSourceURI (volKey .Name , volKey .Zone ),
350
- }
351
- snapshotToCreate = snapshotToCreateGA
348
+ snapshotToCreate .SourceDisk = cloud .getZonalDiskSourceURI (volKey .Name , volKey .Zone )
352
349
case meta .Regional :
353
- snapshotToCreateBeta := & compute.Snapshot {
354
- Name : volKey .Name ,
355
- DiskSizeGb : int64 (DiskSizeGb ),
356
- CreationTimestamp : Timestamp ,
357
- Status : "UPLOADING" ,
358
- SelfLink : cloud .getGlobalSnapshotURI (snapshotName ),
359
- SourceDisk : cloud .getRegionalDiskSourceURI (volKey .Name , volKey .Region ),
360
- }
361
- snapshotToCreate = snapshotToCreateBeta
350
+ snapshotToCreate .SourceDisk = cloud .getRegionalDiskSourceURI (volKey .Name , volKey .Region )
362
351
default :
363
352
return nil , fmt .Errorf ("could not create snapshot, disk key was neither zonal nor regional, instead got: %v" , volKey .String ())
364
353
}
@@ -385,7 +374,7 @@ func (cloud *FakeCloudProvider) DeleteSnapshot(ctx context.Context, snapshotName
385
374
return nil
386
375
}
387
376
388
- func (cloud * FakeCloudProvider ) ValidateExistingSnapshot (resp * compute .Snapshot , volKey * meta.Key ) error {
377
+ func (cloud * FakeCloudProvider ) ValidateExistingSnapshot (resp * computev1 .Snapshot , volKey * meta.Key ) error {
389
378
if resp == nil {
390
379
return fmt .Errorf ("disk does not exist" )
391
380
}
@@ -442,7 +431,7 @@ type FakeBlockingCloudProvider struct {
442
431
// Upon starting a CreateSnapshot, it passes a chan 'executeCreateSnapshot' into readyToExecute, then blocks on executeCreateSnapshot.
443
432
// The test calling this function can block on readyToExecute to ensure that the operation has started and
444
433
// allowed the CreateSnapshot to continue by passing a struct into executeCreateSnapshot.
445
- func (cloud * FakeBlockingCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* compute .Snapshot , error ) {
434
+ func (cloud * FakeBlockingCloudProvider ) CreateSnapshot (ctx context.Context , volKey * meta.Key , snapshotName string ) (* computev1 .Snapshot , error ) {
446
435
executeCreateSnapshot := make (chan struct {})
447
436
cloud .ReadyToExecute <- executeCreateSnapshot
448
437
<- executeCreateSnapshot
0 commit comments