Skip to content

Commit 42e8b23

Browse files
authored
Merge pull request #1650 from kubernetes-sigs/fix-mount-permission-issue-1.28
[release-1.28] fix: mountPermission settting issue due to case insensitive parameter
2 parents 2a48215 + af78fe6 commit 42e8b23

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

pkg/azurefile/nodeserver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
7676
return &csi.NodePublishVolumeResponse{}, err
7777
}
7878

79-
if perm := context[mountPermissionsField]; perm != "" {
79+
if perm := getValueInMap(context, mountPermissionsField); perm != "" {
8080
var err error
8181
if mountPermissions, err = strconv.ParseUint(perm, 8, 32); err != nil {
8282
return nil, status.Errorf(codes.InvalidArgument, fmt.Sprintf("invalid mountPermissions %s", perm))

pkg/azurefile/utils.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,20 @@ func setKeyValueInMap(m map[string]string, key, value string) {
266266
m[key] = value
267267
}
268268

269+
// getValueInMap get value from map by key
270+
// key in the map is case insensitive
271+
func getValueInMap(m map[string]string, key string) string {
272+
if m == nil {
273+
return ""
274+
}
275+
for k, v := range m {
276+
if strings.EqualFold(k, key) {
277+
return v
278+
}
279+
}
280+
return ""
281+
}
282+
269283
// replaceWithMap replace key with value for str
270284
func replaceWithMap(str string, m map[string]string) string {
271285
for k, v := range m {

pkg/azurefile/utils_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,52 @@ func TestSetKeyValueInMap(t *testing.T) {
538538
}
539539
}
540540

541+
func TestGetValueInMap(t *testing.T) {
542+
tests := []struct {
543+
desc string
544+
m map[string]string
545+
key string
546+
expected string
547+
}{
548+
{
549+
desc: "nil map",
550+
key: "key",
551+
expected: "",
552+
},
553+
{
554+
desc: "empty map",
555+
m: map[string]string{},
556+
key: "key",
557+
expected: "",
558+
},
559+
{
560+
desc: "non-empty map",
561+
m: map[string]string{"k": "v"},
562+
key: "key",
563+
expected: "",
564+
},
565+
{
566+
desc: "same key already exists",
567+
m: map[string]string{"subDir": "value2"},
568+
key: "subDir",
569+
expected: "value2",
570+
},
571+
{
572+
desc: "case insensitive key already exists",
573+
m: map[string]string{"subDir": "value2"},
574+
key: "subdir",
575+
expected: "value2",
576+
},
577+
}
578+
579+
for _, test := range tests {
580+
result := getValueInMap(test.m, test.key)
581+
if result != test.expected {
582+
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expected)
583+
}
584+
}
585+
}
586+
541587
func TestReplaceWithMap(t *testing.T) {
542588
tests := []struct {
543589
desc string

0 commit comments

Comments
 (0)