Skip to content

Commit

Permalink
webdav mount added
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioLangaritaBenitez committed Jun 21, 2024
1 parent 8bcce24 commit 84b5f92
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 39 deletions.
74 changes: 38 additions & 36 deletions pkg/handlers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,51 +384,53 @@ func createBuckets(service *types.Service, cfg *types.Config, minIOAdminClient *

if service.Mount.Provider != "" {
provID, provName = getProviderInfo(service.Mount.Provider)
if provName == types.MinIOName {
// Check if the provider identifier is defined in StorageProviders
if !isStorageProviderDefined(provName, provID, service.StorageProviders) {
return fmt.Errorf("the StorageProvider \"%s.%s\" is not defined", provName, provID)
}

// Check if the provider identifier is defined in StorageProviders
if !isStorageProviderDefined(provName, provID, service.StorageProviders) {
return fmt.Errorf("the StorageProvider \"%s.%s\" is not defined", provName, provID)
}

path := strings.Trim(service.Mount.Path, " /")
// Split buckets and folders from path
splitPath := strings.SplitN(path, "/", 2)
path := strings.Trim(service.Mount.Path, " /")
// Split buckets and folders from path
splitPath := strings.SplitN(path, "/", 2)

// Currently only MinIO/S3 are supported
// Use the appropriate client
if provName == types.MinIOName {
s3Client = service.StorageProviders.MinIO[provID].GetS3Client()
} else {
s3Client = service.StorageProviders.S3[provID].GetS3Client()
}
// Create bucket
_, err := s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(splitPath[0]),
})
if err != nil {
if aerr, ok := err.(awserr.Error); ok {
// Check if the error is caused because the bucket already exists
if aerr.Code() == s3.ErrCodeBucketAlreadyExists || aerr.Code() == s3.ErrCodeBucketAlreadyOwnedByYou {
log.Printf("The bucket \"%s\" already exists\n", splitPath[0])
} else {
return fmt.Errorf("error creating bucket %s: %v", splitPath[0], err)
}
// Currently only MinIO/S3 are supported
// Use the appropriate client
if provName == types.MinIOName {
s3Client = service.StorageProviders.MinIO[provID].GetS3Client()
} else {
return fmt.Errorf("error creating bucket %s: %v", splitPath[0], err)
s3Client = service.StorageProviders.S3[provID].GetS3Client()
}
}
// Create folder(s)
if len(splitPath) == 2 {
// Add "/" to the end of the key in order to create a folder
folderKey := fmt.Sprintf("%s/", splitPath[1])
_, err := s3Client.PutObject(&s3.PutObjectInput{
// Create bucket
_, err := s3Client.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(splitPath[0]),
Key: aws.String(folderKey),
})
if err != nil {
return fmt.Errorf("error creating folder \"%s\" in bucket \"%s\": %v", folderKey, splitPath[0], err)
if aerr, ok := err.(awserr.Error); ok {
// Check if the error is caused because the bucket already exists
if aerr.Code() == s3.ErrCodeBucketAlreadyExists || aerr.Code() == s3.ErrCodeBucketAlreadyOwnedByYou {
log.Printf("The bucket \"%s\" already exists\n", splitPath[0])
} else {
return fmt.Errorf("error creating bucket %s: %v", splitPath[0], err)
}
} else {
return fmt.Errorf("error creating bucket %s: %v", splitPath[0], err)
}
}
// Create folder(s)
if len(splitPath) == 2 {
// Add "/" to the end of the key in order to create a folder
folderKey := fmt.Sprintf("%s/", splitPath[1])
_, err := s3Client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(splitPath[0]),
Key: aws.String(folderKey),
})
if err != nil {
return fmt.Errorf("error creating folder \"%s\" in bucket \"%s\": %v", folderKey, splitPath[0], err)
}
}
}

}

return nil
Expand Down
39 changes: 36 additions & 3 deletions pkg/types/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ import (
const (
rcloneContainerName = "rclone-container"
rcloneContainerImage = "rclone/rclone"
rcloneStartCommand = `mkdir -p $MNT_POINT/$MINIO_BUCKET
minioCommand = `mkdir -p $MNT_POINT/$MINIO_BUCKET
rclone config create minio s3 provider=Minio access_key_id=$AWS_ACCESS_KEY_ID secret_access_key=$AWS_SECRET_ACCESS_KEY endpoint=$MINIO_ENDPOINT acl=public-read-write
rclone mount minio:/$MINIO_BUCKET $MNT_POINT/$MINIO_BUCKET --dir-cache-time 10s --allow-other --allow-non-empty --umask 0007 --uid 1000 --gid 100 --allow-other --no-checksum &
rclone mount minio:/$MINIO_BUCKET $MNT_POINT/$MINIO_BUCKET `
webdavCommand = `mkdir -p $MNT_POINT/$WEBDAV_FOLDER
rclone config create dcache webdav url=$WEBDAV_HOSTNAME vendor=other user=$WEBDAV_LOGIN pass=$WEBDAV_PASSWORD
rclone mount dcache:$WEBDAV_FOLDER $MNT_POINT/$WEBDAV_FOLDER --vfs-cache-mode full `
communCommand = `--dir-cache-time 10s --allow-other --allow-non-empty --umask 0007 --uid 1000 --gid 100 --allow-other --no-checksum &
pid=$!
while true; do
if [ -f /tmpfolder/finish-file ]; then
Expand Down Expand Up @@ -88,7 +92,7 @@ func sidecarPodSpec(service Service) v1.Container {
Name: rcloneContainerName,
Image: rcloneContainerImage,
Command: []string{"/bin/sh"},
Args: []string{"-c", rcloneStartCommand},
//Args: []string{"-c", rcloneStartCommand},
Ports: []v1.ContainerPort{
{
ContainerPort: 9000,
Expand Down Expand Up @@ -119,6 +123,12 @@ func sidecarPodSpec(service Service) v1.Container {
if provider[0] == MinIOName {
MinIOEnvVars := setMinIOEnvVars(service, provider[1])
container.Env = append(container.Env, MinIOEnvVars...)
container.Args = []string{"-c", minioCommand + communCommand}
}
if provider[0] == WebDavName {
WebDavEnvVars := setWebDavEnvVars(service, provider[1])
container.Env = append(container.Env, WebDavEnvVars...)
container.Args = []string{"-c", webdavCommand + communCommand}
}
return container

Expand Down Expand Up @@ -146,3 +156,26 @@ func setMinIOEnvVars(service Service, providerId string) []v1.EnvVar {
}
return credentials
}

func setWebDavEnvVars(service Service, providerId string) []v1.EnvVar {
//service.Mount.Provider
credentials := []v1.EnvVar{
{
Name: "WEBDAV_FOLDER",
Value: service.Mount.Path,
},
{
Name: "WEBDAV_LOGIN",
Value: service.StorageProviders.WebDav[providerId].Login,
},
{
Name: "WEBDAV_PASSWORD",
Value: service.StorageProviders.WebDav[providerId].Password,
},
{
Name: "WEBDAV_HOSTNAME",
Value: "https://" + service.StorageProviders.WebDav[providerId].Hostname,
},
}
return credentials
}

0 comments on commit 84b5f92

Please sign in to comment.