@@ -55,25 +55,15 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
55
55
return nil , status .Error (codes .InvalidArgument , "Target path not provided" )
56
56
}
57
57
58
- mountOptions := getNodePublishMountOptions (req )
58
+ mountOptions := []string {"bind" }
59
+ if req .GetReadonly () {
60
+ mountOptions = append (mountOptions , "ro" )
61
+ }
59
62
60
63
if err := d .ensureMountPoint (target ); err != nil {
61
64
return nil , status .Errorf (codes .Internal , "Could not mount target %q: %v" , target , err )
62
65
}
63
66
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
-
77
67
klog .V (2 ).Infof ("NodePublishVolume: mounting %s at %s with mountOptions: %v" , source , target , mountOptions )
78
68
if err := d .mounter .Mount (source , target , "" , mountOptions ); err != nil {
79
69
if removeErr := os .Remove (target ); removeErr != nil {
@@ -259,19 +249,7 @@ func (d *Driver) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandVolume
259
249
return nil , status .Error (codes .Unimplemented , fmt .Sprintf ("NodeExpandVolume is not yet implemented" ))
260
250
}
261
251
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
275
253
func (d * Driver ) ensureMountPoint (target string ) error {
276
254
notMnt , err := d .mounter .IsLikelyNotMountPoint (target )
277
255
if err != nil && ! os .IsNotExist (err ) {
@@ -294,8 +272,8 @@ func (d *Driver) ensureMountPoint(target string) error {
294
272
// notMnt = true
295
273
}
296
274
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 )
299
277
return err
300
278
}
301
279
0 commit comments