support local volume empty path
@@ -153,6 +153,13 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
log.Errorf("NodePublishVolume: mount local volume %s with path %s", req.VolumeId, targetPath)
return nil, status.Error(codes.Internal, "NodePublishVolume: targetPath is empty")
}
+ // Check targetPath
+ if _, err := os.Stat(targetPath); os.IsNotExist(err) {
+ if err := os.MkdirAll(targetPath, 0750); err != nil {
+ log.Errorf("NodePublishVolume: local volume %s mkdir target path %s with error: %s", req.VolumeId, targetPath, err.Error())
+ return nil, status.Errorf(codes.Internal, "NodePublishVolume: local volume %s mkdir target path %s with error: %s", req.VolumeId, targetPath, err.Error())
+ }
+ }
volumeType := ""
if _, ok := req.VolumeContext[VolumeTypeTag]; ok {
