Skip to content

Commit

Permalink
Config: Fix panic on invalid lua-shared-dict. (kubernetes#12281)
Browse files Browse the repository at this point in the history
  • Loading branch information
AleksaC authored Nov 2, 2024
1 parent 440575e commit ac23d40
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 5 additions & 2 deletions internal/ingress/controller/template/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,11 @@ func ReadConfig(src map[string]string) config.Configuration {
delete(conf, luaSharedDictsKey)
lsd := splitAndTrimSpace(val, ",")
for _, v := range lsd {
v = strings.ReplaceAll(v, " ", "")
results := strings.SplitN(v, ":", 2)
results := strings.SplitN(strings.ReplaceAll(v, " ", ""), ":", 2)
if len(results) != 2 {
klog.Errorf("Ignoring poorly formatted Lua dictionary %v", v)
continue
}
dictName := results[0]
size := dictStrToKb(results[1])
if size < 0 {
Expand Down
5 changes: 5 additions & 0 deletions internal/ingress/controller/template/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,11 @@ func TestLuaSharedDictsParsing(t *testing.T) {
entry: map[string]string{"lua-shared-dicts": "configuration_data: 10, my_random_dict:15 , another_example:2"},
expect: map[string]int{"configuration_data": 10240, "my_random_dict": 15360, "another_example": 2048},
},
{
name: "invalid format",
entry: map[string]string{"lua-shared-dicts": "mydict: 10, invalid_dict 100"},
expect: map[string]int{"mydict": 10240},
},
{
name: "invalid size value should be ignored",
entry: map[string]string{"lua-shared-dicts": "mydict: 10, invalid_dict: 1a, bad_mb_dict:10mb"},
Expand Down

0 comments on commit ac23d40

Please sign in to comment.