Skip to content

Commit 354d960

Browse files
authored
Merge pull request #1198 from k8s-infra-cherrypick-robot/cherry-pick-1196-to-release-1.22
[release-1.22] fix: mountPermission settting issue due to case insensitive parameter
2 parents db43866 + 74c677c commit 354d960

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

pkg/blob/blob.go

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

975+
// getValueInMap get value from map by key
976+
// key in the map is case insensitive
977+
func getValueInMap(m map[string]string, key string) string {
978+
if m == nil {
979+
return ""
980+
}
981+
for k, v := range m {
982+
if strings.EqualFold(k, key) {
983+
return v
984+
}
985+
}
986+
return ""
987+
}
988+
975989
// replaceWithMap replace key with value for str
976990
func replaceWithMap(str string, m map[string]string) string {
977991
for k, v := range m {

pkg/blob/blob_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,52 @@ func TestSetKeyValueInMap(t *testing.T) {
15611561
}
15621562
}
15631563

1564+
func TestGetValueInMap(t *testing.T) {
1565+
tests := []struct {
1566+
desc string
1567+
m map[string]string
1568+
key string
1569+
expected string
1570+
}{
1571+
{
1572+
desc: "nil map",
1573+
key: "key",
1574+
expected: "",
1575+
},
1576+
{
1577+
desc: "empty map",
1578+
m: map[string]string{},
1579+
key: "key",
1580+
expected: "",
1581+
},
1582+
{
1583+
desc: "non-empty map",
1584+
m: map[string]string{"k": "v"},
1585+
key: "key",
1586+
expected: "",
1587+
},
1588+
{
1589+
desc: "same key already exists",
1590+
m: map[string]string{"subDir": "value2"},
1591+
key: "subDir",
1592+
expected: "value2",
1593+
},
1594+
{
1595+
desc: "case insensitive key already exists",
1596+
m: map[string]string{"subDir": "value2"},
1597+
key: "subdir",
1598+
expected: "value2",
1599+
},
1600+
}
1601+
1602+
for _, test := range tests {
1603+
result := getValueInMap(test.m, test.key)
1604+
if result != test.expected {
1605+
t.Errorf("test[%s]: unexpected output: %v, expected result: %v", test.desc, result, test.expected)
1606+
}
1607+
}
1608+
}
1609+
15641610
func TestReplaceWithMap(t *testing.T) {
15651611
tests := []struct {
15661612
desc string

pkg/blob/nodeserver.go

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

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

0 commit comments

Comments
 (0)