Skip to content

Commit 91ac231

Browse files
Prachi030510Prachi Shivanand Anure
andauthored
Fix object path trimming in Bucket Object Path mount support (#288)
* Fix object path trimming for Bucket Object Path mount support * Fix object path trimming for Bucket Object Path mount support * minor canges * deleted: tests/e2e/test_results.txt * minor canges * minor canges * minor canges * Remove logging of objectPath in parseCustomSecret Removed logging of the found objectPath for custom secret parsing. * minor canges * minor canges * minor canges * minor canges * minor canges * minor canges * minor canges * minor canges * minor canges * minor canges --------- Co-authored-by: Prachi Shivanand Anure <[email protected]>
1 parent bcbc8e6 commit 91ac231

13 files changed

+63
-40
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ require (
2727
k8s.io/client-go v0.33.4
2828
k8s.io/klog/v2 v2.130.1
2929
k8s.io/kubernetes v1.33.4
30+
k8s.io/mount-utils v0.33.4
3031
k8s.io/pod-security-admission v0.33.4
3132
)
3233

@@ -173,7 +174,6 @@ require (
173174
k8s.io/kube-scheduler v0.33.4 // indirect
174175
k8s.io/kubectl v0.33.4 // indirect
175176
k8s.io/kubelet v0.33.4 // indirect
176-
k8s.io/mount-utils v0.33.4 // indirect
177177
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738 // indirect
178178
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.2 // indirect
179179
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect

pkg/driver/controllerserver.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
132132
secretMapCustom := parseCustomSecret(secret)
133133
klog.Info("custom secret parameters parsed successfully, length of custom secret: ", len(secretMapCustom))
134134

135+
if objectPath, exists := secretMapCustom["objectPath"]; exists {
136+
klog.Infof("volume_id:%q objectPath found in secret: %q", volumeID, objectPath)
137+
params["objectPath"] = objectPath
138+
} else {
139+
klog.Infof("volume_id:%q no objectPath in secret (mounting bucket root)", volumeID)
140+
}
141+
135142
secretMap = secretMapCustom
136143
}
137144

@@ -497,6 +504,7 @@ func parseCustomSecret(secret *v1.Secret) map[string]string {
497504
cosEndpoint string
498505
locationConstraint string
499506
bucketVersioning string
507+
objectPath string
500508
)
501509

502510
if bytesVal, ok := secret.Data["accessKey"]; ok {
@@ -539,6 +547,10 @@ func parseCustomSecret(secret *v1.Secret) map[string]string {
539547
bucketVersioning = string(bytesVal)
540548
}
541549

550+
if bytesVal, ok := secret.Data["objectPath"]; ok {
551+
objectPath = string(bytesVal)
552+
}
553+
542554
secretMapCustom["accessKey"] = accessKey
543555
secretMapCustom["secretKey"] = secretKey
544556
secretMapCustom["apiKey"] = apiKey
@@ -549,6 +561,7 @@ func parseCustomSecret(secret *v1.Secret) map[string]string {
549561
secretMapCustom["cosEndpoint"] = cosEndpoint
550562
secretMapCustom["locationConstraint"] = locationConstraint
551563
secretMapCustom[constants.BucketVersioning] = bucketVersioning
564+
secretMapCustom["objectPath"] = objectPath
552565

553566
return secretMapCustom
554567
}

pkg/driver/controllerserver_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var (
6262
"cosEndpoint": "test-endpoint",
6363
"iamEndpoint": "testIamEndpoint",
6464
"bucketName": bucketName,
65+
"objectPath": "test/object/path",
6566
}
6667

6768
testEndpoint = flag.String("endpoint", "unix:/tmp/testcsi.sock", "Test CSI endpoint")
@@ -192,6 +193,7 @@ func TestCreateVolume(t *testing.T) {
192193
constants.BucketVersioning: "true",
193194
"locationConstraint": "test-region",
194195
"cosEndpoint": "test-endpoint",
196+
"objectPath": "test/object/path",
195197
},
196198
},
197199
},

pkg/mounter/fake_mounter-rclone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "errors"
44

55
type fakercloneMounter struct {
66
bucketName string
7-
objPath string
7+
objectPath string
88
endPoint string
99
locConstraint string
1010
authType string
@@ -20,7 +20,7 @@ type fakercloneMounter struct {
2020
func fakenewRcloneMounter(isFailedMount, isFailedUnmount bool) Mounter {
2121
return &fakercloneMounter{
2222
bucketName: bucketName,
23-
objPath: objPath,
23+
objectPath: objectPath,
2424
endPoint: endPoint,
2525
locConstraint: region,
2626
accessKeys: keys,

pkg/mounter/fake_mounter-s3fs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "errors"
44

55
type fakes3fsMounter struct {
66
bucketName string
7-
objPath string
7+
objectPath string
88
endPoint string
99
locConstraint string
1010
authType string
@@ -18,7 +18,7 @@ type fakes3fsMounter struct {
1818
func fakenewS3fsMounter(isFailedMount, isFailedUnmount bool) Mounter {
1919
return &fakes3fsMounter{
2020
bucketName: bucketName,
21-
objPath: objPath,
21+
objectPath: objectPath,
2222
endPoint: endPoint,
2323
locConstraint: region,
2424
accessKeys: keys,

pkg/mounter/fake_mounter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import "github.com/IBM/ibm-object-csi-driver/pkg/constants"
44

55
const (
66
bucketName = "fakeBucketName"
7-
objPath = "fakePath"
7+
objectPath = "fakePath"
88
endPoint = "fakeEndPoint"
99
region = "fakeRegion"
1010
keys = "fakeKeys"

pkg/mounter/mounter-rclone.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
// rcloneMounter Implements Mounter
3131
type RcloneMounter struct {
3232
BucketName string //From Secret in SC
33-
ObjPath string //From Secret in SC
33+
ObjectPath string //From Secret in SC
3434
EndPoint string //From Secret in SC
3535
LocConstraint string //From Secret in SC
3636
AuthType string
@@ -78,8 +78,8 @@ func NewRcloneMounter(secretMap map[string]string, mountOptions []string, mounte
7878
if val, check = secretMap["bucketName"]; check {
7979
mounter.BucketName = val
8080
}
81-
if val, check = secretMap["objPath"]; check {
82-
mounter.ObjPath = val
81+
if val, check = secretMap["objectPath"]; check {
82+
mounter.ObjectPath = val
8383
}
8484
if val, check = secretMap["accessKey"]; check {
8585
accessKey = val
@@ -115,8 +115,8 @@ func NewRcloneMounter(secretMap map[string]string, mountOptions []string, mounte
115115
mounter.UID = secretMap["uid"]
116116
}
117117

118-
klog.Infof("newRcloneMounter args:\n\tbucketName: [%s]\n\tobjPath: [%s]\n\tendPoint: [%s]\n\tlocationConstraint: [%s]\n\tauthType: [%s]",
119-
mounter.BucketName, mounter.ObjPath, mounter.EndPoint, mounter.LocConstraint, mounter.AuthType)
118+
klog.Infof("newRcloneMounter args:\n\tbucketName: [%s]\n\tobjectPath: [%s]\n\tendPoint: [%s]\n\tlocationConstraint: [%s]\n\tauthType: [%s]",
119+
mounter.BucketName, mounter.ObjectPath, mounter.EndPoint, mounter.LocConstraint, mounter.AuthType)
120120

121121
updatedOptions := updateMountOptions(mountOptions, secretMap)
122122
mounter.MountOptions = updatedOptions
@@ -191,8 +191,9 @@ func (rclone *RcloneMounter) Mount(source string, target string) error {
191191
return err
192192
}
193193

194-
if rclone.ObjPath != "" {
195-
bucketName = fmt.Sprintf("%s:%s/%s", remote, rclone.BucketName, rclone.ObjPath)
194+
if rclone.ObjectPath != "" {
195+
trimmedPath := strings.TrimPrefix(rclone.ObjectPath, "/")
196+
bucketName = fmt.Sprintf("%s:%s/%s", remote, rclone.BucketName, trimmedPath)
196197
} else {
197198
bucketName = fmt.Sprintf("%s:%s", remote, rclone.BucketName)
198199
}

pkg/mounter/mounter-rclone_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var (
1414
"cosEndpoint": "test-endpoint",
1515
"locationConstraint": "test-loc-constraint",
1616
"bucketName": "test-bucket-name",
17-
"objPath": "test-obj-path",
17+
"objectPath": "test-obj-path",
1818
"accessKey": "test-access-key",
1919
"secretKey": "test-secret-key",
2020
"apiKey": "test-api-key",
@@ -35,7 +35,7 @@ func TestNewRcloneMounter_Success(t *testing.T) {
3535
assert.True(t, ok)
3636

3737
assert.Equal(t, rCloneMounter.BucketName, secretMapRClone["bucketName"])
38-
assert.Equal(t, rCloneMounter.ObjPath, secretMapRClone["objPath"])
38+
assert.Equal(t, rCloneMounter.ObjectPath, secretMapRClone["objectPath"])
3939
assert.Equal(t, rCloneMounter.EndPoint, secretMapRClone["cosEndpoint"])
4040
assert.Equal(t, rCloneMounter.LocConstraint, secretMapRClone["locationConstraint"])
4141
assert.Equal(t, rCloneMounter.UID, secretMapRClone["uid"])
@@ -47,7 +47,7 @@ func TestNewRcloneMounter_Only_GID(t *testing.T) {
4747
"cosEndpoint": "test-endpoint",
4848
"locationConstraint": "test-loc-constraint",
4949
"bucketName": "test-bucket-name",
50-
"objPath": "test-obj-path",
50+
"objectPath": "test-obj-path",
5151
"accessKey": "test-access-key",
5252
"secretKey": "test-secret-key",
5353
"apiKey": "test-api-key",
@@ -60,7 +60,7 @@ func TestNewRcloneMounter_Only_GID(t *testing.T) {
6060
assert.True(t, ok)
6161

6262
assert.Equal(t, rCloneMounter.BucketName, secretMap["bucketName"])
63-
assert.Equal(t, rCloneMounter.ObjPath, secretMap["objPath"])
63+
assert.Equal(t, rCloneMounter.ObjectPath, secretMap["objectPath"])
6464
assert.Equal(t, rCloneMounter.EndPoint, secretMap["cosEndpoint"])
6565
assert.Equal(t, rCloneMounter.LocConstraint, secretMap["locationConstraint"])
6666
assert.Equal(t, rCloneMounter.GID, secretMap["gid"])
@@ -71,7 +71,7 @@ func TestNewRcloneMounter_MountOptsInSecret(t *testing.T) {
7171
"cosEndpoint": "test-endpoint",
7272
"locationConstraint": "test-loc-constraint",
7373
"bucketName": "test-bucket-name",
74-
"objPath": "test-obj-path",
74+
"objectPath": "test-obj-path",
7575
"accessKey": "test-access-key",
7676
"secretKey": "test-secret-key",
7777
"apiKey": "test-api-key",
@@ -86,7 +86,7 @@ func TestNewRcloneMounter_MountOptsInSecret(t *testing.T) {
8686
assert.True(t, ok)
8787

8888
assert.Equal(t, rCloneMounter.BucketName, secretMap["bucketName"])
89-
assert.Equal(t, rCloneMounter.ObjPath, secretMap["objPath"])
89+
assert.Equal(t, rCloneMounter.ObjectPath, secretMap["objectPath"])
9090
assert.Equal(t, rCloneMounter.EndPoint, secretMap["cosEndpoint"])
9191
assert.Equal(t, rCloneMounter.LocConstraint, secretMap["locationConstraint"])
9292
assert.Equal(t, rCloneMounter.UID, secretMap["uid"])
@@ -138,7 +138,7 @@ func TestRcloneMount_WorkerNode_Positive(t *testing.T) {
138138
EndPoint: "testEndpoint",
139139
GID: "testGID",
140140
UID: "testUID",
141-
ObjPath: "testObjPath",
141+
ObjectPath: "testObjectPath",
142142
MounterUtils: mounterUtils.NewFakeMounterUtilsImpl(mounterUtils.FakeMounterUtilsFuncStruct{
143143
FuseMountFn: func(path, comm string, args []string) error {
144144
return nil
@@ -166,7 +166,7 @@ func TestRcloneMount_WorkerNode_Negative(t *testing.T) {
166166
EndPoint: "testEndpoint",
167167
GID: "testGID",
168168
UID: "testUID",
169-
ObjPath: "testObjPath",
169+
ObjectPath: "testObjectPath",
170170
MounterUtils: mounterUtils.NewFakeMounterUtilsImpl(mounterUtils.FakeMounterUtilsFuncStruct{
171171
FuseMountFn: func(path, comm string, args []string) error {
172172
return nil

pkg/mounter/mounter-s3fs.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// s3fsMounter Implements Mounter
3030
type S3fsMounter struct {
3131
BucketName string //From Secret in SC
32-
ObjPath string //From Secret in SC
32+
ObjectPath string //From Secret in SC
3333
EndPoint string //From Secret in SC
3434
LocConstraint string //From Secret in SC
3535
AuthType string
@@ -73,8 +73,8 @@ func NewS3fsMounter(secretMap map[string]string, mountOptions []string, mounterU
7373
if val, check = secretMap["bucketName"]; check {
7474
mounter.BucketName = val
7575
}
76-
if val, check = secretMap["objPath"]; check {
77-
mounter.ObjPath = val
76+
if val, check = secretMap["objectPath"]; check {
77+
mounter.ObjectPath = val
7878
}
7979
if val, check = secretMap["accessKey"]; check {
8080
accessKey = val
@@ -100,8 +100,8 @@ func NewS3fsMounter(secretMap map[string]string, mountOptions []string, mounterU
100100
mounter.AuthType = "hmac"
101101
}
102102

103-
klog.Infof("newS3fsMounter args:\n\tbucketName: [%s]\n\tobjPath: [%s]\n\tendPoint: [%s]\n\tlocationConstraint: [%s]\n\tauthType: [%s]\n\tkpRootKeyCrn: [%s]",
104-
mounter.BucketName, mounter.ObjPath, mounter.EndPoint, mounter.LocConstraint, mounter.AuthType, mounter.KpRootKeyCrn)
103+
klog.Infof("newS3fsMounter args:\n\tbucketName: [%s]\n\tobjectPath: [%s]\n\tendPoint: [%s]\n\tlocationConstraint: [%s]\n\tauthType: [%s]\n\tkpRootKeyCrn: [%s]",
104+
mounter.BucketName, mounter.ObjectPath, mounter.EndPoint, mounter.LocConstraint, mounter.AuthType, mounter.KpRootKeyCrn)
105105

106106
updatedOptions := updateS3FSMountOptions(mountOptions, secretMap, defaultParams)
107107
mounter.MountOptions = updatedOptions
@@ -147,8 +147,12 @@ func (s3fs *S3fsMounter) Mount(source string, target string) error {
147147
return fmt.Errorf("S3FSMounter Mount: Cannot create file %s: %v", passwdFile, err)
148148
}
149149

150-
if s3fs.ObjPath != "" {
151-
bucketName = fmt.Sprintf("%s:/%s", s3fs.BucketName, s3fs.ObjPath)
150+
if s3fs.ObjectPath != "" {
151+
if strings.HasPrefix(s3fs.ObjectPath, "/") {
152+
bucketName = fmt.Sprintf("%s:%s", s3fs.BucketName, s3fs.ObjectPath)
153+
} else {
154+
bucketName = fmt.Sprintf("%s:/%s", s3fs.BucketName, s3fs.ObjectPath)
155+
}
152156
} else {
153157
bucketName = s3fs.BucketName
154158
}

pkg/mounter/mounter-s3fs_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var (
1515
"cosEndpoint": "test-endpoint",
1616
"locationConstraint": "test-loc-constraint",
1717
"bucketName": "test-bucket-name",
18-
"objPath": "test-obj-path",
18+
"objectPath": "test-obj-path",
1919
"accessKey": "test-access-key",
2020
"secretKey": "test-secret-key",
2121
"apiKey": "test-api-key",
@@ -33,7 +33,7 @@ func TestNewS3fsMounter_Success(t *testing.T) {
3333
assert.True(t, ok)
3434

3535
assert.Equal(t, s3fsMounter.BucketName, secretMap["bucketName"])
36-
assert.Equal(t, s3fsMounter.ObjPath, secretMap["objPath"])
36+
assert.Equal(t, s3fsMounter.ObjectPath, secretMap["objectPath"])
3737
assert.Equal(t, s3fsMounter.EndPoint, secretMap["cosEndpoint"])
3838
assert.Equal(t, s3fsMounter.LocConstraint, secretMap["locationConstraint"])
3939
}
@@ -43,7 +43,7 @@ func TestNewS3fsMounter_Success_Hmac(t *testing.T) {
4343
"cosEndpoint": "test-endpoint",
4444
"locationConstraint": "test-loc-constraint",
4545
"bucketName": "test-bucket-name",
46-
"objPath": "test-obj-path",
46+
"objectPath": "test-obj-path",
4747
"accessKey": "test-access-key",
4848
"secretKey": "test-secret-key",
4949
"kpRootKeyCRN": "test-kp-root-key-crn",
@@ -62,7 +62,7 @@ func TestNewS3fsMounter_Success_Hmac(t *testing.T) {
6262
assert.True(t, ok)
6363

6464
assert.Equal(t, s3fsMounter.BucketName, secretMap["bucketName"])
65-
assert.Equal(t, s3fsMounter.ObjPath, secretMap["objPath"])
65+
assert.Equal(t, s3fsMounter.ObjectPath, secretMap["objectPath"])
6666
assert.Equal(t, s3fsMounter.EndPoint, secretMap["cosEndpoint"])
6767
assert.Equal(t, s3fsMounter.LocConstraint, secretMap["locationConstraint"])
6868
}
@@ -85,7 +85,7 @@ func TestS3FSMount_NodeServer_Positive(t *testing.T) {
8585
}),
8686
LocConstraint: "test-location",
8787
MountOptions: mountOptions,
88-
ObjPath: "test-objPath",
88+
ObjectPath: "test-objectPath",
8989
}
9090

9191
err := s3fs.Mount(source, target)

0 commit comments

Comments
 (0)