@@ -10,8 +10,6 @@ import (
1010
1111 "github.com/container-storage-interface/spec/lib/go/csi"
1212 "github.com/linode/linodego"
13- "google.golang.org/grpc/codes"
14- "google.golang.org/grpc/status"
1513
1614 linodevolumes "github.com/linode/linode-blockstorage-csi-driver/pkg/linode-volumes"
1715 "github.com/linode/linode-blockstorage-csi-driver/pkg/logger"
@@ -667,13 +665,17 @@ func (cs *ControllerServer) attachVolume(ctx context.Context, volumeID, linodeID
667665 PersistAcrossBoots : & persist ,
668666 })
669667 if err != nil {
670- code := codes .Internal // Default error code is Internal.
671- // Check if the error indicates that the volume is already attached.
668+ // https://github.com/container-storage-interface/spec/blob/master/spec.md#controllerpublishvolume-errors
672669 var apiErr * linodego.Error
673- if errors .As (err , & apiErr ) && strings .Contains (apiErr .Message , "is already attached" ) {
674- code = codes .Unavailable // Allow a retry if the volume is already attached: race condition can occur here
670+ if errors .As (err , & apiErr ) {
671+ switch {
672+ case strings .Contains (apiErr .Message , "is already attached" ):
673+ return errAlreadyAttached
674+ case strings .Contains (apiErr .Message , "Maximum number of block storage volumes are attached to this Linode" ):
675+ return errMaxAttachments
676+ }
675677 }
676- return status . Errorf ( code , "attach volume: %v" , err )
678+ return errInternal ( "attach volume %d to Linode %d : %v" , volumeID , linodeID , err )
677679 }
678680 return nil // Return nil if the volume is successfully attached.
679681}
0 commit comments