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

yq does not recognize helm template yaml key: {{...}}:{{...}} #2270

Open
amir-hoseyn77 opened this issue Jan 27, 2025 · 1 comment
Open

yq does not recognize helm template yaml key: {{...}}:{{...}} #2270

amir-hoseyn77 opened this issue Jan 27, 2025 · 1 comment
Labels

Comments

@amir-hoseyn77
Copy link

Describe the bug
I have a "helm" template whose line contains key: {{aaa}}:{{bbb}} that causes a parsing error not found key! The {{aaa}}:{{bbb}} must be evaluated as value for key but yq thinks that {{aaa}} is a new key so must be in a new line!

I have checked this file with some YAML validator websites and they have trouble with that line.

Version of yq: v4.44.6
Operating system: Ubuntu 24.04
Installed via: wget binary release

Input Yaml
data1.yml:

tracing:
  enabled: {{ .Values.jaeger.enabled }}
  exporter:
    endpoint: {{ .Values.jaeger.collector.host }}:{{ include "policy-clamp-ac-a1pms-ppnt.exporter-port" . }}

Command
A simple eval even .

yq eval '.tracing.enabled' data1.yaml

Actual behavior
Error:

Error: bad file 'data1.yaml': yaml: line 3: did not find expected key

Expected behavior

{{ .Values.jaeger.enabled }}

Additional context
I have installed yq with wget. It seems snap-installed yq has some inconsistency with root privilege.

@jandubois
Copy link
Contributor

jandubois commented Jan 28, 2025

The problem is that data1.yaml is not valid YAML until after the Go template has been evaluated.

If all your template substitutions are strings, then you can work around this by putting template code in quotes:

tracing:
  enabled: '{{ .Values.jaeger.enabled }}'
  exporter:
    endpoint: '{{ .Values.jaeger.collector.host }}:{{ include "policy-clamp-ac-a1pms-ppnt.exporter-port" . }}'

But in general this is not possible, e.g. when you need the substitution to be a number or a boolean. Or if you have multi-line logic using {{ if … }}. In that case you must process the file with helm template first to turn it into valid YAML, and only then can you parse it.

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

No branches or pull requests

2 participants