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