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