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

fromJson (toJson .Chart) does not have reflexive behavior #12990

Open
SOF3 opened this issue Apr 29, 2024 · 3 comments
Open

fromJson (toJson .Chart) does not have reflexive behavior #12990

SOF3 opened this issue Apr 29, 2024 · 3 comments

Comments

@SOF3
Copy link

SOF3 commented Apr 29, 2024

Output of helm version:

version.BuildInfo{Version:"v3.14.2", GitCommit:"c309b6f0ff63856811846ce18f3bdc93d2b4d54b", GitTreeState:"clean", GoVersion:"go1.21.7"}

When I evaluate .Chart.Name, it goes through the Go exported field. But when I evaluate (fromJson (toJson .Chart)).Name, it becomes null, because toJson emits Name as the alias name instead, and fromJson would not unmarshal it back to the tagged struct and I have to write .name instead of .Name.

@SOF3
Copy link
Author

SOF3 commented Apr 29, 2024

I know it was weird of me to toJson a .Chart. I did so simply because I was passing an enormous dictionary as argument to another template, and I thought it was easier to format it as YAML and (include "internal-template" . | include "library-template"), and I tried to write the .Chart inside the YAML.

@banjoh
Copy link

banjoh commented May 2, 2024

@SOF3 do you have a complete, but minimal example which I can look at and test the failure scenario? It's a bit unclear (to me) what is happening here.

@SOF3
Copy link
Author

SOF3 commented May 14, 2024

$ cat templates/example.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: abc
data:
  release: {{include "show-keys" (toJson .Release) | toJson}}
  chart: {{include "show-keys" (toJson .Chart) | toJson}}

{{- define "show-keys" -}}
{{keys (fromJson .)}}
{{- end}}

$ helm template .
---
# Source: demo/templates/example.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: abc
data:
  release: "[Revision Service IsInstall IsUpgrade Name Namespace]"
  chart: "[version description apiVersion appVersion type IsRoot name]"

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

No branches or pull requests

3 participants