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
}
const (
defaultFsPath = "csi-fs"
)
func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
params := req.GetParameters()
capacityBytes := int64(req.GetCapacityRange().GetRequiredBytes())
@ -94,7 +90,6 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
Mounter: mounterType,
MountOptions: mountOptions,
CapacityBytes: capacityBytes,
FSPath: defaultFsPath,
}
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 {
return nil, fmt.Errorf("failed to create prefix %s: %v", path.Join(prefix, defaultFsPath), err)
if err = client.CreatePrefix(bucketName, prefix); err != nil {
return nil, fmt.Errorf("failed to create prefix %s: %v", prefix, err)
}
if err := client.SetFSMeta(meta); err != nil {

View file

@ -3,7 +3,6 @@ package mounter
import (
"fmt"
"os"
"path"
"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 {
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{
"--endpoint", goofys.endpoint,
"--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 {
args := []string{
"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),
"--daemon",
"--s3-provider=AWS",

View file

@ -38,7 +38,7 @@ func newS3backerMounter(meta *s3.FSMeta, cfg *s3.Config) (Mounter, error) {
if err != nil {
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
if meta.CapacityBytes == 0 {
meta.CapacityBytes = s3backerDefaultSize
@ -98,7 +98,7 @@ func (s3backer *s3backerMounter) mountInit(p string) error {
args := []string{
fmt.Sprintf("--blockSize=%s", s3backerBlockSize),
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",
s3backer.meta.BucketName,
p,

View file

@ -3,7 +3,6 @@ package mounter
import (
"fmt"
"os"
"path"
"github.com/ctrox/csi-s3/pkg/s3"
)
@ -42,7 +41,7 @@ func (s3fs *s3fsMounter) Mount(source string, target string) error {
return err
}
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,
"-o", "use_path_request_style",
"-o", fmt.Sprintf("url=%s", s3fs.url),

View file

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