2021-04-03 10:40:58 +00:00
|
|
|
package mounter
|
2019-03-07 19:27:02 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2021-04-05 13:07:16 +00:00
|
|
|
"path"
|
2021-04-03 10:40:58 +00:00
|
|
|
|
2021-08-24 10:33:26 +00:00
|
|
|
"github.com/yandex-cloud/k8s-csi-s3/pkg/s3"
|
2019-03-07 19:27:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Implements Mounter
|
|
|
|
type rcloneMounter struct {
|
2021-04-05 13:07:16 +00:00
|
|
|
meta *s3.FSMeta
|
2019-03-07 19:27:02 +00:00
|
|
|
url string
|
|
|
|
region string
|
|
|
|
accessKeyID string
|
|
|
|
secretAccessKey string
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
rcloneCmd = "rclone"
|
|
|
|
)
|
|
|
|
|
2021-04-05 13:07:16 +00:00
|
|
|
func newRcloneMounter(meta *s3.FSMeta, cfg *s3.Config) (Mounter, error) {
|
2019-03-07 19:27:02 +00:00
|
|
|
return &rcloneMounter{
|
2021-04-05 13:07:16 +00:00
|
|
|
meta: meta,
|
2019-03-07 19:27:02 +00:00
|
|
|
url: cfg.Endpoint,
|
|
|
|
region: cfg.Region,
|
|
|
|
accessKeyID: cfg.AccessKeyID,
|
|
|
|
secretAccessKey: cfg.SecretAccessKey,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2023-03-06 21:41:41 +00:00
|
|
|
func (rclone *rcloneMounter) Mount(target, volumeID string) error {
|
2019-03-07 19:27:02 +00:00
|
|
|
args := []string{
|
|
|
|
"mount",
|
2021-07-16 13:33:13 +00:00
|
|
|
fmt.Sprintf(":s3:%s", path.Join(rclone.meta.BucketName, rclone.meta.Prefix)),
|
2019-03-07 19:27:02 +00:00
|
|
|
fmt.Sprintf("%s", target),
|
|
|
|
"--daemon",
|
|
|
|
"--s3-provider=AWS",
|
|
|
|
"--s3-env-auth=true",
|
|
|
|
fmt.Sprintf("--s3-endpoint=%s", rclone.url),
|
|
|
|
"--allow-other",
|
|
|
|
"--vfs-cache-mode=writes",
|
|
|
|
}
|
2021-09-07 10:37:04 +00:00
|
|
|
if rclone.region != "" {
|
|
|
|
args = append(args, fmt.Sprintf("--s3-region=%s", rclone.region))
|
|
|
|
}
|
2021-07-16 13:12:57 +00:00
|
|
|
args = append(args, rclone.meta.MountOptions...)
|
2019-03-07 19:27:02 +00:00
|
|
|
os.Setenv("AWS_ACCESS_KEY_ID", rclone.accessKeyID)
|
|
|
|
os.Setenv("AWS_SECRET_ACCESS_KEY", rclone.secretAccessKey)
|
|
|
|
return fuseMount(target, rcloneCmd, args)
|
|
|
|
}
|