Skip to content

Commit

Permalink
Remove nfs custom mounter
Browse files Browse the repository at this point in the history
  • Loading branch information
Deyuan Deng authored and ddysher committed Apr 3, 2015
1 parent dca645d commit e8fc2fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 122 deletions.
24 changes: 15 additions & 9 deletions pkg/volume/nfs/nfs.go
Expand Up @@ -17,23 +17,25 @@ limitations under the License.
package nfs

import (
"fmt"
"os"

"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/types"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util"
"github.com/GoogleCloudPlatform/kubernetes/pkg/util/mount"
"github.com/GoogleCloudPlatform/kubernetes/pkg/volume"
"github.com/golang/glog"
)

// This is the primary entrypoint for volume plugins.
func ProbeVolumePlugins() []volume.VolumePlugin {
return []volume.VolumePlugin{&nfsPlugin{nil, newNFSMounter()}}
return []volume.VolumePlugin{&nfsPlugin{nil, mount.New()}}
}

type nfsPlugin struct {
host volume.VolumeHost
mounter nfsMountInterface
mounter mount.Interface
}

var _ volume.VolumePlugin = &nfsPlugin{}
Expand Down Expand Up @@ -69,7 +71,7 @@ func (plugin *nfsPlugin) NewBuilder(spec *api.Volume, podRef *api.ObjectReferenc
return plugin.newBuilderInternal(spec, podRef, plugin.mounter)
}

func (plugin *nfsPlugin) newBuilderInternal(spec *api.Volume, podRef *api.ObjectReference, mounter nfsMountInterface) (volume.Builder, error) {
func (plugin *nfsPlugin) newBuilderInternal(spec *api.Volume, podRef *api.ObjectReference, mounter mount.Interface) (volume.Builder, error) {
return &nfs{
volName: spec.Name,
server: spec.VolumeSource.NFS.Server,
Expand All @@ -85,7 +87,7 @@ func (plugin *nfsPlugin) NewCleaner(volName string, podUID types.UID) (volume.Cl
return plugin.newCleanerInternal(volName, podUID, plugin.mounter)
}

func (plugin *nfsPlugin) newCleanerInternal(volName string, podUID types.UID, mounter nfsMountInterface) (volume.Cleaner, error) {
func (plugin *nfsPlugin) newCleanerInternal(volName string, podUID types.UID, mounter mount.Interface) (volume.Cleaner, error) {
return &nfs{
volName: volName,
server: "",
Expand All @@ -104,7 +106,7 @@ type nfs struct {
server string
exportPath string
readOnly bool
mounter nfsMountInterface
mounter mount.Interface
plugin *nfsPlugin
}

Expand All @@ -122,17 +124,21 @@ func (nfsVolume *nfs) SetUpAt(dir string) error {
if mountpoint {
return nil
}
exportDir := nfsVolume.exportPath
flags := uintptr(0)
if nfsVolume.readOnly {
flags = mount.FlagReadOnly
}
os.MkdirAll(dir, 0750)
err = nfsVolume.mounter.Mount(nfsVolume.server, exportDir, dir, nfsVolume.readOnly)
err = nfsVolume.mounter.Mount(fmt.Sprintf("%s:%s", nfsVolume.server, nfsVolume.exportPath),
dir, "nfs", flags, fmt.Sprintf("addr=%s", nfsVolume.server))
if err != nil {
mountpoint, mntErr := nfsVolume.mounter.IsMountPoint(dir)
if mntErr != nil {
glog.Errorf("IsMountpoint check failed: %v", mntErr)
return err
}
if mountpoint {
if mntErr = nfsVolume.mounter.Unmount(dir); mntErr != nil {
if mntErr = nfsVolume.mounter.Unmount(dir, 0); mntErr != nil {
glog.Errorf("Failed to unmount: %v", mntErr)
return err
}
Expand Down Expand Up @@ -172,7 +178,7 @@ func (nfsVolume *nfs) TearDownAt(dir string) error {
return os.Remove(dir)
}

if err := nfsVolume.mounter.Unmount(dir); err != nil {
if err := nfsVolume.mounter.Unmount(dir, 0); err != nil {
glog.Errorf("Unmounting failed: %v", err)
return err
}
Expand Down
72 changes: 0 additions & 72 deletions pkg/volume/nfs/nfs_mount.go

This file was deleted.

52 changes: 11 additions & 41 deletions pkg/volume/nfs/nfs_test.go
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package nfs

import (
"fmt"
"os"
"testing"

Expand Down Expand Up @@ -67,35 +66,6 @@ func contains(modes []api.AccessModeType, mode api.AccessModeType) bool {
return false
}

type fakeNFSMounter struct {
FakeMounter mount.FakeMounter
}

func (fake *fakeNFSMounter) Mount(server string, source string, target string, readOnly bool) error {
flags := 0
if readOnly {
flags |= mount.FlagReadOnly
}
fake.FakeMounter.MountPoints = append(fake.FakeMounter.MountPoints, mount.MountPoint{Device: server, Path: target, Type: "nfs", Opts: nil, Freq: 0, Pass: 0})
return fake.FakeMounter.Mount(fmt.Sprintf("%s:%s", server, source), target, "nfs", 0, "")
}

func (fake *fakeNFSMounter) Unmount(target string) error {
fake.FakeMounter.MountPoints = []mount.MountPoint{}
return fake.FakeMounter.Unmount(target, 0)
}

func (fake *fakeNFSMounter) List() ([]mount.MountPoint, error) {
list, _ := fake.FakeMounter.List()
return list, nil
}

func (fake *fakeNFSMounter) IsMountPoint(dir string) (bool, error) {
list, _ := fake.FakeMounter.List()
isMount := len(list) > 0
return isMount, nil
}

func TestPlugin(t *testing.T) {
plugMgr := volume.VolumePluginMgr{}
plugMgr.InitPlugins(ProbeVolumePlugins(), volume.NewFakeVolumeHost("/tmp/fake", nil, nil))
Expand All @@ -107,7 +77,7 @@ func TestPlugin(t *testing.T) {
Name: "vol1",
VolumeSource: api.VolumeSource{NFS: &api.NFSVolumeSource{"localhost", "/tmp", false}},
}
fake := &fakeNFSMounter{}
fake := &mount.FakeMounter{}
builder, err := plug.(*nfsPlugin).newBuilderInternal(spec, &api.ObjectReference{UID: types.UID("poduid")}, fake)
volumePath := builder.GetPath()
if err != nil {
Expand All @@ -133,14 +103,14 @@ func TestPlugin(t *testing.T) {
if builder.(*nfs).readOnly {
t.Errorf("The volume source should not be read-only and it is.")
}
if len(fake.FakeMounter.Log) != 1 {
t.Errorf("Mount was not called exactly one time. It was called %d times.", len(fake.FakeMounter.Log))
if len(fake.Log) != 1 {
t.Errorf("Mount was not called exactly one time. It was called %d times.", len(fake.Log))
} else {
if fake.FakeMounter.Log[0].Action != mount.FakeActionMount {
t.Errorf("Unexpected mounter action: %#v", fake.FakeMounter.Log[0])
if fake.Log[0].Action != mount.FakeActionMount {
t.Errorf("Unexpected mounter action: %#v", fake.Log[0])
}
}
fake.FakeMounter.ResetLog()
fake.ResetLog()

cleaner, err := plug.(*nfsPlugin).newCleanerInternal("vol1", types.UID("poduid"), fake)
if err != nil {
Expand All @@ -157,13 +127,13 @@ func TestPlugin(t *testing.T) {
} else if !os.IsNotExist(err) {
t.Errorf("SetUp() failed: %v", err)
}
if len(fake.FakeMounter.Log) != 1 {
t.Errorf("Unmount was not called exactly one time. It was called %d times.", len(fake.FakeMounter.Log))
if len(fake.Log) != 1 {
t.Errorf("Unmount was not called exactly one time. It was called %d times.", len(fake.Log))
} else {
if fake.FakeMounter.Log[0].Action != mount.FakeActionUnmount {
t.Errorf("Unexpected mounter action: %#v", fake.FakeMounter.Log[0])
if fake.Log[0].Action != mount.FakeActionUnmount {
t.Errorf("Unexpected mounter action: %#v", fake.Log[0])
}
}

fake.FakeMounter.ResetLog()
fake.ResetLog()
}

0 comments on commit e8fc2fd

Please sign in to comment.