@@ -122,7 +122,7 @@ const (
122
122
123
123
replicationTypeNone = "none"
124
124
replicationTypeRegionalPD = "regional-pd"
125
-
125
+ diskNotFound = ""
126
126
// The maximum number of entries that we can include in the
127
127
// ListVolumesResposne
128
128
// In reality, the limit here is 4MB (based on gRPC client response limits),
@@ -277,7 +277,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
277
277
existingDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gceAPIVersion )
278
278
if err != nil {
279
279
if ! gce .IsGCEError (err , "notFound" ) {
280
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
280
+ return nil , common .LoggedError ("CreateVolume, failed to getDisk when validating: " , err )
281
281
}
282
282
}
283
283
if err == nil {
@@ -333,7 +333,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
333
333
if gce .IsGCEError (err , "notFound" ) {
334
334
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
335
335
} else {
336
- return nil , common .LoggedError ("CreateVolume unknown get disk error when validating: " , err )
336
+ return nil , common .LoggedError ("CreateVolume, getDisk error when validating: " , err )
337
337
}
338
338
}
339
339
@@ -393,9 +393,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
393
393
disk , err = createSingleZoneDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
394
394
if err != nil {
395
395
// Emit metric for expected disk type from storage class
396
- if params .DiskType != "" {
397
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
398
- }
396
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
399
397
return nil , common .LoggedError ("CreateVolume failed to create single zonal disk " + name + ": " , err )
400
398
}
401
399
case replicationTypeRegionalPD :
@@ -405,9 +403,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
405
403
disk , err = createRegionalDisk (ctx , gceCS .CloudProvider , name , zones , params , capacityRange , capBytes , snapshotID , volumeContentSourceVolumeID , multiWriter )
406
404
if err != nil {
407
405
// Emit metric for expected disk type from storage class
408
- if params .DiskType != "" {
409
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
410
- }
406
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
411
407
return nil , common .LoggedError ("CreateVolume failed to create regional disk " + name + ": " , err )
412
408
}
413
409
default :
@@ -417,9 +413,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
417
413
ready , err := isDiskReady (disk )
418
414
if err != nil {
419
415
// Emit metric for expected disk type from storage class as the disk is not ready and might not have PD type populated
420
- if params .DiskType != "" {
421
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
422
- }
416
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateVolume" , err , params .DiskType )
423
417
return nil , status .Errorf (codes .Internal , "CreateVolume disk %v had error checking ready status: %v" , volKey , err .Error ())
424
418
}
425
419
if ! ready {
@@ -462,7 +456,7 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
462
456
463
457
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
464
458
if err != nil {
465
- return nil , common .LoggedError ("unknown Delete disk error : " , err )
459
+ return nil , common .LoggedError ("Failed to delete disk : " , err )
466
460
}
467
461
468
462
klog .V (4 ).Infof ("DeleteVolume succeeded for disk %v" , volKey )
@@ -562,10 +556,11 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
562
556
defer gceCS .volumeLocks .Release (lockingVolumeID )
563
557
diskToPublish , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
564
558
if err != nil {
559
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskNotFound )
565
560
if gce .IsGCENotFoundError (err ) {
566
561
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
567
562
}
568
- return nil , status .Errorf (codes .Internal , "Unknown get disk error : %v" , err .Error ())
563
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk : %v" , err .Error ())
569
564
}
570
565
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
571
566
if err != nil {
@@ -576,7 +571,7 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
576
571
if gce .IsGCENotFoundError (err ) {
577
572
return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
578
573
}
579
- return nil , status .Errorf (codes .Internal , "Unknown get instance error : %v" , err .Error ())
574
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
580
575
}
581
576
582
577
readWrite := "READ_WRITE"
@@ -612,16 +607,17 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
612
607
return nil , status .Errorf (codes .InvalidArgument , "'%s' is not a compatible disk type with the machine type %s, please review the GCP online documentation for available persistent disk options" , udErr .DiskType , machineType )
613
608
}
614
609
// Emit metric for error
615
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
616
- return nil , status .Errorf (codes .Internal , "unknown Attach error : %v" , err .Error ())
610
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
611
+ return nil , status .Errorf (codes .Internal , "Failed to Attach : %v" , err .Error ())
617
612
}
618
613
619
614
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
620
615
if err != nil {
621
616
// Emit metric for error
622
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , diskToPublish . GetPDType ( ))
623
- return nil , status .Errorf (codes .Internal , "unknown WaitForAttach error : %v" , err .Error ())
617
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerPublishVolume" , err , metrics . GetDiskType ( diskToPublish ))
618
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach : %v" , err .Error ())
624
619
}
620
+
625
621
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
626
622
return pubVolResp , nil
627
623
}
@@ -721,15 +717,13 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
721
717
}
722
718
diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
723
719
if err != nil {
724
- common .LoggedError ("Unknown get disk error: " , err )
720
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskNotFound )
721
+ common .LoggedError ("Failed to getDisk: " , err )
725
722
}
726
723
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
727
724
if err != nil {
728
- //Do not emit metric if disk is unknown
729
- if diskToUnpublish != nil {
730
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskToUnpublish .GetPDType ())
731
- }
732
- return nil , common .LoggedError ("unknown detach error: " , err )
725
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , metrics .GetDiskType (diskToUnpublish ))
726
+ return nil , common .LoggedError ("Failed to detach: " , err )
733
727
}
734
728
735
729
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
@@ -767,7 +761,7 @@ func (gceCS *GCEControllerServer) ValidateVolumeCapabilities(ctx context.Context
767
761
if gce .IsGCENotFoundError (err ) {
768
762
return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .Name , err .Error ())
769
763
}
770
- return nil , common .LoggedError ("Unknown get disk error : " , err )
764
+ return nil , common .LoggedError ("Failed to getDisk : " , err )
771
765
}
772
766
773
767
// Check Volume Context is Empty
@@ -830,7 +824,7 @@ func (gceCS *GCEControllerServer) ListVolumes(ctx context.Context, req *csi.List
830
824
if gce .IsGCEInvalidError (err ) {
831
825
return nil , status .Errorf (codes .Aborted , "ListVolumes error with invalid request: %v" , err .Error ())
832
826
}
833
- return nil , common .LoggedError ("Unknown list disk error : " , err )
827
+ return nil , common .LoggedError ("Failed to list disk: " , err )
834
828
}
835
829
gceCS .disks = diskList
836
830
gceCS .seen = map [string ]int {}
@@ -913,7 +907,7 @@ func (gceCS *GCEControllerServer) CreateSnapshot(ctx context.Context, req *csi.C
913
907
if gce .IsGCENotFoundError (err ) {
914
908
return nil , status .Errorf (codes .NotFound , "CreateSnapshot could not find disk %v: %v" , volKey .String (), err .Error ())
915
909
}
916
- return nil , common .LoggedError ("CreateSnapshot unknown get disk error : " , err )
910
+ return nil , common .LoggedError ("CreateSnapshot, failed to getDisk : " , err )
917
911
}
918
912
919
913
snapshotParams , err := common .ExtractAndDefaultSnapshotParameters (req .GetParameters (), gceCS .Driver .name )
@@ -948,35 +942,30 @@ func (gceCS *GCEControllerServer) createPDSnapshot(ctx context.Context, project
948
942
}
949
943
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , gceCS .CloudProvider .GetDefaultProject (), volKey , gce .GCEAPIVersionV1 )
950
944
if err != nil {
951
- common .LoggedError ("Unknown get disk error : " , err )
945
+ common .LoggedError ("Failed to getDisk : " , err )
952
946
}
953
947
// Check if PD snapshot already exists
954
948
var snapshot * compute.Snapshot
955
949
snapshot , err = gceCS .CloudProvider .GetSnapshot (ctx , project , snapshotName )
956
950
if err != nil {
957
951
if ! gce .IsGCEError (err , "notFound" ) {
958
- return nil , status .Errorf (codes .Internal , "Unknown get snapshot error : %v" , err .Error ())
952
+ return nil , status .Errorf (codes .Internal , "Failed to get snapshot: %v" , err .Error ())
959
953
}
960
954
// If we could not find the snapshot, we create a new one
961
955
snapshot , err = gceCS .CloudProvider .CreateSnapshot (ctx , project , volKey , snapshotName , snapshotParams )
962
956
if err != nil {
963
957
if gce .IsGCEError (err , "notFound" ) {
958
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , diskNotFound )
964
959
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
965
960
}
966
- //Do not emit metric if disk is unknown
967
- if sourceDisk != nil {
968
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
969
- }
970
- return nil , common .LoggedError ("Unknown create snapshot error: " , err )
961
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
962
+ return nil , common .LoggedError ("Failed to create snapshot: " , err )
971
963
}
972
964
}
973
965
974
966
err = gceCS .validateExistingSnapshot (snapshot , volKey )
975
967
if err != nil {
976
- //Do not emit metric if disk is unknown
977
- if sourceDisk != nil {
978
- gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , sourceDisk .GetPDType ())
979
- }
968
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("CreateSnapshot" , err , metrics .GetDiskType (sourceDisk ))
980
969
return nil , status .Errorf (codes .AlreadyExists , "Error in creating snapshot: %v" , err .Error ())
981
970
}
982
971
@@ -1010,15 +999,15 @@ func (gceCS *GCEControllerServer) createImage(ctx context.Context, project strin
1010
999
image , err = gceCS .CloudProvider .GetImage (ctx , project , imageName )
1011
1000
if err != nil {
1012
1001
if ! gce .IsGCEError (err , "notFound" ) {
1013
- return nil , common .LoggedError ("Unknown get image error : " , err )
1002
+ return nil , common .LoggedError ("Failed to get image: " , err )
1014
1003
}
1015
1004
// create a new image
1016
1005
image , err = gceCS .CloudProvider .CreateImage (ctx , project , volKey , imageName , snapshotParams )
1017
1006
if err != nil {
1018
1007
if gce .IsGCEError (err , "notFound" ) {
1019
1008
return nil , status .Errorf (codes .NotFound , "Could not find volume with ID %v: %v" , volKey .String (), err .Error ())
1020
1009
}
1021
- return nil , common .LoggedError ("Unknown create image error : " , err )
1010
+ return nil , common .LoggedError ("Failed to create image: " , err )
1022
1011
}
1023
1012
}
1024
1013
@@ -1148,12 +1137,12 @@ func (gceCS *GCEControllerServer) DeleteSnapshot(ctx context.Context, req *csi.D
1148
1137
case common .DiskSnapshotType :
1149
1138
err = gceCS .CloudProvider .DeleteSnapshot (ctx , project , key )
1150
1139
if err != nil {
1151
- return nil , common .LoggedError ("unknown Delete snapshot error : " , err )
1140
+ return nil , common .LoggedError ("Failed to DeleteSnapshot : " , err )
1152
1141
}
1153
1142
case common .DiskImageType :
1154
1143
err = gceCS .CloudProvider .DeleteImage (ctx , project , key )
1155
1144
if err != nil {
1156
- return nil , common .LoggedError ("unknown Delete image error: " , err )
1145
+ return nil , common .LoggedError ("Failed to DeleteImage error: " , err )
1157
1146
}
1158
1147
default :
1159
1148
return nil , status .Errorf (codes .InvalidArgument , "unknown snapshot type %s" , snapshotType )
@@ -1185,7 +1174,7 @@ func (gceCS *GCEControllerServer) ListSnapshots(ctx context.Context, req *csi.Li
1185
1174
if gce .IsGCEInvalidError (err ) {
1186
1175
return nil , status .Errorf (codes .Aborted , "ListSnapshots error with invalid request: %v" , err .Error ())
1187
1176
}
1188
- return nil , common .LoggedError ("Unknown list snapshots error : " , err )
1177
+ return nil , common .LoggedError ("Failed to list snapshots: " , err )
1189
1178
}
1190
1179
gceCS .snapshots = snapshotList
1191
1180
gceCS .snapshotTokens = map [string ]int {}
@@ -1231,21 +1220,19 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1231
1220
1232
1221
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1233
1222
if err != nil {
1223
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , diskNotFound )
1234
1224
if gce .IsGCENotFoundError (err ) {
1235
1225
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1236
1226
}
1237
1227
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1238
1228
}
1239
1229
sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1240
1230
if err != nil {
1241
- common .LoggedError ("Unknown get disk error : " , err )
1231
+ common .LoggedError ("Failed to getDisk : " , err )
1242
1232
}
1243
1233
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1244
1234
if err != nil {
1245
- //Do not emit metric if disk is unknown
1246
- if sourceDisk != nil {
1247
- gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , sourceDisk .GetPDType ())
1248
- }
1235
+ defer gceCS .Metrics .RecordOperationErrorMetrics ("ControllerExpandVolume" , err , metrics .GetDiskType (sourceDisk ))
1249
1236
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
1250
1237
}
1251
1238
@@ -1269,15 +1256,15 @@ func (gceCS *GCEControllerServer) getSnapshots(ctx context.Context, req *csi.Lis
1269
1256
if gce .IsGCEError (err , "invalid" ) {
1270
1257
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1271
1258
}
1272
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1259
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1273
1260
}
1274
1261
1275
1262
images , _ , err = gceCS .CloudProvider .ListImages (ctx , filter )
1276
1263
if err != nil {
1277
1264
if gce .IsGCEError (err , "invalid" ) {
1278
1265
return nil , status .Errorf (codes .Aborted , "Invalid error: %v" , err .Error ())
1279
1266
}
1280
- return nil , common .LoggedError ("Unknown list image error : " , err )
1267
+ return nil , common .LoggedError ("Failed to list image: " , err )
1281
1268
}
1282
1269
1283
1270
entries := []* csi.ListSnapshotsResponse_Entry {}
@@ -1318,7 +1305,7 @@ func (gceCS *GCEControllerServer) getSnapshotByID(ctx context.Context, snapshotI
1318
1305
// return empty list if no snapshot is found
1319
1306
return & csi.ListSnapshotsResponse {}, nil
1320
1307
}
1321
- return nil , common .LoggedError ("Unknown list snapshot error : " , err )
1308
+ return nil , common .LoggedError ("Failed to list snapshot: " , err )
1322
1309
}
1323
1310
e , err := generateDiskSnapshotEntry (snapshot )
1324
1311
if err != nil {
0 commit comments