From c7abe28ade38c2c431e773dbf757af73da8b146a Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Sun, 29 Jul 2018 10:00:53 +0200 Subject: [PATCH] Allow configuring mounter via storageclass parameter --- deploy/kubernetes/csi-s3-driver.yaml | 6 ------ deploy/kubernetes/provisioner.yaml | 6 ------ deploy/kubernetes/secret.yaml | 3 --- deploy/kubernetes/storageclass.yaml | 4 ++++ pkg/s3/controllerserver.go | 3 +++ pkg/s3/mounter.go | 12 ++++++++++-- pkg/s3/s3-client.go | 1 + 7 files changed, 18 insertions(+), 17 deletions(-) diff --git a/deploy/kubernetes/csi-s3-driver.yaml b/deploy/kubernetes/csi-s3-driver.yaml index fcba4d4..3a548b0 100644 --- a/deploy/kubernetes/csi-s3-driver.yaml +++ b/deploy/kubernetes/csi-s3-driver.yaml @@ -83,7 +83,6 @@ spec: - "--secret-access-key=$(SECRET_ACCESS_KEY)" - "--s3-endpoint=$(S3_ENDPOINT)" - "--region=$(REGION)" - - "--mounter=$(MOUNTER)" - "--encryption-key=$(ENCRYPTION_KEY)" - "--v=4" env: @@ -113,11 +112,6 @@ spec: secretKeyRef: name: csi-s3-secret key: region - - name: MOUNTER - valueFrom: - secretKeyRef: - name: csi-s3-secret - key: mounter - name: ENCRYPTION_KEY valueFrom: secretKeyRef: diff --git a/deploy/kubernetes/provisioner.yaml b/deploy/kubernetes/provisioner.yaml index 04933d1..8c0ea1e 100644 --- a/deploy/kubernetes/provisioner.yaml +++ b/deploy/kubernetes/provisioner.yaml @@ -87,7 +87,6 @@ spec: - "--secret-access-key=$(SECRET_ACCESS_KEY)" - "--s3-endpoint=$(S3_ENDPOINT)" - "--region=$(REGION)" - - "--mounter=$(MOUNTER)" - "--encryption-key=$(ENCRYPTION_KEY)" - "--v=4" env: @@ -117,11 +116,6 @@ spec: secretKeyRef: name: csi-s3-secret key: region - - name: MOUNTER - valueFrom: - secretKeyRef: - name: csi-s3-secret - key: mounter - name: ENCRYPTION_KEY valueFrom: secretKeyRef: diff --git a/deploy/kubernetes/secret.yaml b/deploy/kubernetes/secret.yaml index 7342f52..47a8e18 100644 --- a/deploy/kubernetes/secret.yaml +++ b/deploy/kubernetes/secret.yaml @@ -8,9 +8,6 @@ stringData: endpoint: # If not on S3, set it to "" region: - # specify which mounter to use - # can be set to s3fs, goofys or s3ql - mounter: # Currently only for s3ql # If not using s3ql, set it to "" encryptionKey: diff --git a/deploy/kubernetes/storageclass.yaml b/deploy/kubernetes/storageclass.yaml index dfe708d..10ace23 100644 --- a/deploy/kubernetes/storageclass.yaml +++ b/deploy/kubernetes/storageclass.yaml @@ -4,3 +4,7 @@ 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 s3backer, s3ql, s3fs or goofys + mounter: s3backer diff --git a/pkg/s3/controllerserver.go b/pkg/s3/controllerserver.go index 6809115..693cb31 100644 --- a/pkg/s3/controllerserver.go +++ b/pkg/s3/controllerserver.go @@ -50,6 +50,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } capacityBytes := int64(req.GetCapacityRange().GetRequiredBytes()) + params := req.GetParameters() + mounter := params[mounterTypeKey] glog.V(5).Infof("Got a request to create bucket %s", volumeID) @@ -77,6 +79,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } b := &bucket{ Name: volumeID, + Mounter: mounter, CapacityBytes: capacityBytes, FSPath: fsPrefix, } diff --git a/pkg/s3/mounter.go b/pkg/s3/mounter.go index e7e1325..0135ef6 100644 --- a/pkg/s3/mounter.go +++ b/pkg/s3/mounter.go @@ -22,11 +22,17 @@ const ( goofysMounterType = "goofys" s3qlMounterType = "s3ql" s3backerMounterType = "s3backer" + mounterTypeKey = "mounter" ) // newMounter returns a new mounter depending on the mounterType parameter func newMounter(bucket *bucket, cfg *Config) (Mounter, error) { - switch cfg.Mounter { + mounter := bucket.Mounter + // Fall back to mounterType in cfg + if len(bucket.Mounter) == 0 { + mounter = cfg.Mounter + } + switch mounter { case s3fsMounterType: return newS3fsMounter(bucket, cfg) @@ -39,8 +45,10 @@ func newMounter(bucket *bucket, cfg *Config) (Mounter, error) { case s3backerMounterType: return newS3backerMounter(bucket, cfg) + default: + // default to s3backer + return newS3backerMounter(bucket, cfg) } - return nil, fmt.Errorf("Error mounting bucket %s, invalid mounter specified: %s", bucket.Name, cfg.Mounter) } func fuseMount(path string, command string, args []string) error { diff --git a/pkg/s3/s3-client.go b/pkg/s3/s3-client.go index e3c76bc..8591caf 100644 --- a/pkg/s3/s3-client.go +++ b/pkg/s3/s3-client.go @@ -23,6 +23,7 @@ type s3Client struct { type bucket struct { Name string + Mounter string FSPath string CapacityBytes int64 }