armory / dinghy

Pipelines as code for Spinnaker
Apache License 2.0
31 stars 12 forks source link

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

Open haisum opened 3 years ago

haisum commented 3 years ago

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 https://github.com/armory/dinghy/pull/122 would allow a lot of flexibility and avoid these bugs.

Karthikeyanraman94 commented 3 years ago

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

thameezb commented 1 year ago

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 }}