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

Chart v4 should handle an array of assets #3060 #3061

Merged
merged 2 commits into from
Jun 17, 2024
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
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
Loading