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

@ -35,6 +35,7 @@ var (
secretAccessKey = flag.String("secret-access-key", "", "S3 Secret Access Key to use") secretAccessKey = flag.String("secret-access-key", "", "S3 Secret Access Key to use")
s3endpoint = flag.String("s3-endpoint", "", "S3 Endpoint URL to use") s3endpoint = flag.String("s3-endpoint", "", "S3 Endpoint URL to use")
region = flag.String("region", "", "S3 Region to use") region = flag.String("region", "", "S3 Region to use")
mounter = flag.String("mounter", "s3fs", "Specify which Mounter to use")
encryptionKey = flag.String("encryption-key", "", "Encryption key for file system (only used with s3ql)") encryptionKey = flag.String("encryption-key", "", "Encryption key for file system (only used with s3ql)")
) )
@ -46,6 +47,7 @@ func main() {
SecretAccessKey: *secretAccessKey, SecretAccessKey: *secretAccessKey,
Endpoint: *s3endpoint, Endpoint: *s3endpoint,
Region: *region, Region: *region,
Mounter: *mounter,
EncryptionKey: *encryptionKey, EncryptionKey: *encryptionKey,
} }

View file

@ -83,6 +83,7 @@ spec:
- "--secret-access-key=$(SECRET_ACCESS_KEY)" - "--secret-access-key=$(SECRET_ACCESS_KEY)"
- "--s3-endpoint=$(S3_ENDPOINT)" - "--s3-endpoint=$(S3_ENDPOINT)"
- "--region=$(REGION)" - "--region=$(REGION)"
- "--mounter=$(MOUNTER)"
- "--encryption-key=$(ENCRYPTION_KEY)" - "--encryption-key=$(ENCRYPTION_KEY)"
- "--v=4" - "--v=4"
env: env:
@ -112,6 +113,11 @@ spec:
secretKeyRef: secretKeyRef:
name: csi-s3-secret name: csi-s3-secret
key: region key: region
- name: MOUNTER
valueFrom:
secretKeyRef:
name: csi-s3-secret
key: mounter
- name: ENCRYPTION_KEY - name: ENCRYPTION_KEY
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:

View file

@ -87,6 +87,7 @@ spec:
- "--secret-access-key=$(SECRET_ACCESS_KEY)" - "--secret-access-key=$(SECRET_ACCESS_KEY)"
- "--s3-endpoint=$(S3_ENDPOINT)" - "--s3-endpoint=$(S3_ENDPOINT)"
- "--region=$(REGION)" - "--region=$(REGION)"
- "--mounter=$(MOUNTER)"
- "--encryption-key=$(ENCRYPTION_KEY)" - "--encryption-key=$(ENCRYPTION_KEY)"
- "--v=4" - "--v=4"
env: env:
@ -116,6 +117,11 @@ spec:
secretKeyRef: secretKeyRef:
name: csi-s3-secret name: csi-s3-secret
key: region key: region
- name: MOUNTER
valueFrom:
secretKeyRef:
name: csi-s3-secret
key: mounter
- name: ENCRYPTION_KEY - name: ENCRYPTION_KEY
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:

View file

@ -6,7 +6,11 @@ stringData:
accessKeyID: <YOUR_ACCESS_KEY_ID> accessKeyID: <YOUR_ACCESS_KEY_ID>
secretAccessKey: <YOUR_SECRET_ACCES_KEY> secretAccessKey: <YOUR_SECRET_ACCES_KEY>
endpoint: <S3_ENDPOINT_URL> endpoint: <S3_ENDPOINT_URL>
# If not on S3, just set it to "" # If not on S3, set it to ""
region: <S3_REGION> region: <S3_REGION>
# specify which mounter to use
# can be set to s3fs, goofys or s3ql
mounter: <MOUNTER>
# Currently only for s3ql # Currently only for s3ql
# encryptionKey: <FS encryption key> # If not using s3ql, set it to ""
encryptionKey: <FS_ENCRYPTION_KEY>

View file

@ -4,8 +4,3 @@ apiVersion: storage.k8s.io/v1
metadata: metadata:
name: csi-s3 name: csi-s3
provisioner: ch.ctrox.csi.s3-driver provisioner: ch.ctrox.csi.s3-driver
parameters:
# specify which mounter to use
# can be set to s3fs, goofys or s3ql
# s3fs is the default
# mounter: s3ql

View file

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

View file

@ -7,19 +7,18 @@ import "fmt"
type Mounter interface { type Mounter interface {
Format() error Format() error
Mount(targetPath string) error Mount(targetPath string) error
Unmount(targetPath string) error
} }
const ( const (
mounterKey = "mounter"
s3fsMounterType = "s3fs" s3fsMounterType = "s3fs"
goofysMounterType = "goofys" goofysMounterType = "goofys"
s3qlMounterType = "s3ql" s3qlMounterType = "s3ql"
) )
// newMounter returns a new mounter depending on the mounterType parameter // newMounter returns a new mounter depending on the mounterType parameter
func newMounter(mounterType string, bucket string, cfg *Config) (Mounter, error) { func newMounter(bucket string, cfg *Config) (Mounter, error) {
switch mounterType { switch cfg.Mounter {
case "":
case s3fsMounterType: case s3fsMounterType:
return newS3fsMounter(bucket, cfg) return newS3fsMounter(bucket, cfg)
@ -30,5 +29,5 @@ func newMounter(mounterType string, bucket string, cfg *Config) (Mounter, error)
return newS3qlMounter(bucket, cfg) 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" "context"
goofysApi "github.com/kahing/goofys/api" goofysApi "github.com/kahing/goofys/api"
"k8s.io/kubernetes/pkg/util/mount"
) )
const defaultRegion = "us-east-1" const defaultRegion = "us-east-1"
@ -61,3 +62,7 @@ func (goofys *goofysMounter) Mount(targetPath string) error {
} }
return nil return nil
} }
func (goofys *goofysMounter) Unmount(targetPath string) error {
return mount.New("").Unmount(targetPath)
}

View file

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

View file

@ -26,8 +26,9 @@ type s3qlMounter struct {
} }
const ( const (
s3qlCmdMkfs = "mkfs.s3ql" s3qlCmdMkfs = "mkfs.s3ql"
s3qlCmdMount = "mount.s3ql" s3qlCmdMount = "mount.s3ql"
s3qlCmdUnmount = "umount.s3ql"
) )
func newS3qlMounter(bucket string, cfg *Config) (Mounter, error) { 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) 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 { func s3qlCmd(s3qlCmd string, args []string, stdin io.Reader) error {
cmd := exec.Command(s3qlCmd, args...) cmd := exec.Command(s3qlCmd, args...)
if stdin != nil { 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", glog.V(4).Infof("target %v\ndevice %v\nreadonly %v\nvolumeId %v\nattributes %v\nmountflags %v\n",
targetPath, deviceID, readOnly, volumeID, attrib, mountFlags) targetPath, deviceID, readOnly, volumeID, attrib, mountFlags)
mounterType := ns.s3.cfg.Mounter mounter, err := newMounter(volumeID, ns.s3.cfg)
if mounterType == "" {
mounterType = attrib[mounterKey]
}
mounter, err := newMounter(mounterType, volumeID, ns.s3.cfg)
if err != nil { if err != nil {
return nil, err 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") 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 { if err != nil {
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }