@@ -542,10 +542,10 @@ func parseMachineType(machineTypeUrl string) string {
542
542
}
543
543
544
544
func (gceCS * GCEControllerServer ) executeControllerPublishVolume (ctx context.Context , req * csi.ControllerPublishVolumeRequest ) (* csi.ControllerPublishVolumeResponse , error , string ) {
545
- diskToPublish := ""
545
+ diskType := ""
546
546
project , volKey , err := gceCS .validateControllerPublishVolumeRequest (ctx , req )
547
547
if err != nil {
548
- return nil , err , diskToPublish
548
+ return nil , err , diskType
549
549
}
550
550
551
551
volumeID := req .GetVolumeId ()
@@ -560,36 +560,36 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
560
560
project , volKey , err = gceCS .CloudProvider .RepairUnderspecifiedVolumeKey (ctx , project , volKey )
561
561
if err != nil {
562
562
if gce .IsGCENotFoundError (err ) {
563
- return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskToPublish
563
+ return nil , status .Errorf (codes .NotFound , "ControllerPublishVolume could not find volume with ID %v: %v" , volumeID , err .Error ()), diskType
564
564
}
565
- return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskToPublish
565
+ return nil , common .LoggedError ("ControllerPublishVolume error repairing underspecified volume key: " , err ), diskType
566
566
}
567
567
568
568
// Acquires the lock for the volume on that node only, because we need to support the ability
569
569
// to publish the same volume onto different nodes concurrently
570
570
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
571
571
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
572
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskToPublish
572
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskType
573
573
}
574
574
defer gceCS .volumeLocks .Release (lockingVolumeID )
575
575
disk , err := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
576
- diskToPublish = metrics .GetDiskType (disk )
576
+ diskType = metrics .GetDiskType (disk )
577
577
if err != nil {
578
578
if gce .IsGCENotFoundError (err ) {
579
- return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskToPublish
579
+ return nil , status .Errorf (codes .NotFound , "Could not find disk %v: %v" , volKey .String (), err .Error ()), diskType
580
580
}
581
- return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskToPublish
581
+ return nil , status .Errorf (codes .Internal , "Failed to getDisk: %v" , err .Error ()), diskType
582
582
}
583
583
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
584
584
if err != nil {
585
- return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskToPublish
585
+ return nil , status .Errorf (codes .NotFound , "could not split nodeID: %v" , err .Error ()), diskType
586
586
}
587
587
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
588
588
if err != nil {
589
589
if gce .IsGCENotFoundError (err ) {
590
- return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskToPublish
590
+ return nil , status .Errorf (codes .NotFound , "Could not find instance %v: %v" , nodeID , err .Error ()), diskType
591
591
}
592
- return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskToPublish
592
+ return nil , status .Errorf (codes .Internal , "Failed to get instance: %v" , err .Error ()), diskType
593
593
}
594
594
595
595
readWrite := "READ_WRITE"
@@ -599,21 +599,21 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
599
599
600
600
deviceName , err := common .GetDeviceName (volKey )
601
601
if err != nil {
602
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskToPublish
602
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskType
603
603
}
604
604
605
605
attached , err := diskIsAttachedAndCompatible (deviceName , instance , volumeCapability , readWrite )
606
606
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 ()), diskToPublish
607
+ return nil , status .Errorf (codes .AlreadyExists , "Disk %v already published to node %v but incompatible: %v" , volKey .Name , nodeID , err .Error ()), diskType
608
608
}
609
609
if attached {
610
610
// Volume is attached to node. Success!
611
611
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v, already attached." , volKey , nodeID )
612
- return pubVolResp , nil , diskToPublish
612
+ return pubVolResp , nil , diskType
613
613
}
614
614
instanceZone , instanceName , err = common .NodeIDToZoneAndName (nodeID )
615
615
if err != nil {
616
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskToPublish
616
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskType
617
617
}
618
618
err = gceCS .CloudProvider .AttachDisk (ctx , project , volKey , readWrite , attachableDiskTypePersistent , instanceZone , instanceName )
619
619
if err != nil {
@@ -622,18 +622,18 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
622
622
// If we encountered an UnsupportedDiskError, rewrite the error message to be more user friendly.
623
623
// The error message from GCE is phrased around disk create on VM creation, not runtime attach.
624
624
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 ), diskToPublish
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 ), diskType
626
626
}
627
- return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskToPublish
627
+ return nil , status .Errorf (codes .Internal , "Failed to Attach: %v" , err .Error ()), diskType
628
628
}
629
629
630
630
err = gceCS .CloudProvider .WaitForAttach (ctx , project , volKey , instanceZone , instanceName )
631
631
if err != nil {
632
- return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskToPublish
632
+ return nil , status .Errorf (codes .Internal , "Errored during WaitForAttach: %v" , err .Error ()), diskType
633
633
}
634
634
635
635
klog .V (4 ).Infof ("ControllerPublishVolume succeeded for disk %v to instance %v" , volKey , nodeID )
636
- return pubVolResp , nil , diskToPublish
636
+ return pubVolResp , nil , diskType
637
637
}
638
638
639
639
func (gceCS * GCEControllerServer ) ControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
@@ -644,18 +644,17 @@ func (gceCS *GCEControllerServer) ControllerUnpublishVolume(ctx context.Context,
644
644
gceCS .Metrics .RecordOperationErrorMetrics ("ControllerUnpublishVolume" , err , diskTypeForMetric )
645
645
}
646
646
}()
647
- project , volKey , err : = gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
647
+ _ , _ , err = gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
648
648
if err != nil {
649
649
return nil , err
650
650
}
651
+ err = status .Errorf (codes .InvalidArgument , "error message" )
651
652
// Only valid requests will be queued
652
653
backoffId := gceCS .errorBackoff .backoffId (req .NodeId , req .VolumeId )
653
654
if gceCS .errorBackoff .blocking (backoffId ) {
654
655
return nil , status .Errorf (codes .Unavailable , "ControllerUnpublish not permitted on node %q due to backoff condition" , req .NodeId )
655
656
}
656
- diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
657
- diskTypeForMetric = metrics .GetDiskType (diskToUnpublish )
658
- resp , err := gceCS .executeControllerUnpublishVolume (ctx , req )
657
+ resp , err , diskTypeForMetric := gceCS .executeControllerUnpublishVolume (ctx , req )
659
658
if err != nil {
660
659
klog .Infof ("For node %s adding backoff due to error for volume %s" , req .NodeId , req .VolumeId )
661
660
gceCS .errorBackoff .next (backoffId )
@@ -685,11 +684,12 @@ func (gceCS *GCEControllerServer) validateControllerUnpublishVolumeRequest(ctx c
685
684
return project , volKey , nil
686
685
}
687
686
688
- func (gceCS * GCEControllerServer ) executeControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error ) {
687
+ func (gceCS * GCEControllerServer ) executeControllerUnpublishVolume (ctx context.Context , req * csi.ControllerUnpublishVolumeRequest ) (* csi.ControllerUnpublishVolumeResponse , error , string ) {
688
+ var diskType string
689
689
project , volKey , err := gceCS .validateControllerUnpublishVolumeRequest (ctx , req )
690
690
691
691
if err != nil {
692
- return nil , err
692
+ return nil , err , diskType
693
693
}
694
694
695
695
volumeID := req .GetVolumeId ()
@@ -698,52 +698,53 @@ func (gceCS *GCEControllerServer) executeControllerUnpublishVolume(ctx context.C
698
698
if err != nil {
699
699
if gce .IsGCENotFoundError (err ) {
700
700
klog .Warningf ("Treating volume %v as unpublished because it could not be found" , volumeID )
701
- return & csi.ControllerUnpublishVolumeResponse {}, nil
701
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
702
702
}
703
- return nil , common .LoggedError ("ControllerUnpublishVolume error repairing underspecified volume key: " , err )
703
+ return nil , common .LoggedError ("ControllerUnpublishVolume error repairing underspecified volume key: " , err ), diskType
704
704
}
705
705
706
706
// Acquires the lock for the volume on that node only, because we need to support the ability
707
707
// to unpublish the same volume from different nodes concurrently
708
708
lockingVolumeID := fmt .Sprintf ("%s/%s" , nodeID , volumeID )
709
709
if acquired := gceCS .volumeLocks .TryAcquire (lockingVolumeID ); ! acquired {
710
- return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID )
710
+ return nil , status .Errorf (codes .Aborted , common .VolumeOperationAlreadyExistsFmt , lockingVolumeID ), diskType
711
711
}
712
712
defer gceCS .volumeLocks .Release (lockingVolumeID )
713
-
713
+ diskToUnpublish , _ := gceCS .CloudProvider .GetDisk (ctx , project , volKey , gce .GCEAPIVersionV1 )
714
+ diskType = metrics .GetDiskType (diskToUnpublish )
714
715
instanceZone , instanceName , err := common .NodeIDToZoneAndName (nodeID )
715
716
if err != nil {
716
- return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ())
717
+ return nil , status .Errorf (codes .InvalidArgument , "could not split nodeID: %v" , err .Error ()), diskType
717
718
}
718
719
instance , err := gceCS .CloudProvider .GetInstanceOrError (ctx , instanceZone , instanceName )
719
720
if err != nil {
720
721
if gce .IsGCENotFoundError (err ) {
721
722
// Node not existing on GCE means that disk has been detached
722
723
klog .Warningf ("Treating volume %v as unpublished because node %v could not be found" , volKey .String (), instanceName )
723
- return & csi.ControllerUnpublishVolumeResponse {}, nil
724
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
724
725
}
725
- return nil , status .Errorf (codes .Internal , "error getting instance: %v" , err .Error ())
726
+ return nil , status .Errorf (codes .Internal , "error getting instance: %v" , err .Error ()), diskType
726
727
}
727
728
728
729
deviceName , err := common .GetDeviceName (volKey )
729
730
if err != nil {
730
- return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ())
731
+ return nil , status .Errorf (codes .Internal , "error getting device name: %v" , err .Error ()), diskType
731
732
}
732
733
733
734
attached := diskIsAttached (deviceName , instance )
734
735
735
736
if ! attached {
736
737
// Volume is not attached to node. Success!
737
738
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v. Already not attached." , volKey , nodeID )
738
- return & csi.ControllerUnpublishVolumeResponse {}, nil
739
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
739
740
}
740
741
err = gceCS .CloudProvider .DetachDisk (ctx , project , deviceName , instanceZone , instanceName )
741
742
if err != nil {
742
- return nil , common .LoggedError ("Failed to detach: " , err )
743
+ return nil , common .LoggedError ("Failed to detach: " , err ), diskType
743
744
}
744
745
745
746
klog .V (4 ).Infof ("ControllerUnpublishVolume succeeded for disk %v from node %v" , volKey , nodeID )
746
- return & csi.ControllerUnpublishVolumeResponse {}, nil
747
+ return & csi.ControllerUnpublishVolumeResponse {}, nil , diskType
747
748
}
748
749
749
750
func (gceCS * GCEControllerServer ) ValidateVolumeCapabilities (ctx context.Context , req * csi.ValidateVolumeCapabilitiesRequest ) (* csi.ValidateVolumeCapabilitiesResponse , error ) {
0 commit comments