Skip to content

Commit

Permalink
Merge pull request #130 from bertinatto/add_mountoptions_support
Browse files Browse the repository at this point in the history
Add mountOptions support
  • Loading branch information
Cheng Pan authored Dec 9, 2018
2 parents 655725c + 74bb1a2 commit 68069e9
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,25 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
return nil, status.Error(codes.InvalidArgument, "Volume capability not supported")
}

options := []string{"bind"}
mountOptions := []string{"bind"}
if req.GetReadonly() {
options = append(options, "ro")
mountOptions = append(mountOptions, "ro")
}

if m := volCap.GetMount(); m != nil {
hasOption := func(options []string, opt string) bool {
for _, o := range options {
if o == opt {
return true
}
}
return false
}
for _, f := range m.MountFlags {
if !hasOption(mountOptions, f) {
mountOptions = append(mountOptions, f)
}
}
}

glog.V(5).Infof("NodePublishVolume: creating dir %s", target)
Expand All @@ -160,7 +176,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
}

glog.V(5).Infof("NodePublishVolume: mounting %s at %s", source, target)
if err := d.mounter.Interface.Mount(source, target, "ext4", options); err != nil {
if err := d.mounter.Interface.Mount(source, target, "ext4", mountOptions); err != nil {
os.Remove(target)
return nil, status.Errorf(codes.Internal, "Could not mount %q at %q: %v", source, target, err)
}
Expand Down

0 comments on commit 68069e9

Please sign in to comment.