Remove additional FSPath prefix

This commit is contained in:
Vitaliy Filippov 2021-07-16 16:33:13 +03:00
parent 63a2ab3476
commit 9562699f1b
6 changed files with 12 additions and 18 deletions

View file

@ -40,10 +40,6 @@ type controllerServer struct {
*csicommon.DefaultControllerServer *csicommon.DefaultControllerServer
} }
const (
defaultFsPath = "csi-fs"
)
func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
params := req.GetParameters() params := req.GetParameters()
capacityBytes := int64(req.GetCapacityRange().GetRequiredBytes()) capacityBytes := int64(req.GetCapacityRange().GetRequiredBytes())
@ -94,7 +90,6 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
Mounter: mounterType, Mounter: mounterType,
MountOptions: mountOptions, MountOptions: mountOptions,
CapacityBytes: capacityBytes, CapacityBytes: capacityBytes,
FSPath: defaultFsPath,
} }
client, err := s3.NewClientFromSecret(req.GetSecrets()) client, err := s3.NewClientFromSecret(req.GetSecrets())
@ -124,8 +119,8 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
} }
} }
if err = client.CreatePrefix(bucketName, path.Join(prefix, defaultFsPath)); err != nil { if err = client.CreatePrefix(bucketName, prefix); err != nil {
return nil, fmt.Errorf("failed to create prefix %s: %v", path.Join(prefix, defaultFsPath), err) return nil, fmt.Errorf("failed to create prefix %s: %v", prefix, err)
} }
if err := client.SetFSMeta(meta); err != nil { if err := client.SetFSMeta(meta); err != nil {

View file

@ -3,7 +3,6 @@ package mounter
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"github.com/ctrox/csi-s3/pkg/s3" "github.com/ctrox/csi-s3/pkg/s3"
) )
@ -46,7 +45,7 @@ func (goofys *goofysMounter) Unstage(stageTarget string) error {
} }
func (goofys *goofysMounter) Mount(source string, target string) error { func (goofys *goofysMounter) Mount(source string, target string) error {
fullPath := fmt.Sprintf("%s:%s", goofys.meta.BucketName, path.Join(goofys.meta.Prefix, goofys.meta.FSPath)) fullPath := fmt.Sprintf("%s:%s", goofys.meta.BucketName, goofys.meta.Prefix)
args := []string{ args := []string{
"--endpoint", goofys.endpoint, "--endpoint", goofys.endpoint,
"--region", goofys.region, "--region", goofys.region,

View file

@ -42,7 +42,7 @@ func (rclone *rcloneMounter) Unstage(stageTarget string) error {
func (rclone *rcloneMounter) Mount(source string, target string) error { func (rclone *rcloneMounter) Mount(source string, target string) error {
args := []string{ args := []string{
"mount", "mount",
fmt.Sprintf(":s3:%s", path.Join(rclone.meta.BucketName, rclone.meta.Prefix, rclone.meta.FSPath)), fmt.Sprintf(":s3:%s", path.Join(rclone.meta.BucketName, rclone.meta.Prefix)),
fmt.Sprintf("%s", target), fmt.Sprintf("%s", target),
"--daemon", "--daemon",
"--s3-provider=AWS", "--s3-provider=AWS",

View file

@ -38,7 +38,7 @@ func newS3backerMounter(meta *s3.FSMeta, cfg *s3.Config) (Mounter, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
url.Path = path.Join(url.Path, meta.BucketName, meta.Prefix, meta.FSPath) url.Path = path.Join(url.Path, meta.BucketName, meta.Prefix)
// s3backer cannot work with 0 size volumes // s3backer cannot work with 0 size volumes
if meta.CapacityBytes == 0 { if meta.CapacityBytes == 0 {
meta.CapacityBytes = s3backerDefaultSize meta.CapacityBytes = s3backerDefaultSize
@ -98,7 +98,7 @@ func (s3backer *s3backerMounter) mountInit(p string) error {
args := []string{ args := []string{
fmt.Sprintf("--blockSize=%s", s3backerBlockSize), fmt.Sprintf("--blockSize=%s", s3backerBlockSize),
fmt.Sprintf("--size=%v", s3backer.meta.CapacityBytes), fmt.Sprintf("--size=%v", s3backer.meta.CapacityBytes),
fmt.Sprintf("--prefix=%s/", path.Join(s3backer.meta.Prefix, s3backer.meta.FSPath)), fmt.Sprintf("--prefix=%s/", s3backer.meta.Prefix),
"--listBlocks", "--listBlocks",
s3backer.meta.BucketName, s3backer.meta.BucketName,
p, p,

View file

@ -3,7 +3,6 @@ package mounter
import ( import (
"fmt" "fmt"
"os" "os"
"path"
"github.com/ctrox/csi-s3/pkg/s3" "github.com/ctrox/csi-s3/pkg/s3"
) )
@ -42,7 +41,7 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error {
return err return err
} }
args := []string{ args := []string{
fmt.Sprintf("%s:/%s", s3fs.meta.BucketName, path.Join(s3fs.meta.Prefix, s3fs.meta.FSPath)), fmt.Sprintf("%s:/%s", s3fs.meta.BucketName, s3fs.meta.Prefix),
target, target,
"-o", "use_path_request_style", "-o", "use_path_request_style",
"-o", fmt.Sprintf("url=%s", s3fs.url), "-o", fmt.Sprintf("url=%s", s3fs.url),

View file

@ -38,7 +38,6 @@ type FSMeta struct {
Prefix string `json:"Prefix"` Prefix string `json:"Prefix"`
Mounter string `json:"Mounter"` Mounter string `json:"Mounter"`
MountOptions []string `json:"MountOptions"` MountOptions []string `json:"MountOptions"`
FSPath string `json:"FSPath"`
CapacityBytes int64 `json:"CapacityBytes"` CapacityBytes int64 `json:"CapacityBytes"`
} }
@ -87,10 +86,12 @@ func (client *s3Client) CreateBucket(bucketName string) error {
} }
func (client *s3Client) CreatePrefix(bucketName string, prefix string) error { func (client *s3Client) CreatePrefix(bucketName string, prefix string) error {
if prefix != "" {
_, err := client.minio.PutObject(client.ctx, bucketName, prefix+"/", bytes.NewReader([]byte("")), 0, minio.PutObjectOptions{}) _, err := client.minio.PutObject(client.ctx, bucketName, prefix+"/", bytes.NewReader([]byte("")), 0, minio.PutObjectOptions{})
if err != nil { if err != nil {
return err return err
} }
}
return nil return nil
} }