@@ -177,6 +177,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
177
177
// Apply Parameters (case-insensitive). We leave validation of
178
178
// the values to the cloud provider.
179
179
params , err := common .ExtractAndDefaultParameters (req .GetParameters (), gceCS .Driver .name , gceCS .Driver .extraVolumeLabels )
180
+ diskTypeForMetric = params .DiskType
180
181
if err != nil {
181
182
return nil , status .Errorf (codes .InvalidArgument , "failed to extract parameters: %v" , err .Error ())
182
183
}
@@ -280,7 +281,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
280
281
281
282
// Verify that the volume in VolumeContentSource exists.
282
283
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
283
- diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
284
284
if err != nil {
285
285
if gce .IsGCEError (err , "notFound" ) {
286
286
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -337,7 +337,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
337
337
338
338
// Create the disk
339
339
var disk * gce.CloudDisk
340
- diskTypeForMetric = params .DiskType
341
340
switch params .ReplicationType {
342
341
case replicationTypeNone :
343
342
if len (zones ) != 1 {
@@ -395,8 +394,6 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
395
394
}
396
395
397
396
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
398
- disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
399
- diskTypeForMetric = metrics .GetDiskType (disk )
400
397
if err != nil {
401
398
if gce .IsGCENotFoundError (err ) {
402
399
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -409,7 +406,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
409
406
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
410
407
}
411
408
defer gceCS .volumeLocks .Release (volumeID )
412
-
409
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
410
+ diskTypeForMetric = metrics .GetDiskType (disk )
413
411
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
414
412
if err != nil {
415
413
return nil , common .LoggedError ("Failed to delete disk: " , err )
@@ -428,18 +426,17 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
428
426
}
429
427
}()
430
428
// Only valid requests will be accepted
431
- project , volKey , err : = gceCS .validateControllerPublishVolumeRequest (ctx , req )
429
+ _ , _ , err = gceCS .validateControllerPublishVolumeRequest (ctx , req )
432
430
if err != nil {
433
431
return nil , err
434
432
}
435
- diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
436
- diskTypeForMetric = metrics .GetDiskType (diskToPublish )
433
+
437
434
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
438
435
if gceCS .errorBackoff .blocking (backoffId ) {
439
436
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
440
437
}
441
438
442
- resp , err := gceCS .executeControllerPublishVolume (ctx , req )
439
+ resp , err , diskTypeForMetric := gceCS .executeControllerPublishVolume (ctx , req )
443
440
if err != nil {
444
441
klog .Infof ("For node %s adding backoff due to error for volume %s: %v" , req .NodeId , req .VolumeId , err .Error ())
445
442
gceCS .errorBackoff .next (backoffId )
@@ -487,10 +484,11 @@ func parseMachineType(machineTypeUrl string) string {
487
484
return machineType
488
485
}
489
486
490
- func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
487
+ func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error , string ) {
488
+ diskToPublish := ""
491
489
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
492
490
if err != nil {
493
- return nil , err
491
+ return nil , err , diskToPublish
494
492
}
495
493
496
494
volumeID := req .GetVolumeId ()
@@ -505,35 +503,36 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
505
503
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
506
504
if err != nil {
507
505
if gce .IsGCENotFoundError (err ) {
508
- return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
506
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskToPublish
509
507
}
510
- return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err )
508
+ return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskToPublish
511
509
}
512
510
513
511
// Acquires the lock for the volume on that node only, because we need to support the ability
514
512
// to publish the same volume onto different nodes concurrently
515
513
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
516
514
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
517
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
515
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskToPublish
518
516
}
519
517
defer gceCS .volumeLocks .Release (lockingVolumeID )
520
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
518
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
519
+ diskToPublish = metrics .GetDiskType (disk )
521
520
if err != nil {
522
521
if gce .IsGCENotFoundError (err ) {
523
- return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
522
+ return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskToPublish
524
523
}
525
- return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ())
524
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskToPublish
526
525
}
527
526
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
528
527
if err != nil {
529
- return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ())
528
+ return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskToPublish
530
529
}
531
530
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
532
531
if err != nil {
533
532
if gce .IsGCENotFoundError (err ) {
534
- return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
533
+ return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskToPublish
535
534
}
536
- return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
535
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskToPublish
537
536
}
538
537
539
538
readWrite := "READ_WRITE"
@@ -543,21 +542,21 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
543
542
544
543
deviceName , err := common .GetDeviceName (volKey )
545
544
if err != nil {
546
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ())
545
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskToPublish
547
546
}
548
547
549
548
attached , err := diskIsAttachedAndCompatible (deviceName , instance , volumeCapability , readWrite )
550
549
if err != nil {
551
- return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ())
550
+ return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskToPublish
552
551
}
553
552
if attached {
554
553
// Volume is attached to node. Success!
555
554
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v, already attached." , volKey , nodeID )
556
- return pubVolResp , nil
555
+ return pubVolResp , nil , diskToPublish
557
556
}
558
557
instanceZone , instanceName , err = common .NodeIDToZoneAndName (nodeID )
559
558
if err != nil {
560
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ())
559
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskToPublish
561
560
}
562
561
err = gceCS .CloudProvider .AttachDisk (ctx , project , volKey , readWrite , attachableDiskTypePersistent , instanceZone , instanceName )
563
562
if err != nil {
@@ -566,18 +565,18 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
566
565
// If we encountered an UnsupportedDiskError, rewrite the error message to be more user friendly.
567
566
// The error message from GCE is phrased around disk create on VM creation, not runtime attach.
568
567
machineType := parseMachineType (instance .MachineType )
569
- 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 )
568
+ 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 ), diskToPublish
570
569
}
571
- return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
570
+ return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskToPublish
572
571
}
573
572
574
573
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
575
574
if err != nil {
576
- return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
575
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskToPublish
577
576
}
578
577
579
578
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
580
- return pubVolResp , nil
579
+ return pubVolResp , nil , diskToPublish
581
580
}
582
581
583
582
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
@@ -592,14 +591,13 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
592
591
if err != nil {
593
592
return nil , err
594
593
}
595
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
596
- diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
597
594
// Only valid requests will be queued
598
595
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
599
596
if gceCS .errorBackoff .blocking (backoffId ) {
600
597
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
601
598
}
602
-
599
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
600
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
603
601
resp , err := gceCS .executeControllerUnpublishVolume (ctx , req )
604
602
if err != nil {
605
603
klog .Infof ("For node %s adding backoff due to error for volume %s" , req .NodeId , req .VolumeId )
@@ -1200,15 +1198,15 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1200
1198
if err != nil {
1201
1199
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1202
1200
}
1203
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1204
- diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1205
1201
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1206
1202
if err != nil {
1207
1203
if gce .IsGCENotFoundError (err ) {
1208
1204
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1209
1205
}
1210
1206
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1211
1207
}
1208
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1209
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1212
1210
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1213
1211
if err != nil {
1214
1212
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
0 commit comments