diff --git a/pkg/nfs/nfs.go b/pkg/nfs/nfs.go index 3bc4b613..6dfd0b7c 100644 --- a/pkg/nfs/nfs.go +++ b/pkg/nfs/nfs.go @@ -19,6 +19,7 @@ package nfs import ( "github.com/container-storage-interface/spec/lib/go/csi" "github.com/golang/glog" + "k8s.io/kubernetes/pkg/util/mount" ) type nfsDriver struct { @@ -61,14 +62,15 @@ func NewNFSdriver(nodeID, endpoint string) *nfsDriver { return n } -func NewNodeServer(n *nfsDriver) *nodeServer { +func NewNodeServer(n *nfsDriver, mounter mount.Interface) *nodeServer { return &nodeServer{ - Driver: n, + Driver: n, + mounter: mounter, } } func (n *nfsDriver) Run() { - n.ns = NewNodeServer(n) + n.ns = NewNodeServer(n, mount.New("")) s := NewNonBlockingGRPCServer() s.Start(n.endpoint, NewDefaultIdentityServer(n), diff --git a/pkg/nfs/nodeserver.go b/pkg/nfs/nodeserver.go index 750cd4a1..d4fcdee5 100644 --- a/pkg/nfs/nodeserver.go +++ b/pkg/nfs/nodeserver.go @@ -18,10 +18,11 @@ package nfs import ( "fmt" - "github.com/golang/glog" "os" "strings" + "github.com/golang/glog" + "github.com/container-storage-interface/spec/lib/go/csi" "golang.org/x/net/context" "google.golang.org/grpc/codes" @@ -30,12 +31,13 @@ import ( ) type nodeServer struct { - Driver *nfsDriver + Driver *nfsDriver + mounter mount.Interface } func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolumeRequest) (*csi.NodePublishVolumeResponse, error) { targetPath := req.GetTargetPath() - notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath) + notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath) if err != nil { if os.IsNotExist(err) { if err := os.MkdirAll(targetPath, 0750); err != nil { @@ -60,8 +62,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis ep := req.GetVolumeContext()["share"] source := fmt.Sprintf("%s:%s", s, ep) - mounter := mount.New("") - err = mounter.Mount(source, targetPath, "nfs", mo) + err = ns.mounter.Mount(source, targetPath, "nfs", mo) if err != nil { if os.IsPermission(err) { return nil, status.Error(codes.PermissionDenied, err.Error()) @@ -77,7 +78,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpublishVolumeRequest) (*csi.NodeUnpublishVolumeResponse, error) { targetPath := req.GetTargetPath() - notMnt, err := mount.New("").IsLikelyNotMountPoint(targetPath) + notMnt, err := ns.mounter.IsLikelyNotMountPoint(targetPath) if err != nil { if os.IsNotExist(err) { @@ -90,7 +91,7 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu return nil, status.Error(codes.NotFound, "Volume not mounted") } - err = mount.CleanupMountPoint(req.GetTargetPath(), mount.New(""), false) + err = mount.CleanupMountPoint(req.GetTargetPath(), ns.mounter, false) if err != nil { return nil, status.Error(codes.Internal, err.Error()) }