From 74bb1a247d59d4e6155b5b4119fc83f024be36f7 Mon Sep 17 00:00:00 2001 From: Fabio Bertinatto Date: Thu, 29 Nov 2018 14:35:35 +0100 Subject: [PATCH] Add mountOptions support --- pkg/driver/node.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/pkg/driver/node.go b/pkg/driver/node.go index 55baebb85a..1f6cc5ecb6 100644 --- a/pkg/driver/node.go +++ b/pkg/driver/node.go @@ -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) @@ -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) }