@@ -38,7 +38,8 @@ type NodeServer struct {
3838
3939// NodePublishVolume mount the volume
4040func (ns * NodeServer ) NodePublishVolume (ctx context.Context , req * csi.NodePublishVolumeRequest ) (* csi.NodePublishVolumeResponse , error ) {
41- if req .GetVolumeCapability () == nil {
41+ volCap := req .GetVolumeCapability ()
42+ if volCap == nil {
4243 return nil , status .Error (codes .InvalidArgument , "Volume capability missing in request" )
4344 }
4445 volumeID := req .GetVolumeId ()
@@ -49,6 +50,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
4950 if len (targetPath ) == 0 {
5051 return nil , status .Error (codes .InvalidArgument , "Target path not provided" )
5152 }
53+ mountOptions := volCap .GetMount ().GetMountFlags ()
54+ if req .GetReadonly () {
55+ mountOptions = append (mountOptions , "ro" )
56+ }
5257
5358 var server , baseDir string
5459 for k , v := range req .GetVolumeContext () {
@@ -57,6 +62,10 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
5762 server = v
5863 case paramShare :
5964 baseDir = v
65+ case mountOptionsField :
66+ if v != "" {
67+ mountOptions = append (mountOptions , v )
68+ }
6069 }
6170 }
6271
@@ -83,11 +92,6 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
8392 return & csi.NodePublishVolumeResponse {}, nil
8493 }
8594
86- mountOptions := req .GetVolumeCapability ().GetMount ().GetMountFlags ()
87- if req .GetReadonly () {
88- mountOptions = append (mountOptions , "ro" )
89- }
90-
9195 klog .V (2 ).Infof ("NodePublishVolume: volumeID(%v) source(%s) targetPath(%s) mountflags(%v)" , volumeID , source , targetPath , mountOptions )
9296 err = ns .mounter .Mount (source , targetPath , "nfs" , mountOptions )
9397 if err != nil {
0 commit comments