helm: cannot unmarshal string into Go value of type releaseutil.SimpleHead

I am getting unmarshal error on simple validation that I am performing from my .tpl file.

I have a function defined in _helpers.tpl like:-

{{- define "actionValidate" -}}
  {{ $action := .Values.actions }}
  {{- if or (eq $action "action1") (eq $action "action2") (eq $action "action3") -}}
    true
  {{- end -}}
{{- end -}}

I 'm invoking this function from one of the .tpl file inside templates folder .

{{ include "actionValidate" . | required "Action value is incorrect. The valid values are 'action1', 'action2', 'action3' " }}

On running helm install command , I’m getting following issue:- ‘error unmarshaling JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead

However helm dry run command does not show any error and is executed successfully.

Output of helm version: Client: &version.Version{SemVer:“v2.13.1”, GitCommit:“618447cbf203d147601b4b9bd7f8c37a5d39fbb4”, GitTreeState:“clean”} Server: &version.Version{SemVer:“v2.13.1”, GitCommit:“618447cbf203d147601b4b9bd7f8c37a5d39fbb4”, GitTreeState:“clean”}

Output of kubectl version: Client Version: version.Info{Major:“1”, Minor:“14”, GitVersion:“v1.14.0”, GitCommit:“641856db18352033a0d96dbc99153fa3b27298e5”, GitTreeState:“clean”, BuildDate:“2019-03-25T15:53:57Z”, GoVersion:“go1.12.1”, Compiler:“gc”, Platform:“linux/amd64”} Server Version: version.Info{Major:“1”, Minor:“14”, GitVersion:“v1.14.0”, GitCommit:“641856db18352033a0d96dbc99153fa3b27298e5”, GitTreeState:“clean”, BuildDate:“2019-03-25T15:45:25Z”, GoVersion:“go1.12.1”, Compiler:“gc”, Platform:“linux/amd64”}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 27 (6 by maintainers)

Most upvoted comments

Same issue in my case with that:

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ template "stuff.fullname" . }}-init
  labels:
    app: {{ template "stuff.name" . }}
    chart: {{ template "stuff.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
data:
  {{- $files := .Files }}
  {{-  range tuple "init/init.sh" }}
  {{ . }}: |-
    {{ $files.Get . }}
  {{ end }}

results in

Error: YAML parse error on stuff-chart/templates/init/init.sh: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead

Does anyone know a workaround for this or an alternative to achieve the same thing I am trying to do? I am not familiar with Helm Charts and the Helm Documentation is absolutely atrocious and disgusting. I would appreciate any help leading me in the right direction.

@Saurabh-16 Looking at this again I am finding an issue during install when I use required. Output from my investigation as follows.

$ cat chrt-5550/templates/configmap.yaml 
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ .Release.Name }}-configmap
data:
  myvalue: "Hello World"
  action: {{ include "chrt-5550.actionValidate" . | required "Action value is incorrect. The valid values are 'action1', 'action2', 'action3' " }}

$ helm install --name chrt-5550 chrt-5550/ --debug --dry-run
[debug] Created tunnel using local port: '43491'

[debug] SERVER: "127.0.0.1:43491"

[debug] Original chart version: ""
[debug] CHART PATH: /home/usr1/test/helm-charts/chrt-5550

NAME:   chrt-5550
REVISION: 1
RELEASED: Thu Jun 13 16:56:42 2019
CHART: chrt-5550-0.1.0
USER-SUPPLIED VALUES:
[....]

---
# Source: chrt-5550/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: chrt-5550-configmap
data:
  myvalue: "Hello World"
  action: true
---
[....]

$ helm install --name chrt-5550 chrt-5550/
Error: release chrt-5550 failed: ConfigMap in version "v1" cannot be handled as a ConfigMap: v1.ConfigMap.Data: ReadString: expects " or n, but found t, error found in #10 byte of ...|"action":true,"myval|..., bigger context ...|{"apiVersion":"v1","data":{"action":true,"myvalue":"Hello World"},"kind":"ConfigMap","m|...

Looks like this might be a bug.

Is this an issue or there is something wrong with the code syntax .

For other travelers who find themselves here… This can also be caused by certain unprintable chars/bytes making their way into your YAML, say when going through certain editors. YMMV.

I’ve found a workaround. You can comment out the function invocation and helm will still perform the validation, failing if a truthy value is not returned by the validation function.

_helpers.tpl

{{- define "actionValidate" -}}
  {{ $action := .Values.actions }}
  {{- if or (eq $action "action1") (eq $action "action2") (eq $action "action3") -}}
    true
  {{- end -}}
{{- end -}}

...

validations.yaml

# Execute Variable Validations.

# NOTE This is a helm hack, the functions for validation are defined in _helpers.tpl
# The validation function invocations must be yaml commented out.
# Otherwise, there will be golang runtime error
# This workaround allows go parser to be happy while still fishing out invalid values

# {{ include "actionValidate" .  | required ".Values.actions value is incorrect. The valid values are 'action1', 'action2', 'action3' "  }}

Another easy solution is to just do {{ $_ := ... }}

However the error reporting for this failure is still a PITA.

For me, it’s about wrong filename of Notes… Instead of NOTES.txt, it was Notes.txt It’s working now after renaming it mv templates/Notes.txt templates.NOTES.txt

i have the same problem Or am I using the wrong method?

data:
  {{- $tfile := .Files }}
  {{- range tuple "1.toml" }}
  {{ . }}: |-
    {{ $tfile.Get . }}
  {{- end }}

1.toml

 test="123"

helm version

 PS H:\> helm.exe version
version.BuildInfo{Version:"v3.8.2", GitCommit:"6e3701edea09e5d55a8ca2aae03a68917630e91b", GitTreeState:"clean", GoVersion:"go1.17.5"}

template

PS H:\> helm.exe template test .\liunuxea\
Error: YAML parse error on linuxea/templates/1.toml: error unmarshaling JSON: while decoding JSON: json: cannot unmarshal string into Go value of type releaseutil.SimpleHead

Use --debug flag to render out invalid YAML

when modified to json

{ test="123" }

template as follows

data:
  1.toml: |-
---
# Source: linuxea/templates/1.toml
{ test="123" }

thanks

I’ve added a PR but the auto linking hasn’t worked.

I’ll re-open this as an open invitation for someone to look into this issue. I don’t have enough time to fix this but contributions are welcome. Thanks for the reproduction case @caleb15.

I’m getting this error with helm version 3.5.0.

Replication steps:

  1. helm create foo2
  2. Insert the required line from https://helm.sh/docs/howto/charts_tips_and_tricks/ at the start of the deployment yaml file with --- on the second line: sed -i '1s/^/\{\{ required "A valid .Values.who entry required!" .Values.who \}\}\n---\n/' foo2/templates/deployment.yaml
  3. Insert who: bob at the end of the values file: echo "who: bob" >> foo2/values.yaml
  4. helm template foo2

@hickeyma can you remove the stale lifecycle please? It might be more than 30 days between reports but this is a persistent issue and is now easily replicable.

+1 same issue with Helm v3.2.1

same here.when I try to create a configmap from files.

apiVersion: v1
kind: ConfigMap
metadata:
  name: xxxx
  namespace: xxxx
data:
  {{- (.Files.Glob "abc/def/src/*").AsConfig | nindent 2 }}