Skip to content

Commit

Permalink
Merge pull request #2104 from umagnus/release-1.26
Browse files Browse the repository at this point in the history
[release-1.26] fix: improve disk attach/detach error message
  • Loading branch information
andyzhangx authored Nov 30, 2023
2 parents ded301c + c07eb92 commit 1cb9ec9
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pkg/azuredisk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
const (
waitForSnapshotCopyInterval = 5 * time.Second
waitForSnapshotCopyTimeout = 10 * time.Minute
maxErrMsgLength = 990
)

// listVolumeStatus explains the return status of `listVolumesByResourceGroup`
Expand Down Expand Up @@ -445,7 +446,11 @@ func (d *Driver) ControllerPublishVolume(ctx context.Context, req *csi.Controlle
}
if err != nil {
klog.Errorf("Attach volume %s to instance %s failed with %v", diskURI, nodeName, err)
return nil, status.Errorf(codes.Internal, "Attach volume %s to instance %s failed with %v", diskURI, nodeName, err)
errMsg := fmt.Sprintf("Attach volume %s to instance %s failed with %v", diskURI, nodeName, err)
if len(errMsg) > maxErrMsgLength {
errMsg = errMsg[:maxErrMsgLength]
}
return nil, status.Errorf(codes.Internal, errMsg)
}
}
klog.V(2).Infof("attach volume %s to node %s successfully", diskURI, nodeName)
Expand Down Expand Up @@ -492,7 +497,12 @@ func (d *Driver) ControllerUnpublishVolume(ctx context.Context, req *csi.Control
if strings.Contains(err.Error(), consts.ErrDiskNotFound) {
klog.Warningf("volume %s already detached from node %s", diskURI, nodeID)
} else {
return nil, status.Errorf(codes.Internal, "Could not detach volume %s from node %s: %v", diskURI, nodeID, err)
klog.Errorf("Could not detach volume %s from node %s: %v", diskURI, nodeID, err)
errMsg := fmt.Sprintf("Could not detach volume %s from node %s: %v", diskURI, nodeID, err)
if len(errMsg) > maxErrMsgLength {
errMsg = errMsg[:maxErrMsgLength]
}
return nil, status.Errorf(codes.Internal, errMsg)
}
}
klog.V(2).Infof("detach volume %s from node %s successfully", diskURI, nodeID)
Expand Down

0 comments on commit 1cb9ec9

Please sign in to comment.