Mounter can now only be specified through flag

This commit is contained in:
Cyrill Troxler 2018-07-21 15:23:11 +02:00
parent 9d5d84ebfb
commit 8cd8f6b6cd
11 changed files with 53 additions and 25 deletions

View file

@ -60,11 +60,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, err
}
}
mounterType := cs.s3.cfg.Mounter
if mounterType == "" {
mounterType = req.GetParameters()[mounterKey]
}
mounter, err := newMounter(mounterType, volumeID, cs.s3.cfg)
mounter, err := newMounter(volumeID, cs.s3.cfg)
if err != nil {
return nil, err
}

View file

@ -7,19 +7,18 @@ import "fmt"
type Mounter interface {
Format() error
Mount(targetPath string) error
Unmount(targetPath string) error
}
const (
mounterKey = "mounter"
s3fsMounterType = "s3fs"
goofysMounterType = "goofys"
s3qlMounterType = "s3ql"
)
// newMounter returns a new mounter depending on the mounterType parameter
func newMounter(mounterType string, bucket string, cfg *Config) (Mounter, error) {
switch mounterType {
case "":
func newMounter(bucket string, cfg *Config) (Mounter, error) {
switch cfg.Mounter {
case s3fsMounterType:
return newS3fsMounter(bucket, cfg)
@ -30,5 +29,5 @@ func newMounter(mounterType string, bucket string, cfg *Config) (Mounter, error)
return newS3qlMounter(bucket, cfg)
}
return nil, fmt.Errorf("Error mounting bucket %s, invalid mounter specified: %s", bucket, mounterType)
return nil, fmt.Errorf("Error mounting bucket %s, invalid mounter specified: %s", bucket, cfg.Mounter)
}

View file

@ -7,6 +7,7 @@ import (
"context"
goofysApi "github.com/kahing/goofys/api"
"k8s.io/kubernetes/pkg/util/mount"
)
const defaultRegion = "us-east-1"
@ -61,3 +62,7 @@ func (goofys *goofysMounter) Mount(targetPath string) error {
}
return nil
}
func (goofys *goofysMounter) Unmount(targetPath string) error {
return mount.New("").Unmount(targetPath)
}

View file

@ -4,6 +4,8 @@ import (
"fmt"
"os"
"os/exec"
"k8s.io/kubernetes/pkg/util/mount"
)
// Implements Mounter
@ -49,6 +51,10 @@ func (s3fs *s3fsMounter) Mount(targetPath string) error {
return nil
}
func (s3fs *s3fsMounter) Unmount(targetPath string) error {
return mount.New("").Unmount(targetPath)
}
func writes3fsPass(pwFileContent string) error {
pwFileName := fmt.Sprintf("%s/.passwd-s3fs", os.Getenv("HOME"))
pwFile, err := os.OpenFile(pwFileName, os.O_RDWR|os.O_CREATE, 0600)

View file

@ -26,8 +26,9 @@ type s3qlMounter struct {
}
const (
s3qlCmdMkfs = "mkfs.s3ql"
s3qlCmdMount = "mount.s3ql"
s3qlCmdMkfs = "mkfs.s3ql"
s3qlCmdMount = "mount.s3ql"
s3qlCmdUnmount = "umount.s3ql"
)
func newS3qlMounter(bucket string, cfg *Config) (Mounter, error) {
@ -78,6 +79,13 @@ func (s3ql *s3qlMounter) Mount(targetPath string) error {
return s3qlCmd(s3qlCmdMount, append(args, s3ql.options...), nil)
}
func (s3ql *s3qlMounter) Unmount(targetPath string) error {
args := []string{
targetPath,
}
return s3qlCmd(s3qlCmdUnmount, append(args, s3ql.options...), nil)
}
func s3qlCmd(s3qlCmd string, args []string, stdin io.Reader) error {
cmd := exec.Command(s3qlCmd, args...)
if stdin != nil {

View file

@ -78,11 +78,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
glog.V(4).Infof("target %v\ndevice %v\nreadonly %v\nvolumeId %v\nattributes %v\nmountflags %v\n",
targetPath, deviceID, readOnly, volumeID, attrib, mountFlags)
mounterType := ns.s3.cfg.Mounter
if mounterType == "" {
mounterType = attrib[mounterKey]
}
mounter, err := newMounter(mounterType, volumeID, ns.s3.cfg)
mounter, err := newMounter(volumeID, ns.s3.cfg)
if err != nil {
return nil, err
}
@ -105,7 +101,11 @@ func (ns *nodeServer) NodeUnpublishVolume(ctx context.Context, req *csi.NodeUnpu
return nil, status.Error(codes.InvalidArgument, "Target path missing in request")
}
err := mount.New("").Unmount(req.GetTargetPath())
mounter, err := newMounter(req.GetVolumeId(), ns.s3.cfg)
if err != nil {
return nil, err
}
mounter.Unmount(req.GetTargetPath())
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}