@@ -1219,9 +1219,8 @@ func opIsDone(op *computev1.Operation) (bool, error) {
1219
1219
1220
1220
func (cloud * CloudProvider ) GetInstanceOrError (ctx context.Context , instanceZone , instanceName string ) (* computev1.Instance , error ) {
1221
1221
klog .V (5 ).Infof ("Getting instance %v from zone %v" , instanceName , instanceZone )
1222
- svc := cloud .service
1223
1222
project := cloud .project
1224
- instance , err := svc .Instances .Get (project , instanceZone , instanceName ).Do ()
1223
+ instance , err := cloud . service .Instances .Get (project , instanceZone , instanceName ).Do ()
1225
1224
if err != nil {
1226
1225
return nil , err
1227
1226
}
@@ -1230,9 +1229,9 @@ func (cloud *CloudProvider) GetInstanceOrError(ctx context.Context, instanceZone
1230
1229
1231
1230
func (cloud * CloudProvider ) GetSnapshot (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
1232
1231
klog .V (5 ).Infof ("Getting snapshot %v" , snapshotName )
1233
- svc := cloud .service
1234
- snapshot , err := svc .Snapshots .Get (project , snapshotName ).Context (ctx ).Do ()
1232
+ snapshot , err := cloud .service .Snapshots .Get (project , snapshotName ).Context (ctx ).Do ()
1235
1233
if err != nil {
1234
+ klog .V (5 ).Infof ("Error getting snapshot %v: %v" , snapshotName , err )
1236
1235
return nil , err
1237
1236
}
1238
1237
return snapshot , nil
@@ -1268,15 +1267,34 @@ func (cloud *CloudProvider) CreateSnapshot(ctx context.Context, project string,
1268
1267
if description == "" {
1269
1268
description = "Snapshot created by GCE-PD CSI Driver"
1270
1269
}
1271
- return cloud .createZonalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1272
1270
case meta .Regional :
1273
1271
if description == "" {
1274
1272
description = "Regional Snapshot created by GCE-PD CSI Driver"
1275
1273
}
1276
- return cloud .createRegionalDiskSnapshot (ctx , project , volKey , snapshotName , snapshotParams , description )
1277
1274
default :
1278
1275
return nil , fmt .Errorf ("could not create snapshot, key was neither zonal nor regional, instead got: %v" , volKey .String ())
1279
1276
}
1277
+
1278
+ snapshotToCreate := & computev1.Snapshot {
1279
+ Name : snapshotName ,
1280
+ StorageLocations : snapshotParams .StorageLocations ,
1281
+ Description : description ,
1282
+ Labels : snapshotParams .Labels ,
1283
+ SourceDisk : cloud .GetDiskSourceURI (project , volKey ),
1284
+ }
1285
+ _ , err = cloud .service .Snapshots .Insert (project , snapshotToCreate ).Context (ctx ).Do ()
1286
+
1287
+ if err != nil {
1288
+ return nil , err
1289
+ }
1290
+
1291
+ snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1292
+
1293
+ if err == nil {
1294
+ err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1295
+ }
1296
+
1297
+ return snapshot , err
1280
1298
}
1281
1299
1282
1300
func (cloud * CloudProvider ) CreateImage (ctx context.Context , project string , volKey * meta.Key , imageName string , snapshotParams common.SnapshotParameters ) (* computev1.Image , error ) {
@@ -1452,52 +1470,6 @@ func (cloud *CloudProvider) resizeRegionalDisk(ctx context.Context, project stri
1452
1470
return requestGb , nil
1453
1471
}
1454
1472
1455
- func (cloud * CloudProvider ) createZonalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1456
- snapshotToCreate := & computev1.Snapshot {
1457
- Name : snapshotName ,
1458
- StorageLocations : snapshotParams .StorageLocations ,
1459
- Description : description ,
1460
- Labels : snapshotParams .Labels ,
1461
- }
1462
-
1463
- _ , err := cloud .service .Disks .CreateSnapshot (project , volKey .Zone , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
1464
-
1465
- if err != nil {
1466
- return nil , err
1467
- }
1468
-
1469
- snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1470
-
1471
- if err == nil {
1472
- err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1473
- }
1474
-
1475
- return snapshot , err
1476
- }
1477
-
1478
- func (cloud * CloudProvider ) createRegionalDiskSnapshot (ctx context.Context , project string , volKey * meta.Key , snapshotName string , snapshotParams common.SnapshotParameters , description string ) (* computev1.Snapshot , error ) {
1479
- snapshotToCreate := & computev1.Snapshot {
1480
- Name : snapshotName ,
1481
- StorageLocations : snapshotParams .StorageLocations ,
1482
- Description : description ,
1483
- Labels : snapshotParams .Labels ,
1484
- }
1485
-
1486
- _ , err := cloud .service .RegionDisks .CreateSnapshot (project , volKey .Region , volKey .Name , snapshotToCreate ).Context (ctx ).Do ()
1487
- if err != nil {
1488
- return nil , err
1489
- }
1490
-
1491
- snapshot , err := cloud .waitForSnapshotCreation (ctx , project , snapshotName )
1492
-
1493
- if err == nil {
1494
- err = cloud .attachTagsToResource (ctx , snapshotParams .ResourceTags , project , snapshot .Id , snapshotsType , "" , false , resourceManagerHostSubPath )
1495
- }
1496
-
1497
- return snapshot , err
1498
-
1499
- }
1500
-
1501
1473
func (cloud * CloudProvider ) waitForSnapshotCreation (ctx context.Context , project , snapshotName string ) (* computev1.Snapshot , error ) {
1502
1474
ticker := time .NewTicker (time .Second )
1503
1475
defer ticker .Stop ()
@@ -1513,7 +1485,7 @@ func (cloud *CloudProvider) waitForSnapshotCreation(ctx context.Context, project
1513
1485
klog .Warningf ("Error in getting snapshot %s, %v" , snapshotName , err .Error ())
1514
1486
} else if snapshot != nil {
1515
1487
if snapshot .Status != "CREATING" {
1516
- klog .V (6 ).Infof ("Snapshot %s status is %s" , snapshotName , snapshot .Status )
1488
+ klog .V (5 ).Infof ("Snapshot %s status is %s" , snapshotName , snapshot .Status )
1517
1489
return snapshot , nil
1518
1490
} else {
1519
1491
klog .V (6 ).Infof ("Snapshot %s is still creating ..." , snapshotName )
0 commit comments