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