@@ -55,25 +55,15 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
5555 return nil , status .Error (codes .InvalidArgument , "Target path not provided" )
5656 }
5757
58- mountOptions := getNodePublishMountOptions (req )
58+ mountOptions := []string {"bind" }
59+ if req .GetReadonly () {
60+ mountOptions = append (mountOptions , "ro" )
61+ }
5962
6063 if err := d .ensureMountPoint (target ); err != nil {
6164 return nil , status .Errorf (codes .Internal , "Could not mount target %q: %v" , target , err )
6265 }
6366
64- readOnly := req .GetReadonly ()
65- volumeID := req .GetVolumeId ()
66- attrib := req .GetVolumeContext ()
67- mountFlags := req .GetVolumeCapability ().GetMount ().GetMountFlags ()
68-
69- klog .V (2 ).Infof ("target %v\n \n readonly %v\n volumeId %v\n Context %v\n mountflags %v\n " ,
70- target , readOnly , volumeID , attrib , mountFlags )
71-
72- klog .V (2 ).Infof ("NodePublishVolume: creating dir %s" , target )
73- if err := d .mounter .MakeDir (target ); err != nil {
74- return nil , status .Errorf (codes .Internal , "Could not create dir %q: %v" , target , err )
75- }
76-
7767 klog .V (2 ).Infof ("NodePublishVolume: mounting %s at %s with mountOptions: %v" , source , target , mountOptions )
7868 if err := d .mounter .Mount (source , target , "" , mountOptions ); err != nil {
7969 if removeErr := os .Remove (target ); removeErr != nil {
@@ -259,19 +249,7 @@ func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolume
259249 return nil , status .Error (codes .Unimplemented , fmt .Sprintf ("NodeExpandVolume is not yet implemented" ))
260250}
261251
262- func getNodePublishMountOptions (req * csi.NodePublishVolumeRequest ) []string {
263- mountFlags := req .GetVolumeCapability ().GetMount ().GetMountFlags ()
264- mountOptions := []string {"bind" }
265- if req .GetReadonly () {
266- mountOptions = append (mountOptions , "ro" )
267- }
268- mountOptions = util .JoinMountOptions (mountFlags , mountOptions )
269-
270- return mountOptions
271- }
272-
273- // ensureMountPoint: ensure mount point to be valid.
274- // If it is not existed, it will be created.
252+ // ensureMountPoint: create mount point if not exists
275253func (d * Driver ) ensureMountPoint (target string ) error {
276254 notMnt , err := d .mounter .IsLikelyNotMountPoint (target )
277255 if err != nil && ! os .IsNotExist (err ) {
@@ -294,8 +272,8 @@ func (d *Driver) ensureMountPoint(target string) error {
294272 // notMnt = true
295273 }
296274
297- if err := os . MkdirAll (target , 0750 ); err != nil {
298- klog .Errorf ("mkdir failed on target: %s (%v)" , target , err )
275+ if err := d . mounter . MakeDir (target ); err != nil {
276+ klog .Errorf ("MakeDir failed on target: %s (%v)" , target , err )
299277 return err
300278 }
301279
0 commit comments