@@ -485,10 +485,10 @@ func parseMachineType(machineTypeUrl string) string {
485
485
}
486
486
487
487
func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error , string ) {
488
- diskToPublish := ""
488
+ diskType := ""
489
489
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
490
490
if err != nil {
491
- return nil , err , diskToPublish
491
+ return nil , err , diskType
492
492
}
493
493
494
494
volumeID := req .GetVolumeId ()
@@ -503,36 +503,36 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
503
503
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
504
504
if err != nil {
505
505
if gce .IsGCENotFoundError (err ) {
506
- return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskToPublish
506
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskType
507
507
}
508
- return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskToPublish
508
+ return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskType
509
509
}
510
510
511
511
// Acquires the lock for the volume on that node only, because we need to support the ability
512
512
// to publish the same volume onto different nodes concurrently
513
513
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
514
514
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
515
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskToPublish
515
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskType
516
516
}
517
517
defer gceCS .volumeLocks .Release (lockingVolumeID )
518
518
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
519
- diskToPublish = metrics .GetDiskType (disk )
519
+ diskType = metrics .GetDiskType (disk )
520
520
if err != nil {
521
521
if gce .IsGCENotFoundError (err ) {
522
- return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskToPublish
522
+ return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskType
523
523
}
524
- return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskToPublish
524
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskType
525
525
}
526
526
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
527
527
if err != nil {
528
- return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskToPublish
528
+ return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskType
529
529
}
530
530
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
531
531
if err != nil {
532
532
if gce .IsGCENotFoundError (err ) {
533
- return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskToPublish
533
+ return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskType
534
534
}
535
- return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskToPublish
535
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskType
536
536
}
537
537
538
538
readWrite := "READ_WRITE"
@@ -542,21 +542,21 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
542
542
543
543
deviceName , err := common .GetDeviceName (volKey )
544
544
if err != nil {
545
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskToPublish
545
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskType
546
546
}
547
547
548
548
attached , err := diskIsAttachedAndCompatible (deviceName , instance , volumeCapability , readWrite )
549
549
if err != nil {
550
- return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskToPublish
550
+ return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskType
551
551
}
552
552
if attached {
553
553
// Volume is attached to node. Success!
554
554
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v, already attached." , volKey , nodeID )
555
- return pubVolResp , nil , diskToPublish
555
+ return pubVolResp , nil , diskType
556
556
}
557
557
instanceZone , instanceName , err = common .NodeIDToZoneAndName (nodeID )
558
558
if err != nil {
559
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskToPublish
559
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskType
560
560
}
561
561
err = gceCS .CloudProvider .AttachDisk (ctx , project , volKey , readWrite , attachableDiskTypePersistent , instanceZone , instanceName )
562
562
if err != nil {
@@ -565,18 +565,18 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
565
565
// If we encountered an UnsupportedDiskError, rewrite the error message to be more user friendly.
566
566
// The error message from GCE is phrased around disk create on VM creation, not runtime attach.
567
567
machineType := parseMachineType (instance .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
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 ), diskType
569
569
}
570
- return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskToPublish
570
+ return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskType
571
571
}
572
572
573
573
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
574
574
if err != nil {
575
- return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskToPublish
575
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskType
576
576
}
577
577
578
578
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
579
- return pubVolResp , nil , diskToPublish
579
+ return pubVolResp , nil , diskType
580
580
}
581
581
582
582
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
@@ -587,18 +587,17 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
587
587
gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric )
588
588
}
589
589
}()
590
- project , volKey , err : = gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
590
+ _ , _ , err = gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
591
591
if err != nil {
592
592
return nil , err
593
593
}
594
+ err = status .Errorf (codes .InvalidArgument , "error message" )
594
595
// Only valid requests will be queued
595
596
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
596
597
if gceCS .errorBackoff .blocking (backoffId ) {
597
598
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
598
599
}
599
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
600
- diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
601
- resp , err := gceCS .executeControllerUnpublishVolume (ctx , req )
600
+ resp , err , diskTypeForMetric := gceCS .executeControllerUnpublishVolume (ctx , req )
602
601
if err != nil {
603
602
klog .Infof ("For node %s adding backoff due to error for volume %s" , req .NodeId , req .VolumeId )
604
603
gceCS .errorBackoff .next (backoffId )
@@ -628,11 +627,12 @@ func (gceCS *GCEControllerServer) validateControllerUnpublishVolumeRequest(ctx c
628
627
return project , volKey , nil
629
628
}
630
629
631
- func (gceCS * GCEControllerServer ) executeControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
630
+ func (gceCS * GCEControllerServer ) executeControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error , string ) {
631
+ var diskType string
632
632
project , volKey , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
633
633
634
634
if err != nil {
635
- return nil , err
635
+ return nil , err , diskType
636
636
}
637
637
638
638
volumeID := req .GetVolumeId ()
@@ -641,52 +641,53 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
641
641
if err != nil {
642
642
if gce .IsGCENotFoundError (err ) {
643
643
klog .Warningf ("Treating volume %v as unpublished because it could not be found" , volumeID )
644
- return & csi.ControllerUnpublishVolumeResponse {}, nil
644
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
645
645
}
646
- return nil , common .LoggedError ("ControllerUnpublishVolume error repairing underspecified volume key: " , err )
646
+ return nil , common .LoggedError ("ControllerUnpublishVolume error repairing underspecified volume key: " , err ), diskType
647
647
}
648
648
649
649
// Acquires the lock for the volume on that node only, because we need to support the ability
650
650
// to unpublish the same volume from different nodes concurrently
651
651
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
652
652
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
653
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
653
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskType
654
654
}
655
655
defer gceCS .volumeLocks .Release (lockingVolumeID )
656
-
656
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
657
+ diskType = metrics .GetDiskType (diskToUnpublish )
657
658
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
658
659
if err != nil {
659
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ())
660
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskType
660
661
}
661
662
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
662
663
if err != nil {
663
664
if gce .IsGCENotFoundError (err ) {
664
665
// Node not existing on GCE means that disk has been detached
665
666
klog .Warningf ("Treating volume %v as unpublished because node %v could not be found" , volKey .String (), instanceName )
666
- return & csi.ControllerUnpublishVolumeResponse {}, nil
667
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
667
668
}
668
- return nil , status .Errorf (codes .Internal , "error getting instance: %v" , err .Error ())
669
+ return nil , status .Errorf (codes .Internal , "error getting instance: %v" , err .Error ()), diskType
669
670
}
670
671
671
672
deviceName , err := common .GetDeviceName (volKey )
672
673
if err != nil {
673
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ())
674
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskType
674
675
}
675
676
676
677
attached := diskIsAttached (deviceName , instance )
677
678
678
679
if ! attached {
679
680
// Volume is not attached to node. Success!
680
681
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v. Already not attached." , volKey , nodeID )
681
- return & csi.ControllerUnpublishVolumeResponse {}, nil
682
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
682
683
}
683
684
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
684
685
if err != nil {
685
- return nil , common .LoggedError ("Failed to detach: " , err )
686
+ return nil , common .LoggedError ("Failed to detach: " , err ), diskType
686
687
}
687
688
688
689
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
689
- return & csi.ControllerUnpublishVolumeResponse {}, nil
690
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
690
691
}
691
692
692
693
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
0 commit comments