@@ -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,9 +1274,9 @@ 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 {
1279
+ klog .V (5 ).Infof ("Error getting snapshot %v: %v" , snapshotName , err )
1281
1280
return nil , err
1282
1281
}
1283
1282
return snapshot , nil
@@ -1313,15 +1312,34 @@ func (cloud *CloudProvider) CreateSnapshot(ctx context.Context, project string,
1313
1312
if description == "" {
1314
1313
description = "Snapshot created by GCE-PD CSI Driver"
1315
1314
}
1316
- return cloud .createZonalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1317
1315
case meta .Regional :
1318
1316
if description == "" {
1319
1317
description = "Regional Snapshot created by GCE-PD CSI Driver"
1320
1318
}
1321
- return cloud .createRegionalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1322
1319
default :
1323
1320
return nil , fmt .Errorf ("could not create snapshot, key was neither zonal nor regional, instead got: %v" , volKey .String ())
1324
1321
}
1322
+
1323
+ snapshotToCreate := & computev1.Snapshot {
1324
+ Name : snapshotName ,
1325
+ StorageLocations : snapshotParams .StorageLocations ,
1326
+ Description : description ,
1327
+ Labels : snapshotParams .Labels ,
1328
+ SourceDisk : cloud .GetDiskSourceURI (project , volKey ),
1329
+ }
1330
+ _ , err = cloud .service .Snapshots .Insert (project , snapshotToCreate ).Context (ctx ).Do ()
1331
+
1332
+ if err != nil {
1333
+ return nil , err
1334
+ }
1335
+
1336
+ snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1337
+
1338
+ if err == nil {
1339
+ err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1340
+ }
1341
+
1342
+ return snapshot , err
1325
1343
}
1326
1344
1327
1345
func (cloud * CloudProvider ) CreateImage (ctx context.Context , project string , volKey * meta.Key , imageName string , snapshotParams common.SnapshotParameters ) (* computev1.Image , error ) {
@@ -1497,52 +1515,6 @@ func (cloud *CloudProvider) resizeRegionalDisk(ctx context.Context, project stri
1497
1515
return requestGb , nil
1498
1516
}
1499
1517
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
1518
func (cloud * CloudProvider ) waitForSnapshotCreation (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
1547
1519
ticker := time .NewTicker (time .Second )
1548
1520
defer ticker .Stop ()
@@ -1558,7 +1530,7 @@ func (cloud *CloudProvider) waitForSnapshotCreation(ctx context.Context, project
1558
1530
klog .Warningf ("Error in getting snapshot %s, %v" , snapshotName , err .Error ())
1559
1531
} else if snapshot != nil {
1560
1532
if snapshot .Status != "CREATING" {
1561
- klog .V (6 ).Infof ("Snapshot %s status is %s" , snapshotName , snapshot .Status )
1533
+ klog .V (5 ).Infof ("Snapshot %s status is %s" , snapshotName , snapshot .Status )
1562
1534
return snapshot , nil
1563
1535
} else {
1564
1536
klog .V (6 ).Infof ("Snapshot %s is still creating ..." , snapshotName )
0 commit comments