Commit e2379312 authored by Dan Winter's avatar Dan Winter Committed by Matthew Fisher

fix(helm): --set for out of order list values (#4682)

When a user specifies value overrides for list values out of order,
strvals.listItem panics. Change strvals.listItem to handle this case by
re-initializing nil values to a new map.

Closes #4503
Co-authored-by: 's avatarCameron Childress <cameron@cchildress.org>
Co-authored-by: 's avatarKevin Collette <hal.collette@gmail.com>
Co-authored-by: 's avatarConnor McKelvey <connormckelvey@gmail.com>
Co-authored-by: 's avatarDan Winter <dan.j.winter@gmail.com>
Signed-off-by: 's avatarDan Winter <dan.j.winter@gmail.com>
Signed-off-by: 's avatarCameron Childress <cameron@cchildress.org>
Signed-off-by: 's avatarKevin Collette <hal.collette@gmail.com>
Signed-off-by: 's avatarConnor McKelvey <connormckelvey@gmail.com>
parent 3a8a797e
......@@ -61,7 +61,13 @@ func TestInstall(t *testing.T) {
resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}),
expected: "virgil",
},
// Install, values from yaml
{
name: "install with multiple unordered list values",
args: []string{"testdata/testcharts/alpine"},
flags: strings.Split("--name virgil --set foo[1].bar=baz,foo[0].baz=bar", " "),
resp: helm.ReleaseMock(&helm.MockReleaseOptions{Name: "virgil"}),
expected: "virgil",
},
{
name: "install with values",
args: []string{"testdata/testcharts/alpine"},
......
......@@ -288,7 +288,13 @@ func (t *parser) listItem(list []interface{}, i int) ([]interface{}, error) {
// We have a nested object. Send to t.key
inner := map[string]interface{}{}
if len(list) > i {
inner = list[i].(map[string]interface{})
var ok bool
inner, ok = list[i].(map[string]interface{})
if !ok {
// We have indices out of order. Initialize empty value.
list[i] = map[string]interface{}{}
inner = list[i].(map[string]interface{})
}
}
// Recurse
......
......@@ -294,6 +294,30 @@ func TestParseSet(t *testing.T) {
str: "nested[1][1]=1",
expect: map[string]interface{}{"nested": []interface{}{nil, []interface{}{nil, 1}}},
},
{
str: "name1.name2[0].foo=bar,name1.name2[1].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{{"foo": "bar"}, {"foo": "bar"}},
},
},
},
{
str: "name1.name2[1].foo=bar,name1.name2[0].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{{"foo": "bar"}, {"foo": "bar"}},
},
},
},
{
str: "name1.name2[1].foo=bar",
expect: map[string]interface{}{
"name1": map[string]interface{}{
"name2": []map[string]interface{}{nil, {"foo": "bar"}},
},
},
},
}
for _, tt := range tests {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment