@@ -232,6 +232,7 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
232
232
// Apply Parameters (case-insensitive). We leave validation of
233
233
// the values to the cloud provider.
234
234
params , err := common .ExtractAndDefaultParameters (req .GetParameters (), gceCS .Driver .name , gceCS .Driver .extraVolumeLabels )
235
+ diskTypeForMetric = params .DiskType
235
236
if err != nil {
236
237
return nil , status .Errorf (codes .InvalidArgument , "failed to extract parameters: %v" , err .Error ())
237
238
}
@@ -344,7 +345,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
344
345
345
346
// Verify that the volume in VolumeContentSource exists.
346
347
diskFromSourceVolume , err := gceCS .CloudProvider .GetDisk (ctx , project , sourceVolKey , gceAPIVersion )
347
- diskTypeForMetric = metrics .GetDiskType (diskFromSourceVolume )
348
348
if err != nil {
349
349
if gce .IsGCEError (err , "notFound" ) {
350
350
return nil , status .Errorf (codes .NotFound , "CreateVolume source volume %s does not exist" , volumeContentSourceVolumeID )
@@ -401,7 +401,6 @@ func (gceCS *GCEControllerServer) CreateVolume(ctx context.Context, req *csi.Cre
401
401
402
402
// Create the disk
403
403
var disk * gce.CloudDisk
404
- diskTypeForMetric = params .DiskType
405
404
switch params .ReplicationType {
406
405
case replicationTypeNone :
407
406
if len (zones ) != 1 {
@@ -459,8 +458,6 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
459
458
}
460
459
461
460
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
462
- disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
463
- diskTypeForMetric = metrics .GetDiskType (disk )
464
461
if err != nil {
465
462
if gce .IsGCENotFoundError (err ) {
466
463
klog .Warningf ("DeleteVolume treating volume as deleted because cannot find volume %v: %v" , volumeID , err .Error ())
@@ -473,7 +470,8 @@ func (gceCS *GCEControllerServer) DeleteVolume(ctx context.Context, req *csi.Del
473
470
return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , volumeID )
474
471
}
475
472
defer gceCS .volumeLocks .Release (volumeID )
476
-
473
+ disk , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
474
+ diskTypeForMetric = metrics .GetDiskType (disk )
477
475
err = gceCS .CloudProvider .DeleteDisk (ctx , project , volKey )
478
476
if err != nil {
479
477
return nil , common .LoggedError ("Failed to delete disk: " , err )
@@ -492,18 +490,17 @@ func (gceCS *GCEControllerServer) ControllerPublishVolume(ctx context.Context, r
492
490
}
493
491
}()
494
492
// Only valid requests will be accepted
495
- project , volKey , err : = gceCS .validateControllerPublishVolumeRequest (ctx , req )
493
+ _ , _ , err = gceCS .validateControllerPublishVolumeRequest (ctx , req )
496
494
if err != nil {
497
495
return nil , err
498
496
}
499
- diskToPublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
500
- diskTypeForMetric = metrics .GetDiskType (diskToPublish )
497
+
501
498
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
502
499
if gceCS .errorBackoff .blocking (backoffId ) {
503
500
return nil , status .Errorf (codes .Unavailable , "ControllerPublish not permitted on node %q due to backoff condition" , req .NodeId )
504
501
}
505
502
506
- resp , err := gceCS .executeControllerPublishVolume (ctx , req )
503
+ resp , err , diskTypeForMetric := gceCS .executeControllerPublishVolume (ctx , req )
507
504
if err != nil {
508
505
klog .Infof ("For node %s adding backoff due to error for volume %s: %v" , req .NodeId , req .VolumeId , err .Error ())
509
506
gceCS .errorBackoff .next (backoffId )
@@ -551,10 +548,11 @@ func parseMachineType(machineTypeUrl string) string {
551
548
return machineType
552
549
}
553
550
554
- func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error ) {
551
+ func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error , string ) {
552
+ diskToPublish := ""
555
553
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
556
554
if err != nil {
557
- return nil , err
555
+ return nil , err , diskToPublish
558
556
}
559
557
560
558
volumeID := req .GetVolumeId ()
@@ -569,35 +567,36 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
569
567
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
570
568
if err != nil {
571
569
if gce .IsGCENotFoundError (err ) {
572
- return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
570
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskToPublish
573
571
}
574
- return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err )
572
+ return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskToPublish
575
573
}
576
574
577
575
// Acquires the lock for the volume on that node only, because we need to support the ability
578
576
// to publish the same volume onto different nodes concurrently
579
577
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
580
578
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
581
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
579
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskToPublish
582
580
}
583
581
defer gceCS .volumeLocks .Release (lockingVolumeID )
584
- _ , err = gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
582
+ disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
583
+ diskToPublish = metrics .GetDiskType (disk )
585
584
if err != nil {
586
585
if gce .IsGCENotFoundError (err ) {
587
- return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ())
586
+ return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskToPublish
588
587
}
589
- return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ())
588
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskToPublish
590
589
}
591
590
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
592
591
if err != nil {
593
- return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ())
592
+ return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskToPublish
594
593
}
595
594
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
596
595
if err != nil {
597
596
if gce .IsGCENotFoundError (err ) {
598
- return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ())
597
+ return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskToPublish
599
598
}
600
- return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ())
599
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskToPublish
601
600
}
602
601
603
602
readWrite := "READ_WRITE"
@@ -607,21 +606,21 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
607
606
608
607
deviceName , err := common .GetDeviceName (volKey )
609
608
if err != nil {
610
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ())
609
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskToPublish
611
610
}
612
611
613
612
attached , err := diskIsAttachedAndCompatible (deviceName , instance , volumeCapability , readWrite )
614
613
if err != nil {
615
- return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ())
614
+ return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskToPublish
616
615
}
617
616
if attached {
618
617
// Volume is attached to node. Success!
619
618
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v, already attached." , volKey , nodeID )
620
- return pubVolResp , nil
619
+ return pubVolResp , nil , diskToPublish
621
620
}
622
621
instanceZone , instanceName , err = common .NodeIDToZoneAndName (nodeID )
623
622
if err != nil {
624
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ())
623
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskToPublish
625
624
}
626
625
err = gceCS .CloudProvider .AttachDisk (ctx , project , volKey , readWrite , attachableDiskTypePersistent , instanceZone , instanceName )
627
626
if err != nil {
@@ -630,18 +629,18 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
630
629
// If we encountered an UnsupportedDiskError, rewrite the error message to be more user friendly.
631
630
// The error message from GCE is phrased around disk create on VM creation, not runtime attach.
632
631
machineType := parseMachineType (instance .MachineType )
633
- 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 )
632
+ 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
634
633
}
635
- return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ())
634
+ return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskToPublish
636
635
}
637
636
638
637
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
639
638
if err != nil {
640
- return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ())
639
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskToPublish
641
640
}
642
641
643
642
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
644
- return pubVolResp , nil
643
+ return pubVolResp , nil , diskToPublish
645
644
}
646
645
647
646
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
@@ -656,14 +655,13 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
656
655
if err != nil {
657
656
return nil , err
658
657
}
659
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
660
- diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
661
658
// Only valid requests will be queued
662
659
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
663
660
if gceCS .errorBackoff .blocking (backoffId ) {
664
661
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
665
662
}
666
-
663
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
664
+ diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
667
665
resp , err := gceCS .executeControllerUnpublishVolume (ctx , req )
668
666
if err != nil {
669
667
klog .Infof ("For node %s adding backoff due to error for volume %s" , req .NodeId , req .VolumeId )
@@ -1263,15 +1261,15 @@ func (gceCS *GCEControllerServer) ControllerExpandVolume(ctx context.Context, re
1263
1261
if err != nil {
1264
1262
return nil , status .Errorf (codes .InvalidArgument , "ControllerExpandVolume Volume ID is invalid: %v" , err .Error ())
1265
1263
}
1266
- sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1267
- diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1268
1264
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
1269
1265
if err != nil {
1270
1266
if gce .IsGCENotFoundError (err ) {
1271
1267
return nil , status .Errorf (codes .NotFound , "ControllerExpandVolume could not find volume with ID %v: %v" , volumeID , err .Error ())
1272
1268
}
1273
1269
return nil , common .LoggedError ("ControllerExpandVolume error repairing underspecified volume key: " , err )
1274
1270
}
1271
+ sourceDisk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
1272
+ diskTypeForMetric = metrics .GetDiskType (sourceDisk )
1275
1273
resizedGb , err := gceCS .CloudProvider .ResizeDisk (ctx , project , volKey , reqBytes )
1276
1274
if err != nil {
1277
1275
return nil , common .LoggedError ("ControllerExpandVolume failed to resize disk: " , err )
0 commit comments