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

module function renders map variables in golang format instead of JSON format #123

Open
haisum opened this issue Dec 15, 2020 · 2 comments

Comments

@haisum
Copy link
Contributor

haisum commented Dec 15, 2020

Consider these module calls:

{{ module "prodHelmDeploy" "overrides" {"replicas": 4} }}
{{ module "devHelmDeploy" "overrides" "{\"replicas\": 4}" }}

When rendered in module using var function, they end up becoming map[replicas:4] instead of {"replicas": "4"}.

I created this go playground: https://play.golang.org/p/L7UseCdYgMo to find the root cause and looks like implementation of parseValue is to be blamed for this. If parseValue was similar to renderValue, we wouldn't have run into this.

Please run the playground code to see it in action. I have copied code from parse.go.

A workaround I found for this issue was to put a space before beginning "{" in value to avoid check in parseValue function.

As a side note, why does dinghy use "var" function and all this parsing to allow access to these variables. Wouldn't passing these variables in a map to template be easier and allow much more control to the users of templates? For example, helm passes .Values map to templates. A variable map combined with functions from #122 would allow a lot of flexibility and avoid these bugs.

@Karthikeyanraman94
Copy link

This still affecting us.
{{ module "prodHelmDeploy" "overrides" " {"replicas": 4}" }} - this is the working one

@thameezb
Copy link

Had the same issue. However I ended up using a gotemplate for loop to generate the output I require (in YAML).

e.g

      overrides:
      {{- range $k,$v := ( var "overrides" ) }}
        {{ $k }}: "{{ $v }}"
      {{- end }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants