Skip to content

Commit e5c8724

Browse files
authored
Merge branch 'main' into default-observed-generation
2 parents eb31982 + 5e38727 commit e5c8724

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

controllers/helmrelease_controller.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,19 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
611611
// TODO(hidde): this is a bit of hack, as it mimics the way the option string is passed
612612
// to Helm from a CLI perspective. Given the parser is however not publicly accessible
613613
// while it contains all logic around parsing the target path, it is a fair trade-off.
614-
singleValue := v.TargetPath + "=" + string(valuesData)
615-
if err := strvals.ParseInto(singleValue, result); err != nil {
614+
stringValuesData := string(valuesData)
615+
const singleQuote = "'"
616+
const doubleQuote = "\""
617+
var err error
618+
if (strings.HasPrefix(stringValuesData, singleQuote) && strings.HasSuffix(stringValuesData, singleQuote)) || (strings.HasPrefix(stringValuesData, doubleQuote) && strings.HasSuffix(stringValuesData, doubleQuote)) {
619+
stringValuesData = strings.Trim(stringValuesData, singleQuote+doubleQuote)
620+
singleValue := v.TargetPath + "=" + stringValuesData
621+
err = strvals.ParseIntoString(singleValue, result)
622+
} else {
623+
singleValue := v.TargetPath + "=" + stringValuesData
624+
err = strvals.ParseInto(singleValue, result)
625+
}
626+
if err != nil {
616627
return nil, fmt.Errorf("unable to merge value from key '%s' in %s '%s' into target path '%s': %w", v.GetValuesKey(), v.Kind, namespacedName, v.TargetPath, err)
617628
}
618629
}

controllers/helmrelease_controller_test.go

+46
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,52 @@ other: values
107107
},
108108
},
109109
},
110+
{
111+
name: "target path with boolean value",
112+
resources: []runtime.Object{
113+
valuesSecret("values", map[string][]byte{"single": []byte("true")}),
114+
},
115+
references: []v2.ValuesReference{
116+
{
117+
Kind: "Secret",
118+
Name: "values",
119+
ValuesKey: "single",
120+
TargetPath: "merge.at.specific.path",
121+
},
122+
},
123+
want: chartutil.Values{
124+
"merge": map[string]interface{}{
125+
"at": map[string]interface{}{
126+
"specific": map[string]interface{}{
127+
"path": true,
128+
},
129+
},
130+
},
131+
},
132+
},
133+
{
134+
name: "target path with set-string behavior",
135+
resources: []runtime.Object{
136+
valuesSecret("values", map[string][]byte{"single": []byte("\"true\"")}),
137+
},
138+
references: []v2.ValuesReference{
139+
{
140+
Kind: "Secret",
141+
Name: "values",
142+
ValuesKey: "single",
143+
TargetPath: "merge.at.specific.path",
144+
},
145+
},
146+
want: chartutil.Values{
147+
"merge": map[string]interface{}{
148+
"at": map[string]interface{}{
149+
"specific": map[string]interface{}{
150+
"path": "true",
151+
},
152+
},
153+
},
154+
},
155+
},
110156
{
111157
name: "values reference to non existing secret",
112158
references: []v2.ValuesReference{

0 commit comments

Comments
 (0)