You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
toYaml removes all quotes and yaml types breaks #4262
Reacted by Will Plano, kroonprins, Keisuke Hirota, Philipp Knobel, Yevhen Katrechko, Jeff Valore, Anupam, Devendra Singh, Bryant Rockoff, Jocko and 18 more
Reacted by Adam Hamsik, Marc Bihlmaier, Ronny Lehmann, Linhang Kevin Nie, Philipp Knobel, David J. M. Karlsen, Yevhen Katrechko, Lindsay Grace and Milan Baran
oh I see what you mean. However, both are considered strings though according to the YAML spec though, right? That should still work as a string as single, double and unquoted values are accepted as strings according to the spec.
Reacted by Steve Drew, Nick Huanca, Nikolay Arhipov, jasmeetArmory, Philipp Knobel, David J. M. Karlsen, gk, Eric Roberts, Alikhan, Tobias Kuhn and 8 more
So I'm trying to us toYaml to dynamically inject custom Environment variables along side required environment variables in my container: definition in my Helm chart.
The problem is that regardless of whether the value is a numer or string, the requirement is that the environment value needs to be quoted. Because toYaml is unquoting it my helm chart is failing.
Anyone know how I can prevent this?
Reacted by David J. M. Karlsen, Iván Barbecho Delgado, Nathan Grass and Tewfik Ghariani
I solved it by not using toYaml ... That's a seemingly direct way to get data from a values file to append to my env: key, but this solution allows me to make sure all of the values are quoted:
In my opinion this is a bug and not an question/support like it is actually labeled.
Reacted by Ali, Jocko, Konrad Ponichtera, Akram S., Casey Buto, Tobias Kuhn, Lindsay Grace, Quinn Bast, Douglas Naphas, Emil 'Skeen' Madsen and 19 more
After trying for an hour to stop toYaml from removing the quotes that I wanted to keep, I found a solution for my specific usage:
To begin, I have this entry in my values.yaml (block 1)
global:
properties:
mad:
person: 'My id: 1234'
where "1234" should actually come from another entry in my values.yaml (note that I hard coded the id "1234" above but this will be addressed by the solution later). The following entry is also in my values.yaml:
person:
id: 1234
Now I needed to create a file named "mad.yaml" with the following content using toYaml (note the single code around the value) (target i):
mad:
person: 'My id: 1234'
The code that I will use to create the file "mad.yaml" is like this (code A):
I needed to put a yaml defined in a values file as a string with yaml format, and in order to do that i used toYaml.
Unfortunately in that yaml portion i had a string which contained some special characters like : and }
I solved by using the backslash \ before special characters.
Not being able to keep the type of the original yaml is a very surprising behavior. One expects the string "1" to stay a string and not turn into a yaml integer 1: The issue seems to be in "sigs.k8s.io/yaml" package in the Unmarshal function as the following program demonstrates:
package main
import (
"fmt"
"sigs.k8s.io/yaml"
)
var data = `
a: Easy!
b:
c: 2
d: [3, 4]
e: "5"
`
func main() {
// Unmarshal the YAML back into a Person struct.
m := map[string]interface{}{}
err = yaml.Unmarshal([]byte(data), &m)
if err != nil {
fmt.Printf("err: %v\n", err)
return
}
fmt.Println(m)
}
/*
age: 30
name: John
map[a:Easy! b:map[c:2 d:[3 4] e:5]]
*/
The reference go-yaml v2 & v3 program (with the "e" addition) keeps the quotes just fine.
That's pretty garbage. Could also explain why people keep needing quotes even though the yaml spec doesn't require them. Eg. why does CronJob schedule need to be quoted? If Kubernetes won't fix its problems, then Helm should not insist "we're confirming to YAML, don't look at us!" Otherwise that's garbage behavior from both Helm and Kubernetes. What a crappy ecosystem.
The fix is pretty "simple." Stop using these parsers, and write (fork) your own that tracks the quote status of strings on Unmarshal and reproduces them on Marshal. Or is that too difficult for you?
Having just run into this bug nearly 7 years after it was reported, disappointed is an understatement. However, I found a simple workaround for those who find this thread after me. Using the original definition as an example, just place the variable on the next line after a pipe-dash and without quotes, then toYaml() keeps the var as a string.
Having just run into this bug nearly 7 years after it was reported, disappointed is an understatement. However, I found a simple workaround for those who find this thread after me. Using the original definition as an example, just place the variable on the next line after a pipe-dash and without quotes, then toYaml() keeps the var as a string.
I eventually abandoned trying to use toYaml. My "simple fix" worked in OP's case, but not mine (a string with spaces in it). You may have luck with just the pipe char, e.g.
property: |
value
as long as the value is a simple non-whitespaced string.
helm and the Go/Kubernetes ecosystem sucks. for f's sake just ask Claude to write a better yaml library, if you can't be bothered to do it yourselves. it can use Java Jackson as a reference, since in Java people do things correctly.
helm and the Go/Kubernetes ecosystem sucks. for f's sake just ask Claude to write a better yaml library, if you can't be bothered to do it yourselves. it can use Java Jackson as a reference, since in Java people do things correctly.
helm and the Go/Kubernetes ecosystem sucks. for f's sake just ask Claude to write a better yaml library, if you can't be bothered to do it yourselves. it can use Java Jackson as a reference, since in Java people do things correctly.
Activity
bacongobbler commentedon Jun 29, 2018
@ashanaakh can you provide the output of
helm templatewith this sample?shal commentedon Jun 29, 2018
@bacongobbler Sorry, I can't provide all output, because it is confidential information.
I see, that function changed type of
0x1ddf249430c343f72f8b19868ea4f932500e0000.In values.yml it was in quotes, like
After
toYaml, I seeso configmap looks like this
bacongobbler commentedon Jun 29, 2018
oh I see what you mean. However, both are considered strings though according to the YAML spec though, right? That should still work as a string as single, double and unquoted values are accepted as strings according to the spec.
shal commentedon Jun 29, 2018
@bacongobbler Unfortunately,
0x1ddf249430c343f72f8b19868ea4f932500e0000is hexadecimal literal in YAML.So it is kind of integer.
Please, take a look on YAML specification here.
Thanks!
shal commentedon Jul 1, 2018
@bacongobbler
Here I see, that
toYamlfunction just use dependency for marshaling.https://github.com/kubernetes/helm/blob/aa98e7e3dd2356bce72e8e367e8c87e8085c692b/pkg/strvals/parser.go#L33-L40
I reproduced this bug using helm dependency
github.com/ghodss/yaml.Output will be:
Actually this dependency has one more dependency, which is
github.com/go-yaml/yaml, where this bug occurs.hmcmanus commentedon Jul 13, 2018
It might be a bit late now but I had the same problem but was able to get around it by copying what these guys did here:
https://github.com/kubernetes/charts/blob/master/incubator/elasticsearch-curator/values.yaml
amir-hadi commentedon Apr 8, 2020
@shal You closed this issue, did the problem disappear for you? I see a similar behavior with
toYamlwhich is caused problems for me right now.shal commentedon Apr 8, 2020
Hey @amir-hadi, I temporary resolved this issue by just copying all YAML files as config maps into the helm chart 😄
jocko-wowza commentedon Jun 18, 2020
So I'm trying to us toYaml to dynamically inject custom Environment variables along side required environment variables in my
container:definition in my Helm chart.The problem is that regardless of whether the value is a numer or string, the requirement is that the environment value needs to be quoted. Because toYaml is unquoting it my helm chart is failing.
Anyone know how I can prevent this?
jocko-wowza commentedon Jun 18, 2020
I solved it by not using toYaml ... That's a seemingly direct way to get data from a values file to append to my
env:key, but this solution allows me to make sure all of the values are quoted:rdxmb commentedon Jun 19, 2020
In my opinion this is a bug and not an question/support like it is actually labeled.
rdxmb commentedon Jun 19, 2020
Can this issue be opened again?
50 remaining items
andykcfung commentedon Nov 11, 2022
After trying for an hour to stop toYaml from removing the quotes that I wanted to keep, I found a solution for my specific usage:
To begin, I have this entry in my values.yaml (block 1)
global: properties: mad: person: 'My id: 1234'where "1234" should actually come from another entry in my values.yaml (note that I hard coded the id "1234" above but this will be addressed by the solution later). The following entry is also in my values.yaml:
Now I needed to create a file named "mad.yaml" with the following content using toYaml (note the single code around the value) (target i):
The code that I will use to create the file "mad.yaml" is like this (code A):
mad.yaml: |- {{ tpl (toYaml .Values.global.properties) . | indent 4}}The solution: I modified my original entry (i.e., block 1) to this:
global: properties: mad: person: '{{ printf "%s %d" "My id:" (.Values.person.id | int) }}'and my code (code A) was able to produce what I wanted (i.e., target i).
Hope this helps. It took me much longer to write this up than to find the solution I needed.
joejulian commentedon Nov 11, 2022
If your string has to have the single quotes, you could also use the squote filter
With a value of:
this template:
produces:
changeprop: refactor match template for liftwing
RiccardoManzan commentedon May 26, 2023
I needed to put a yaml defined in a values file as a string with yaml format, and in order to do that i used
toYaml.Unfortunately in that yaml portion i had a string which contained some special characters like
:and}I solved by using the backslash
\before special characters.In this way i was able to keep my escapes.
changeprop: add hack to allow quotes in lift wing's config
almson commentedon Jun 1, 2023
That's pretty garbage. Could also explain why people keep needing quotes even though the yaml spec doesn't require them. Eg. why does CronJob schedule need to be quoted? If Kubernetes won't fix its problems, then Helm should not insist "we're confirming to YAML, don't look at us!" Otherwise that's garbage behavior from both Helm and Kubernetes. What a crappy ecosystem.
The fix is pretty "simple." Stop using these parsers, and write (fork) your own that tracks the quote status of strings on Unmarshal and reproduces them on Marshal. Or is that too difficult for you?
fix: quote node selector values (#796)
baracudda commentedon Mar 13, 2025
Having just run into this bug nearly 7 years after it was reported, disappointed is an understatement. However, I found a simple workaround for those who find this thread after me. Using the original definition as an example, just place the variable on the next line after a pipe-dash and without quotes, then toYaml() keeps the var as a string.
which results in
If you use a pipe-dash and double quote the string, the quotes will be a part of the resulting variable value.
grassehh commentedon Mar 26, 2025
When I use double quote, the resulting variable has additionnal surrounding simple quotes. Exemple
produces
And if I try with simple quote, it ends with 3 quotes:
produces
baracudda commentedon Mar 26, 2025
I eventually abandoned trying to use toYaml. My "simple fix" worked in OP's case, but not mine (a string with spaces in it). You may have luck with just the pipe char, e.g.
as long as the value is a simple non-whitespaced string.
grassehh commentedon Nov 6, 2025
Hello, why is this issue closed ? The problem still remains
dlerps commentedon May 7, 2026
This is a bug which is unresolved and should not be closed!
almson commentedon May 13, 2026
helm and the Go/Kubernetes ecosystem sucks. for f's sake just ask Claude to write a better yaml library, if you can't be bothered to do it yourselves. it can use Java Jackson as a reference, since in Java people do things correctly.
cwegener commentedon May 13, 2026
seriously? https://matrix.yaml.info/valid.html
almson commentedon May 14, 2026
If it's so great, why can't it be used to preserve type information?
P.S. go-yaml has 49 errors in that table, but that's not the issue at the root of this bug