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
toYaml removes all quotes and yaml types breaks #4262
Comments
@ashanaakh can you provide the output of |
@bacongobbler Sorry, I can't provide all output, because it is confidential information. I see, that function changed type of In values.yml it was in quotes, like address: "0x1ddf249430c343f72f8b19868ea4f932500e0000" After address: 0x1ddf249430c343f72f8b19868ea4f932500e0000 so configmap looks like this apiVersion: v1
kind: ConfigMap
metadata:
name: {{ template "fullname" . }}
labels:
app: {{ template "fullname" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
data:
file.yml: |-
address: 0x1ddf249430c343f72f8b19868ea4f932500e0000 |
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. |
@bacongobbler Unfortunately, So it is kind of integer. Please, take a look on YAML specification here. Thanks! |
Here I see, that I reproduced this bug using helm dependency package main
import (
"fmt"
"github.com/ghodss/yaml"
)
func main() {
p := map[string]string{"key": "0x1ddf249430c343f72f8b19868ea4f932500e0000"}
d, _ := yaml.Marshal(p)
fmt.Print(string(d))
} Output will be:
Actually this dependency has one more dependency, which is |
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 |
@shal You closed this issue, did the problem disappear for you? I see a similar behavior with |
Hey @amir-hadi, I temporary resolved this issue by just copying all YAML files as config maps into the helm chart 😄 |
So I'm trying to us toYaml to dynamically inject custom Environment variables along side required environment variables in my 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? |
I solved it by not using toYaml ... That's a seemingly direct way to get data from a values file to append to my
|
In my opinion this is a bug and not an question/support like it is actually labeled. |
Can this issue be opened again? |
If someone wants to take a crack at this, here's where Lines 79 to 90 in bb33b92
|
It's likely the call to The information provided in the OP should provide enough information to reproduce the issue as well as the expected output. I would start with writing a unit test for Let me know if you need further clarification. |
|
You can also reproduce the bug in isolation, as described in an earlier comment. |
i use this, works for me
|
Hi everyone, I would like to leave my contribution to this issue, I have investigated a little bit, and I don't think this is actually a bug. The package The scenario described by this issue, we have a Inside If we use the same example to reproduce the bug but instead set the key with a valid value, it works: package main
import (
"fmt"
"gopkg.in/yaml.v2"
)
func main() {
p := map[string]string{"key": "0x1c8"}
d, _ := yaml.Marshal(p)
fmt.Print(string(d))
} Output:
Trying to parse that value with the data, err := strconv.ParseInt("0x1ddf249430c343f72f8b19868ea4f932500e0000", 0, 64)
fmt.Println(data)
fmt.Println(err) Result:
As you can see in the error message the value 9223372036854775807 is the max size of So I don't think it is a bug since YAML package seems to be doing the right thing and the Maybe the post above using the Do you have any feedback on this findings? @bacongobbler |
Just encountered this, it makes toYaml pretty useless for us. With this in values.yaml:
this template
loses the quotes:
|
see #8890. |
Please feel free to do so. Helm is a community project. The documentation can be found here. |
Hm, I guess I do not know if I've understooden the necessary things to do that. Let's try:
Ok. This also works with
Can we see For this does not work:
Sorry, I am kind of confused what the recommended way is to do things like that. |
Is there a solution to the library charts use case? Pretty much every template uses toYaml because of the merge function bellow: {- define "library.util.merge" -}}
{{- $top := first . -}}
{{- $overrides := fromYaml (include (index . 1) $top) | default (dict ) -}}
{{- $tpl := fromYaml (include (index . 2) $top) | default (dict ) -}}
{{- toYaml (merge $overrides $tpl) -}}
{{- end -}} Could this be rewritten in another way? |
Can I also take a look at it? I went through the older comments and all. I can collaborate with you rdxmb. |
please feel free @SupornoChaudhury
|
I spent a while going down a rabbit hole of marshal functions which led me to go reflect package which was being used for determining the type of var once the double quotes are removed. this is the toYAML function:
I am a little new to Go, but I was wondering if we can identify all content within the quotes using regexp and then before returning the output, we replace the content back within quotes.
the text identified as quoted at the start of the function will be padded with quotes again at the end of the toYAML function irrespective of their reflected type.
I believe that would not cause any previous implementation to break. |
I'm not sure if this should go under this issue, although it's definitely in the same genre. YAML types (eg |
I used single quotes around the double quotes to get double quotes in toYaml output. |
Looks like the issue reported by OP happens because the number is too big to fit into uint64, so is treated as a string and hence rendered without quotes. I submitted a possible fix in go-yaml/yaml, but I'm not sure whether this will fix all the related issues. Stripping quotes from strings is the expected behaviour of go-yaml/yaml, and should result in a valid yaml configuration |
I've actually searched for hours to find clear and unambiguous documentation about A feature without documentation is almost like a feature that does not exist, because if nobody can be sure to use it precisely according to spec -- as there is no spec -- then the feature becomes useless, and unusable in scenarios, where you want to be absolutely sure, it does exactly what is expected. This issue here, which has been open for such an enormously long time, pretty much wouldn't exist, if documentation would be proper. I constantly break my teeth out when trying to find documentation on any of the Kubernetes tools, which are popular. Kubernetes has documentation, but considering how complicated that software is, it would need 100 times more documentation, than it has now. Traefik has terrible documentation. You can't know anything when reading their documentation. Basically, software without documentation becomes useless for most users. Too few people have the time or ability to browse through a thousand lines of Go source code, just to get the general gist of what is supposed to happen, regarding a certain functionality. That said, I understand if it's not possible for the core maintainers to address every single issue in a timely manner. On the other hand, I think it's unfair to demand, that users, especially the ones who don't even know anything about how this works, are supposed to do work for this, like in this case, document this feature. I would even document it, if I would get the point of it. However, I cannot get the point of it, as there is no information on it, beside the source code itself, offering that "feature". A tiny step making this whole thing slightly less worse, is at least the following comment. At least, this gives a little insight into what is happening. Still, one would need to read the whole YAML implementation of this specific library for the Go language, to be really sure, what the spec of this feature is or at least, to know what should and should not happen.
I also do not agree with this. First of all, where is the spec? If there is no spec, there is no definitive behaviour. I.e. it's already broken. Nobody can be sure, it does exactly what it is expected to do, as proven by this issue. As I said, this issue wouldn't exist, if proper documentation would be available. To my knowledge, the current state of |
https://yaml.org/spec/ is the canonical specification for YAML. If the yaml parser library does not conform to that specification, it is a bug.
As mentioned before, the entirety of Sounds like this is an upstream issue based on #4262 (comment). Thank you @artemmikhalitsin for contributing a fix upstream. If/when that fix is merged, we can update our dependencies to receive a fix. Doesn't sound like there's any further action to take here on our end. Please follow up with the go-yaml/yaml folks on go-yaml/yaml#820. Thanks. |
This comment helped me achieve my goal. Thaaanks @djmnnit10!. |
This doesn't work for me. The single quotes are just carried over to the final output :( None of the proposed solutions work if you don't control the chart you are using. In my case it's: This allows adding any extra K8s object to the chart, but without quotes it's proving to be very challenging :/ EDIT: I finally found a workaround that works for my use-case (cronjob schedule). Instead of this:
which results in:
I can add whitespace between the quote and the expression:
and it will be rendered as:
Which K8s accepts, despite the extra whitespace (it does not accept a cron schedule without quotes). Hope this helps someone! |
Not being able to keep the type of the original yaml is a very surprising behavior. One expects the string
The reference go-yaml v2 & v3 program (with the |
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): 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. |
If your string has to have the single quotes, you could also use the squote filter With a value of:
this template:
produces:
|
While writing the documentation for the new rules I realized that the match config should be more flexible, since people may need to match different fields depending on the topic that provides the events (with a certain schema). The change should be a no-op. I tried to use toYaml to be more flexible, but I ended up stumbling on helm/helm#4262 and we'd need to have quotes around regexes. As a workaround I implemented more specific range loops for the two use cases that we have (meta.field or field). Bug: T327302 Change-Id: Ice8cd9ff1635a914422ccdceeeed8a7d3998cf62
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 In this way i was able to keep my escapes. |
Due to helm/helm#4262 we cannot use toYaml to render the "match" config, and Change Prop wants string values to be quoted (especially if they contain special chars like in regexes). This change adds a workaround to allow values with quotes, and adds also another special map field "page" to render. Change-Id: I0e1fc7d60a56645f9ad1d59b2887fa23991c9055
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? |
Output of
helm version
:Output of
kubectl version
:Cloud Provider/Platform (AKS, GKE, Minikube etc.): GKE
I got following problem:
File:
values.yml
File:
configmap.yml
After
toYaml
address will be not a string.The text was updated successfully, but these errors were encountered: