Mounter can now only be specified through flag
This commit is contained in:
parent
9d5d84ebfb
commit
8cd8f6b6cd
11 changed files with 53 additions and 25 deletions
|
@ -35,6 +35,7 @@ var (
|
|||
secretAccessKey = flag.String("secret-access-key", "", "S3 Secret Access Key to use")
|
||||
s3endpoint = flag.String("s3-endpoint", "", "S3 Endpoint URL 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)")
|
||||
)
|
||||
|
||||
|
@ -46,6 +47,7 @@ func main() {
|
|||
SecretAccessKey: *secretAccessKey,
|
||||
Endpoint: *s3endpoint,
|
||||
Region: *region,
|
||||
Mounter: *mounter,
|
||||
EncryptionKey: *encryptionKey,
|
||||
}
|
||||
|
||||
|
|
|
@ -83,6 +83,7 @@ spec:
|
|||
- "--secret-access-key=$(SECRET_ACCESS_KEY)"
|
||||
- "--s3-endpoint=$(S3_ENDPOINT)"
|
||||
- "--region=$(REGION)"
|
||||
- "--mounter=$(MOUNTER)"
|
||||
- "--encryption-key=$(ENCRYPTION_KEY)"
|
||||
- "--v=4"
|
||||
env:
|
||||
|
@ -112,6 +113,11 @@ spec:
|
|||
secretKeyRef:
|
||||
name: csi-s3-secret
|
||||
key: region
|
||||
- name: MOUNTER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: csi-s3-secret
|
||||
key: mounter
|
||||
- name: ENCRYPTION_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
|
|
@ -87,6 +87,7 @@ spec:
|
|||
- "--secret-access-key=$(SECRET_ACCESS_KEY)"
|
||||
- "--s3-endpoint=$(S3_ENDPOINT)"
|
||||
- "--region=$(REGION)"
|
||||
- "--mounter=$(MOUNTER)"
|
||||
- "--encryption-key=$(ENCRYPTION_KEY)"
|
||||
- "--v=4"
|
||||
env:
|
||||
|
@ -116,6 +117,11 @@ spec:
|
|||
secretKeyRef:
|
||||
name: csi-s3-secret
|
||||
key: region
|
||||
- name: MOUNTER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: csi-s3-secret
|
||||
key: mounter
|
||||
- name: ENCRYPTION_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
|
|
|
@ -6,7 +6,11 @@ stringData:
|
|||
accessKeyID: <YOUR_ACCESS_KEY_ID>
|
||||
secretAccessKey: <YOUR_SECRET_ACCES_KEY>
|
||||
endpoint: <S3_ENDPOINT_URL>
|
||||
# If not on S3, just set it to ""
|
||||
# If not on S3, set it to ""
|
||||
region: <S3_REGION>
|
||||
# specify which mounter to use
|
||||
# can be set to s3fs, goofys or s3ql
|
||||
mounter: <MOUNTER>
|
||||
# Currently only for s3ql
|
||||
# encryptionKey: <FS encryption key>
|
||||
# If not using s3ql, set it to ""
|
||||
encryptionKey: <FS_ENCRYPTION_KEY>
|
||||
|
|
|
@ -4,8 +4,3 @@ apiVersion: storage.k8s.io/v1
|
|||
metadata:
|
||||
name: csi-s3
|
||||
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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue