Skip to content

Commit

Permalink
fix: add noload mounting option when mounting as read-only
Browse files Browse the repository at this point in the history
  • Loading branch information
iExalt committed Jan 15, 2025
1 parent 53cbd48 commit b6813fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func (d *DefaultNode) NodePublishVolume(_ context.Context, request *csi.NodePubl

if request.GetReadonly() {
mountOpts = append(mountOpts, readOnlyMountOption)

Check failure on line 57 in internal/node/node.go

View workflow job for this annotation

GitHub Actions / lint

appendCombine: can combine chain of 2 appends into one (gocritic)
mountOpts = append(mountOpts, noLoadMountOption)
}

err := nodePublishVolume(d.Mounter, d.Resizer, mountOpts, d.DiskType, request)
Expand Down
12 changes: 6 additions & 6 deletions internal/node/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
expectedTypeSegments = 2
fsDiskFilesystem = "virtiofs"
readOnlyMountOption = "ro"
noLoadMountOption = "noload"
)

var (
Expand Down Expand Up @@ -85,12 +86,11 @@ func nodePublishFilesystemVolume(serialNumber string,
diskType common.DiskType,
request *csi.NodePublishVolumeRequest,
) error {
// Check if the directory exists
if _, err := os.Stat(request.GetTargetPath()); errors.Is(err, os.ErrNotExist) {
// Directory does not exist, create it
if mkdirErr := os.MkdirAll(request.GetTargetPath(), newDirPerms); mkdirErr != nil {
return fmt.Errorf("failed to make directory for target path: %w", mkdirErr)
}
// Make parent directory for target path
// os.MkdirAll will be a noop if the directory already exists
mkDirErr := os.MkdirAll(request.GetTargetPath(), newDirPerms)
if mkDirErr != nil {
return fmt.Errorf("failed to make directory for target path: %w", mkDirErr)
}

mountOpts = append(mountOpts, request.GetVolumeCapability().GetMount().GetMountFlags()...)
Expand Down

0 comments on commit b6813fc

Please sign in to comment.