When you define a value in your values.yaml
file, Helm uses the encoding/json
package to unmarshal the YAML data into a map[string]interface{}
structure. This means that the value is stored as an interface{}
type, which can hold any type of value (string, int, float, etc.).
When you use the {{.Values.prometheus.username}}
syntax in your template, Helm tries to convert the interface{}
value to a string using the fmt.Sprintf
function. If the value can be converted to an integer (like in your case, where the value is '1491301'
), Helm will automatically convert it to an int
type.
This is why you’re seeing the single quotes disappear and the value being treated as an integer. This behavior is due to the way Go’s encoding/json
package handles YAML unmarshaling.
'{{ toString .Values.prometheus.username }}'
To force the value to be treated as a string, you need to use the toString
function. This function explicitly converts the interface{}
value to a string, ensuring that it’s treated as a string in the template.
Using single quotes or double quotes around the value in the values.yaml
file doesn’t make a difference because Helm will still unmarshal the value as an interface{}
type.
So, to summarize:
- Helm uses
map[string]interface{}
to store YAML values, which can lead to type conversions. - When using
{{.Values.prometheus.username}}
, Helm tries to convert theinterface{}
value to a string, which can result in unexpected type conversions. - Using the
toString
function forces the value to be treated as a string, ensuring the correct type conversion.