@@ -225,6 +225,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
225
225
// Apply Parameters (case-insensitive). We leave validation of
226
226
// the values to the cloud provider.
227
227
params , err := common .ExtractAndDefaultParameters (req .GetParameters (), gceCS .Driver .name , gceCS .Driver .extraVolumeLabels )
228
+ diskTypeForMetric = params .DiskType
228
229
if err != nil {
229
230
return nil , status .Errorf (codes .InvalidArgument , "failed to extract parameters: %v" , err .Error ())
230
231
}
@@ -337,7 +338,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
337
338
338
339
// Verify that the volume in VolumeContentSource exists.
339
340
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
340
- diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
341
341
if err != nil {
342
342
if gce .IsGCEError (err , "notFound" ) {
343
343
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -394,7 +394,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
394
394
395
395
// Create the disk
396
396
var disk * gce.CloudDisk
397
- diskTypeForMetric = params .DiskType
398
397
switch params .ReplicationType {
399
398
case replicationTypeNone :
400
399
if len (zones ) != 1 {
@@ -452,8 +451,6 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
452
451
}
453
452
454
453
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
455
- disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
456
- diskTypeForMetric = metrics .GetDiskType (disk )
457
454
if err != nil {
458
455
if gce .IsGCENotFoundError (err ) {
459
456
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -466,7 +463,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
466
463
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
467
464
}
468
465
defer gceCS .volumeLocks .Release (volumeID )
469
-
466
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
467
+ diskTypeForMetric = metrics .GetDiskType (disk )
470
468
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
471
469
if err != nil {
472
470
return nil , common .LoggedError ("Failed to delete disk: " , err )
@@ -485,18 +483,17 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
485
483
}
486
484
}()
487
485
// Only valid requests will be accepted
488
- project , volKey , err : = gceCS .validateControllerPublishVolumeRequest (ctx , req )
486
+ _ , _ , err = gceCS .validateControllerPublishVolumeRequest (ctx , req )
489
487
if err != nil {
490
488
return nil , err
491
489
}
492
- diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
493
- diskTypeForMetric = metrics .GetDiskType (diskToPublish )
490
+
494
491
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
495
492
if gceCS .errorBackoff .blocking (backoffId ) {
496
493
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
497
494
}
498
495
499
- resp , err := gceCS .executeControllerPublishVolume (ctx , req )
496
+ resp , err , diskTypeForMetric := gceCS .executeControllerPublishVolume (ctx , req )
500
497
if err != nil {
501
498
klog .Infof ("For node %s adding backoff due to error for volume %s: %v" , req .NodeId , req .VolumeId , err .Error ())
502
499
gceCS .errorBackoff .next (backoffId )
@@ -544,10 +541,11 @@ func parseMachineType(machineTypeUrl string) string {
544
541
return machineType
545
542
}
546
543
547
- func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
544
+ func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error , string ) {
545
+ diskToPublish := ""
548
546
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
549
547
if err != nil {
550
- return nil , err
548
+ return nil , err , diskToPublish
551
549
}
552
550
553
551
volumeID := req .GetVolumeId ()
@@ -562,35 +560,36 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
562
560
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
563
561
if err != nil {
564
562
if gce .IsGCENotFoundError (err ) {
565
- return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
563
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskToPublish
566
564
}
567
- return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err )
565
+ return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskToPublish
568
566
}
569
567
570
568
// Acquires the lock for the volume on that node only, because we need to support the ability
571
569
// to publish the same volume onto different nodes concurrently
572
570
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
573
571
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
574
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
572
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskToPublish
575
573
}
576
574
defer gceCS .volumeLocks .Release (lockingVolumeID )
577
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
575
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
576
+ diskToPublish = metrics .GetDiskType (disk )
578
577
if err != nil {
579
578
if gce .IsGCENotFoundError (err ) {
580
- return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
579
+ return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskToPublish
581
580
}
582
- return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ())
581
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskToPublish
583
582
}
584
583
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
585
584
if err != nil {
586
- return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ())
585
+ return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskToPublish
587
586
}
588
587
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
589
588
if err != nil {
590
589
if gce .IsGCENotFoundError (err ) {
591
- return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
590
+ return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskToPublish
592
591
}
593
- return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
592
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskToPublish
594
593
}
595
594
596
595
readWrite := "READ_WRITE"
@@ -600,21 +599,21 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
600
599
601
600
deviceName , err := common .GetDeviceName (volKey )
602
601
if err != nil {
603
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ())
602
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskToPublish
604
603
}
605
604
606
605
attached , err := diskIsAttachedAndCompatible (deviceName , instance , volumeCapability , readWrite )
607
606
if err != nil {
608
- return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ())
607
+ return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskToPublish
609
608
}
610
609
if attached {
611
610
// Volume is attached to node. Success!
612
611
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v, already attached." , volKey , nodeID )
613
- return pubVolResp , nil
612
+ return pubVolResp , nil , diskToPublish
614
613
}
615
614
instanceZone , instanceName , err = common .NodeIDToZoneAndName (nodeID )
616
615
if err != nil {
617
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ())
616
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskToPublish
618
617
}
619
618
err = gceCS .CloudProvider .AttachDisk (ctx , project , volKey , readWrite , attachableDiskTypePersistent , instanceZone , instanceName )
620
619
if err != nil {
@@ -623,18 +622,18 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
623
622
// If we encountered an UnsupportedDiskError, rewrite the error message to be more user friendly.
624
623
// The error message from GCE is phrased around disk create on VM creation, not runtime attach.
625
624
machineType := parseMachineType (instance .MachineType )
626
- 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 )
625
+ 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
627
626
}
628
- return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
627
+ return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskToPublish
629
628
}
630
629
631
630
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
632
631
if err != nil {
633
- return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
632
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskToPublish
634
633
}
635
634
636
635
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
637
- return pubVolResp , nil
636
+ return pubVolResp , nil , diskToPublish
638
637
}
639
638
640
639
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
@@ -649,14 +648,13 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
649
648
if err != nil {
650
649
return nil , err
651
650
}
652
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
653
- diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
654
651
// Only valid requests will be queued
655
652
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
656
653
if gceCS .errorBackoff .blocking (backoffId ) {
657
654
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
658
655
}
659
-
656
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
657
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
660
658
resp , err := gceCS .executeControllerUnpublishVolume (ctx , req )
661
659
if err != nil {
662
660
klog .Infof ("For node %s adding backoff due to error for volume %s" , req .NodeId , req .VolumeId )
@@ -1257,15 +1255,15 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1257
1255
if err != nil {
1258
1256
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1259
1257
}
1260
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1261
- diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1262
1258
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1263
1259
if err != nil {
1264
1260
if gce .IsGCENotFoundError (err ) {
1265
1261
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1266
1262
}
1267
1263
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1268
1264
}
1265
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1266
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1269
1267
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1270
1268
if err != nil {
1271
1269
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
0 commit comments