Skip to content

Commit

Permalink
Add mountOptions support
Browse files Browse the repository at this point in the history
  • Loading branch information
bertinatto committed Nov 29, 2018
1 parent 7b9be2a commit 74bb1a2
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 @@ -142,9 +142,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 @@ -153,7 +169,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 74bb1a2

Please sign in to comment.