Skip to content

Commit ab7f63f

Browse files
authored
Fix issue with s3fs mount randomly taking time using IAM credentials on Private VPC clusters (#259)
* Fix issue with s3fs mount randomly taking time using IAM credentials on Private VPC clusters * Fix log messages * Fix the testcase
1 parent 0c34060 commit ab7f63f

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

cos-csi-mounter/server/s3fs.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,23 @@ func (args S3FSArgs) PopulateArgsSlice(bucket, targetPath string) ([]string, err
5959

6060
// Convert to key=value slice
6161
result := []string{bucket, targetPath}
62+
63+
// Add ibm_iam_auth first before ibm_iam_endpoint for correctly setting provided iam endpoint in s3fs-fuse for fetching token
64+
if val, ok := m["ibm_iam_auth"]; ok {
65+
if strings.ToLower(strings.TrimSpace(val)) == "true" {
66+
result = append(result, "-o", "ibm_iam_auth")
67+
} else {
68+
result = append(result, "-o", fmt.Sprintf("ibm_iam_auth=%v", val)) // pragma: allowlist secret
69+
}
70+
delete(m, "ibm_iam_auth")
71+
}
72+
73+
// Add ibm_iam_endpoint
74+
if val, ok := m["ibm_iam_endpoint"]; ok {
75+
result = append(result, "-o", fmt.Sprintf("ibm_iam_endpoint=%v", val))
76+
delete(m, "ibm_iam_endpoint")
77+
}
78+
6279
for k, v := range m {
6380
result = append(result, "-o")
6481
if strings.ToLower(strings.TrimSpace(v)) == "true" {

cos-csi-mounter/server/s3fs_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,23 @@ var (
1313
testBucket = "testBucket"
1414
testTargetPath = "/var/data/kubelet/pods/"
1515
testEndPoint = "testEndPoint"
16+
testIAMEndpoint = "https://test.iam.cloud.ibm.com"
1617
testPasswdFilePath = "testPasswdFilePath"
1718
testURL = "https://testURL"
1819
)
1920

2021
func TestS3FSPopulateArgsSlice_Success(t *testing.T) {
2122
args := S3FSArgs{
22-
AllowOther: "true",
23-
EndPoint: "testEndPoint",
23+
AllowOther: "true",
24+
EndPoint: "testEndPoint",
25+
IBMIamAuth: "true",
26+
IBMIamEndpoint: testIAMEndpoint,
27+
2428
}
2529

2630
resp, err := args.PopulateArgsSlice(testBucket, testTargetPath)
2731
assert.NoError(t, err)
28-
expectedVal := []string{testBucket, testTargetPath, "-o", "allow_other", "-o", "endpoint=" + testEndPoint}
32+
expectedVal := []string{testBucket, testTargetPath, "-o", "ibm_iam_auth", "-o", "ibm_iam_endpoint=" + testIAMEndpoint, "-o", "allow_other", "-o", "endpoint=" + testEndPoint}
2933
slices.Sort(expectedVal)
3034
slices.Sort(resp)
3135
assert.Equal(t, expectedVal, resp)

pkg/mounter/utils/mounter_utils.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/IBM/ibm-object-csi-driver/pkg/constants"
1616
"github.com/mitchellh/go-ps"
1717
"k8s.io/klog/v2"
18+
k8sMountUtils "k8s.io/mount-utils"
1819
)
1920

2021
var unmount = syscall.Unmount
@@ -32,16 +33,19 @@ type MounterOptsUtils struct {
3233

3334
func (su *MounterOptsUtils) FuseMount(path string, comm string, args []string) error {
3435
klog.Info("-FuseMount-")
35-
klog.Infof("FuseMount params:\n\tpath: <%s>\n\tcommand: <%s>\n\targs: <%s>", path, comm, args)
36+
klog.Infof("FuseMount params:\n\tpath: <%s>\n\tcommand: <%s>\n\targs: <%v>", path, comm, args)
3637
out, err := command(comm, args...).CombinedOutput()
3738
if err != nil {
39+
klog.Warningf("FuseMount: mount command failed: mounter=%s, args=%v, error=%v, output=%s", comm, args, err, string(out))
40+
klog.Infof("FuseMount: checking if path already exists and is a mountpoint: path=%s", path)
3841
if mounted, err1 := isMountpoint(path); err1 == nil && mounted { // check if bucket already got mounted
3942
klog.Infof("bucket is already mounted using '%s' mounter", comm)
4043
return nil
4144
}
42-
klog.Errorf("FuseMount: command execution failed: <%s>\nargs: <%s>\nerror: <%v>\noutput: <%v>", comm, args, err, string(out))
45+
klog.Errorf("FuseMount: path is not mountpoint, mount failed: path=%s", path)
4346
return fmt.Errorf("'%s' mount failed: <%v>", comm, string(out))
4447
}
48+
klog.Infof("mount command succeeded: mounter=%s, output=%s", comm, string(out))
4549
if err := waitForMount(path, 10*time.Second); err != nil {
4650
return err
4751
}
@@ -126,20 +130,21 @@ func isMountpoint(pathname string) (bool, error) {
126130

127131
func waitForMount(path string, timeout time.Duration) error {
128132
var elapsed time.Duration
133+
attempt := 1
129134
for {
130-
out, err := exec.Command("mountpoint", path).CombinedOutput()
131-
outStr := strings.TrimSpace(string(out))
132-
if err == nil && strings.HasSuffix(outStr, "is a mountpoint") {
133-
klog.Infof("Path is a mountpoint: pathname - %s", path)
135+
isMount, err := k8sMountUtils.New("").IsMountPoint(path)
136+
if err == nil && isMount {
137+
klog.Infof("Path is a mountpoint: pathname: %s", path)
134138
return nil
135139
}
136140

137-
klog.Infof("Mountpoint check in progress: path=%s, output=%s, err=%v", path, outStr, err)
141+
klog.Infof("Mountpoint check in progress: attempt=%d, path=%s, isMount=%v, err=%v", attempt, path, isMount, err)
138142
time.Sleep(constants.Interval)
139-
elapsed = elapsed + constants.Interval
143+
elapsed += constants.Interval
140144
if elapsed >= timeout {
141-
return fmt.Errorf("timeout waiting for mount: last check output: %s", outStr)
145+
return fmt.Errorf("timeout waiting for mount. Last check response: isMount=%v, err=%v", isMount, err)
142146
}
147+
attempt++
143148
}
144149
}
145150

0 commit comments

Comments
 (0)