Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overwriting inline values with targetPath #1060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/spec/v2/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ Changes to the combined values will trigger a new Helm release.
`.spec.valuesFrom` is an optional list to refer to ConfigMap and Secret
resources from which to take values. The values are merged in the order given,
with the later values overwriting earlier, and then [inline values](#inline-values)
overwriting those.
overwriting those. When `targetPath` is set, it will overwrite everything before,
including inline values.

An item on the list offers the following subkeys:

Expand Down
3 changes: 2 additions & 1 deletion docs/spec/v2beta2/helmreleases.md
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,8 @@ Changes to the combined values will trigger a new Helm release.
`.spec.valuesFrom` is an optional list to refer to ConfigMap and Secret
resources from which to take values. The values are merged in the order given,
with the later values overwriting earlier, and then [inline values](#inline-values)
overwriting those.
overwriting those. When `targetPath` is set, it will overwrite everything before,
including inline values.

An item on the list offers the following subkeys:

Expand Down
7 changes: 5 additions & 2 deletions internal/chartutil/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ const (

// ChartValuesFromReferences attempts to construct new chart values by resolving
// the provided references using the client, merging them in the order given.
// If provided, the values map is merged in last. Overwriting values from
// references. It returns the merged values, or an ErrValuesReference error.
// If provided, the values map is merged in last overwriting values from references,
// unless a reference has a targetPath specified, in which case it will overwrite all.
// It returns the merged values, or an ErrValuesReference error.
func ChartValuesFromReferences(ctx context.Context, client kubeclient.Client, namespace string,
values map[string]interface{}, refs ...v2.ValuesReference) (chartutil.Values, error) {

Expand Down Expand Up @@ -234,6 +235,8 @@ func ChartValuesFromReferences(ctx context.Context, client kubeclient.Client, na
}

if ref.TargetPath != "" {
result = transform.MergeMaps(result, values)

// TODO(hidde): this is a bit of hack, as it mimics the way the option string is passed
// to Helm from a CLI perspective. Given the parser is however not publicly accessible
// while it contains all logic around parsing the target path, it is a fair trade-off.
Expand Down
41 changes: 41 additions & 0 deletions internal/chartutil/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,47 @@ other: values
},
},
},
{
name: "target path precedence over all",
resources: []runtime.Object{
mockConfigMap("values", map[string]string{
"values.yaml": `flat: value
nested:
configuration:
- one
- two
- three
`,
}),
mockSecret("values", map[string][]byte{"key": []byte("value")}),
},
references: []v2.ValuesReference{
{
Kind: kindSecret,
Name: "values",
ValuesKey: "key",
TargetPath: "nested.configuration[0]",
},
{
Kind: kindConfigMap,
Name: "values",
},
},

values: `
nested:
configuration:
- list
- item
- option
`,
want: chartutil.Values{
"flat": "value",
"nested": map[string]interface{}{
"configuration": []interface{}{"value", "item", "option"},
},
},
},
{
name: "target path for string type array item",
resources: []runtime.Object{
Expand Down
Loading