Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 46 additions & 31 deletions pkg/mounter/mounter-rclone.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,26 @@ import (
// Mounter interface defined in mounter.go
// rcloneMounter Implements Mounter
type RcloneMounter struct {
BucketName string //From Secret in SC
ObjPath string //From Secret in SC
EndPoint string //From Secret in SC
LocConstraint string //From Secret in SC
AuthType string
AccessKeys string
KpRootKeyCrn string
UID string
GID string
MountOptions []string
MounterUtils utils.MounterUtils
BucketName string //From Secret in SC
ObjPath string //From Secret in SC
EndPoint string //From Secret in SC
LocConstraint string //From Secret in SC
AuthType string
AccessKeys string
serviceInstanceID string
KpRootKeyCrn string
IAMEndpoint string
UID string
GID string
MountOptions []string
MounterUtils utils.MounterUtils
}

const (
configFileName = "rclone.conf"
remote = "ibmcos"
s3Type = "s3"
cosProvider = "IBMCOS"
envAuth = "true"
)

var (
Expand All @@ -63,8 +64,9 @@ func NewRcloneMounter(secretMap map[string]string, mountOptions []string, mounte
check bool
accessKey string
secretKey string
// apiKey string
mounter *RcloneMounter
apiKey string
serviceId string
mounter *RcloneMounter
)

mounter = &RcloneMounter{}
Expand All @@ -90,21 +92,24 @@ func NewRcloneMounter(secretMap map[string]string, mountOptions []string, mounte
if val, check = secretMap["kpRootKeyCRN"]; check {
mounter.KpRootKeyCrn = val
}
if val, check = secretMap["iamEndpoint"]; check {
mounter.IAMEndpoint = val
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once we expose ibm_iam_endpoint option in rclone, then we need to set this in rclone.conf

}
if val, check = secretMap["apiKey"]; check {
apiKey = val
}
if val, check = secretMap["serviceId"]; check {
serviceId = val
}

// Since IAM support for rClone is not there and api key is required param now, commented below piece of code
// Uncommnet when IAM support for rClone is available

// if val, check = secretMap["apiKey"]; check {
// apiKey = val
// }

// if apiKey != "" {
// mounter.AccessKeys = fmt.Sprintf(":%s", apiKey)
// mounter.AuthType = "iam"
// } else {
mounter.AccessKeys = fmt.Sprintf("%s:%s", accessKey, secretKey)
mounter.AuthType = "hmac"
// }
if apiKey != "" && serviceId != "" {
mounter.AccessKeys = apiKey
mounter.serviceInstanceID = serviceId
mounter.AuthType = "iam"
} else {
mounter.AccessKeys = fmt.Sprintf("%s:%s", accessKey, secretKey)
mounter.AuthType = "hmac"
}

if val, check = secretMap["gid"]; check {
mounter.GID = val
Expand Down Expand Up @@ -250,20 +255,30 @@ func (rclone *RcloneMounter) Unmount(target string) error {
}

func createConfig(configPathWithVolID string, rclone *RcloneMounter) error {
var accessKey, secretKey string
keys := strings.Split(rclone.AccessKeys, ":")
if len(keys) == 2 {
var accessKey, secretKey, apiKey, envAuth, v2Auth string
if rclone.AuthType == "hmac" {
keys := strings.Split(rclone.AccessKeys, ":")
accessKey = keys[0]
secretKey = keys[1]
envAuth = "true"
v2Auth = "false"
} else {
apiKey = rclone.AccessKeys
v2Auth = "true"
envAuth = "false"
}

configParams := []string{
"[" + remote + "]",
"type = " + s3Type,
"endpoint = " + rclone.EndPoint,
"provider = " + cosProvider,
"env_auth = " + envAuth,
"v2_auth = " + v2Auth,
"access_key_id = " + accessKey,
"secret_access_key = " + secretKey,
"ibm_api_key = " + apiKey,
"ibm_resource_instance_id = " + rclone.serviceInstanceID,
}

if rclone.LocConstraint != "" {
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/driver_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (su *DriverStatsUtils) CheckMount(targetPath string) error {
out, err := exec.Command("mountpoint", targetPath).CombinedOutput()
outStr := strings.TrimSpace(string(out))
if err != nil {
klog.V(3).Infof("Check if mountPath exists: Output string %+v", outStr)
klog.V(3).Infof("Check if mountPath exists: Output string- %+v", outStr)
if strings.HasSuffix(outStr, "No such file or directory") {
if err = os.MkdirAll(targetPath, 0750); err != nil {
klog.V(2).Infof("checkMount: Error: %+v", err)
Expand Down