Skip to content

Commit

Permalink
Chart v4 should handle an array of assets #3060 (#3061)
Browse files Browse the repository at this point in the history
<!--Thanks for your contribution. See [CONTRIBUTING](CONTRIBUTING.md)
    for Pulumi's contribution guidelines.

    Help us merge your changes more quickly by adding more details such
    as labels, milestones, and reviewers.-->

### Proposed changes

<!--Give us a brief description of what you've done and what it solves.
-->

This PR fixes the `ValueOpts` in `pkg/provider/pkg/helm` to properly
handle arrays of values when expanding
the assets.

New unit test cases were added.

### Related issues (optional)

<!--Refer to related PRs or issues: #1234, or 'Fixes #1234' or 'Closes
#1234'.
Or link to full URLs to issues or pull requests in other GitHub
repositories. -->

Closes #3060
  • Loading branch information
EronWright committed Jun 17, 2024
1 parent 4893b2f commit dc1febf
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Chart v4 should handle an array of assets (https://github.com/pulumi/pulumi-kubernetes/pull/3061)

## 4.13.0 (June 4, 2024)

### Added
Expand Down
46 changes: 26 additions & 20 deletions provider/pkg/helm/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ func (opts *ValueOpts) MergeValues(p getter.Providers) (map[string]interface{},
}

// User specified a literal value map (possibly containing assets)
values, err := marshalValues(p, opts.Values)
values, err := marshalValue(p, opts.Values)
if err != nil {
return nil, err
}
base = MergeMaps(base, values)
base = MergeMaps(base, values.(map[string]any))

return base, nil
}
Expand Down Expand Up @@ -93,34 +93,40 @@ func readAsset(p getter.Providers, asset pulumi.Asset) ([]byte, error) {
}
}

// marshalValues converts Pulumi values to Helm values.
// marshalValue converts Pulumi values to Helm values.
// - Expands assets to their content (to support --set-file).
func marshalValues(p getter.Providers, a map[string]interface{}) (map[string]interface{}, error) {
func marshalValue(p getter.Providers, v any) (any, error) {
var err error
out := make(map[string]interface{}, len(a))
for k, v := range a {
if v, ok := v.(map[string]interface{}); ok {
out[k], err = marshalValues(p, v)
switch v := v.(type) {
case map[string]any:
out := make(map[string]any, len(v))
for k, e := range v {
out[k], err = marshalValue(p, e)
if err != nil {
return nil, err
}
continue
}
if v, ok := v.(pulumi.Asset); ok {
bytes, err := readAsset(p, v)
return out, nil
case []any:
out := make([]any, len(v))
for i := 0; i < len(v); i++ {
out[i], err = marshalValue(p, v[i])
if err != nil {
return nil, err
}
out[k] = string(bytes)
continue
}
if _, ok := v.(pulumi.Archive); ok {
return nil, errors.New("Archive values are not supported as a Helm value")
}
if _, ok := v.(pulumi.Resource); ok {
return nil, errors.New("Resource values are not supported as a Helm value")
return out, nil
case pulumi.Asset:
bytes, err := readAsset(p, v)
if err != nil {
return nil, err
}
out[k] = v
return string(bytes), nil
case pulumi.Archive:
return nil, errors.New("Archive values are not supported as a Helm value")
case pulumi.Resource:
return nil, errors.New("Resource values are not supported as a Helm value")
default:
return v, nil
}
return out, nil
}
17 changes: 17 additions & 0 deletions provider/pkg/helm/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,28 @@ image:
values: map[string]interface{}{
"extra": map[string]any{
"notes": pulumi.NewStringAsset("this is a note"),
"foo": "bar",
},
},
want: map[string]interface{}{
"extra": map[string]any{
"notes": "this is a note",
"foo": "bar",
},
},
},
{
name: "arrays of assets",
values: map[string]interface{}{
"extraDeploy": []any{
pulumi.NewStringAsset("this is a note"),
"foo",
},
},
want: map[string]interface{}{
"extraDeploy": []any{
"this is a note",
"foo",
},
},
},
Expand Down

0 comments on commit dc1febf

Please sign in to comment.