Skip to content

Commit 654bcf8

Browse files
update CreateVolume response with secretMap values in params (#273)
* update req params with secretMap values * update req params with secretMap values * update req params with secretMap values * update req params with secretMap values * Fix UT coverage * Fix UT coverage * Fix UT coverage * Fix UT coverage * Fix UT coverage
1 parent 4e0c6f6 commit 654bcf8

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

pkg/driver/controllerserver.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* IBM Confidential
33
* OCO Source Materials
44
* IBM Cloud Kubernetes Service, 5737-D43
5-
* (C) Copyright IBM Corp. 2023 All Rights Reserved.
5+
* (C) Copyright IBM Corp. 2023, 2025 All Rights Reserved.
66
* The source code for this program is not published or otherwise divested of
77
* its trade secrets, irrespective of what has been deposited with
88
* the U.S. Copyright Office.
@@ -51,7 +51,6 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
5151
pvcNamespace string
5252
bucketVersioning string
5353
)
54-
secretMapCustom := make(map[string]string)
5554

5655
modifiedRequest, err := utils.ReplaceAndReturnCopy(req)
5756
if err != nil {
@@ -81,6 +80,9 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
8180
}
8281

8382
params := req.GetParameters()
83+
if params == nil {
84+
params = make(map[string]string)
85+
}
8486
klog.Info("CreateVolume Parameters:\n\t", params)
8587

8688
secretMap := req.GetSecrets()
@@ -127,7 +129,7 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
127129
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Secret resource not found %v", err))
128130
}
129131

130-
secretMapCustom = parseCustomSecret(secret)
132+
secretMapCustom := parseCustomSecret(secret)
131133
klog.Info("custom secret parameters parsed successfully, length of custom secret: ", len(secretMapCustom))
132134

133135
secretMap = secretMapCustom
@@ -136,6 +138,8 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
136138
endPoint = secretMap["cosEndpoint"]
137139
if endPoint == "" {
138140
endPoint = params["cosEndpoint"]
141+
} else {
142+
params["cosEndpoint"] = endPoint
139143
}
140144
if endPoint == "" {
141145
return nil, status.Error(codes.InvalidArgument, "cosEndpoint unknown")
@@ -144,28 +148,26 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
144148
locationConstraint = secretMap["locationConstraint"]
145149
if locationConstraint == "" {
146150
locationConstraint = params["locationConstraint"]
151+
} else {
152+
params["locationConstraint"] = locationConstraint
147153
}
148154
if locationConstraint == "" {
149155
return nil, status.Error(codes.InvalidArgument, "locationConstraint unknown")
150156
}
151157

152158
kpRootKeyCrn = secretMap["kpRootKeyCRN"]
153-
if kpRootKeyCrn == "" {
154-
kpRootKeyCrn = secretMapCustom["kpRootKeyCRN"]
155-
}
156159
if kpRootKeyCrn != "" {
157160
klog.Infof("key protect root key crn provided for bucket creation")
158161
}
159162

160163
mounter := secretMap["mounter"]
161164
if mounter == "" {
162165
mounter = params["mounter"]
166+
} else {
167+
params["mounter"] = mounter
163168
}
164169

165170
bucketName = secretMap["bucketName"]
166-
if bucketName == "" {
167-
bucketName = secretMapCustom["bucketName"]
168-
}
169171

170172
// Check for bucketVersioning parameter
171173
if val, ok := secretMap[constants.BucketVersioning]; ok && val != "" {
@@ -189,7 +191,7 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
189191
if err != nil {
190192
return nil, status.Error(codes.InvalidArgument, fmt.Sprintf("Error in getting credentials %v", err))
191193
}
192-
194+
klog.Infof("cosEndpoint and locationConstraint getting paased to ObjectStorageSession: %s, %s", endPoint, locationConstraint)
193195
sess := cs.cosSession.NewObjectStorageSession(endPoint, locationConstraint, creds, cs.Logger)
194196

195197
params["userProvidedBucket"] = "true"
@@ -270,7 +272,6 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
270272
}
271273

272274
func (cs *controllerServer) DeleteVolume(_ context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
273-
//secretMapCustom := make(map[string]string)
274275

275276
modifiedRequest, err := utils.ReplaceAndReturnCopy(req)
276277
if err != nil {

pkg/driver/controllerserver_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ func TestCreateVolume(t *testing.T) {
9797
VolumeContext: map[string]string{
9898
"bucketName": bucketName,
9999
"userProvidedBucket": "true",
100+
"locationConstraint": "test-region",
101+
"cosEndpoint": "test-endpoint",
100102
},
101103
},
102104
},
@@ -121,6 +123,7 @@ func TestCreateVolume(t *testing.T) {
121123
"cosEndpoint": "test-endpoint",
122124
"kpRootKeyCRN": "test-kpRootKeyCRN",
123125
constants.BucketVersioning: "true",
126+
"mounter": "s3fs",
124127
},
125128
},
126129
cosSession: &s3client.FakeCOSSessionFactory{},
@@ -129,6 +132,9 @@ func TestCreateVolume(t *testing.T) {
129132
VolumeId: testVolumeName,
130133
VolumeContext: map[string]string{
131134
"userProvidedBucket": "false",
135+
"locationConstraint": "test-region",
136+
"cosEndpoint": "test-endpoint",
137+
"mounter": "s3fs",
132138
},
133139
},
134140
},
@@ -184,6 +190,8 @@ func TestCreateVolume(t *testing.T) {
184190
constants.PVCNameKey: testPVCName,
185191
constants.PVCNamespaceKey: testPVCNs,
186192
constants.BucketVersioning: "true",
193+
"locationConstraint": "test-region",
194+
"cosEndpoint": "test-endpoint",
187195
},
188196
},
189197
},
@@ -234,6 +242,7 @@ func TestCreateVolume(t *testing.T) {
234242
},
235243
},
236244
},
245+
237246
Secrets: map[string]string{
238247
"iamEndpoint": "testIAMEndpoint",
239248
"apiKey": "testAPIKey",

0 commit comments

Comments
 (0)