Skip to content

Commit

Permalink
Merge pull request #2093 from umagnus/improve_err_msg
Browse files Browse the repository at this point in the history
fix: improve disk attach/detach error message
  • Loading branch information
andyzhangx committed Nov 29, 2023
2 parents c413145 + db53b1f commit 8ac1b36
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 @@ -49,6 +49,7 @@ import (
const (
waitForSnapshotReadyInterval = 5 * time.Second
waitForSnapshotReadyTimeout = 10 * time.Minute
maxErrMsgLength = 990
)

// listVolumeStatus explains the return status of `listVolumesByResourceGroup`
Expand Down Expand Up @@ -463,7 +464,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 @@ -510,7 +515,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 8ac1b36

Please sign in to comment.