@@ -1264,9 +1264,8 @@ func opIsDone(op *computev1.Operation) (bool, error) {
1264
1264
1265
1265
func (cloud * CloudProvider ) GetInstanceOrError (ctx context.Context , instanceZone , instanceName string ) (* computev1.Instance , error ) {
1266
1266
klog .V (5 ).Infof ("Getting instance %v from zone %v" , instanceName , instanceZone )
1267
- svc := cloud .service
1268
1267
project := cloud .project
1269
- instance , err := svc .Instances .Get (project , instanceZone , instanceName ).Do ()
1268
+ instance , err := cloud . service .Instances .Get (project , instanceZone , instanceName ).Do ()
1270
1269
if err != nil {
1271
1270
return nil , err
1272
1271
}
@@ -1275,8 +1274,7 @@ func (cloud *CloudProvider) GetInstanceOrError(ctx context.Context, instanceZone
1275
1274
1276
1275
func (cloud * CloudProvider ) GetSnapshot (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
1277
1276
klog .V (5 ).Infof ("Getting snapshot %v" , snapshotName )
1278
- svc := cloud .service
1279
- snapshot , err := svc .Snapshots .Get (project , snapshotName ).Context (ctx ).Do ()
1277
+ snapshot , err := cloud .service .Snapshots .Get (project , snapshotName ).Context (ctx ).Do ()
1280
1278
if err != nil {
1281
1279
return nil , err
1282
1280
}
@@ -1313,15 +1311,34 @@ func (cloud *CloudProvider) CreateSnapshot(ctx context.Context, project string,
1313
1311
if description == "" {
1314
1312
description = "Snapshot created by GCE-PD CSI Driver"
1315
1313
}
1316
- return cloud .createZonalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1317
1314
case meta .Regional :
1318
1315
if description == "" {
1319
1316
description = "Regional Snapshot created by GCE-PD CSI Driver"
1320
1317
}
1321
- return cloud .createRegionalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1322
1318
default :
1323
1319
return nil , fmt .Errorf ("could not create snapshot, key was neither zonal nor regional, instead got: %v" , volKey .String ())
1324
1320
}
1321
+
1322
+ snapshotToCreate := & computev1.Snapshot {
1323
+ Name : snapshotName ,
1324
+ StorageLocations : snapshotParams .StorageLocations ,
1325
+ Description : description ,
1326
+ Labels : snapshotParams .Labels ,
1327
+ SourceDisk : cloud .GetDiskSourceURI (project , volKey ),
1328
+ }
1329
+ _ , err = cloud .service .Snapshots .Insert (project , snapshotToCreate ).Context (ctx ).Do ()
1330
+
1331
+ if err != nil {
1332
+ return nil , err
1333
+ }
1334
+
1335
+ snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1336
+
1337
+ if err == nil {
1338
+ err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1339
+ }
1340
+
1341
+ return snapshot , err
1325
1342
}
1326
1343
1327
1344
func (cloud * CloudProvider ) CreateImage (ctx context.Context , project string , volKey * meta.Key , imageName string , snapshotParams common.SnapshotParameters ) (* computev1.Image , error ) {
@@ -1497,52 +1514,6 @@ func (cloud *CloudProvider) resizeRegionalDisk(ctx context.Context, project stri
1497
1514
return requestGb , nil
1498
1515
}
1499
1516
1500
- func (cloud * CloudProvider ) createZonalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1501
- snapshotToCreate := & computev1.Snapshot {
1502
- Name : snapshotName ,
1503
- StorageLocations : snapshotParams .StorageLocations ,
1504
- Description : description ,
1505
- Labels : snapshotParams .Labels ,
1506
- }
1507
-
1508
- _ , err := cloud .service .Disks .CreateSnapshot (project , volKey .Zone , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
1509
-
1510
- if err != nil {
1511
- return nil , err
1512
- }
1513
-
1514
- snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1515
-
1516
- if err == nil {
1517
- err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1518
- }
1519
-
1520
- return snapshot , err
1521
- }
1522
-
1523
- func (cloud * CloudProvider ) createRegionalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1524
- snapshotToCreate := & computev1.Snapshot {
1525
- Name : snapshotName ,
1526
- StorageLocations : snapshotParams .StorageLocations ,
1527
- Description : description ,
1528
- Labels : snapshotParams .Labels ,
1529
- }
1530
-
1531
- _ , err := cloud .service .RegionDisks .CreateSnapshot (project , volKey .Region , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
1532
- if err != nil {
1533
- return nil , err
1534
- }
1535
-
1536
- snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1537
-
1538
- if err == nil {
1539
- err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1540
- }
1541
-
1542
- return snapshot , err
1543
-
1544
- }
1545
-
1546
1517
func (cloud * CloudProvider ) waitForSnapshotCreation (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
1547
1518
ticker := time .NewTicker (time .Second )
1548
1519
defer ticker .Stop ()
0 commit comments