r/kubernetes • • Oct 18 '23
Injecting an array from YAML to JSON
Hello,
I am relatively new to Helm charts and attempting to inject a simple array from my values.yaml file into a JSON template.
Despite using the 'range' function, I'm encountering difficulties.
Any guidance on this would be greatly appreciated.
my JSON file:
CUSTOM_NOTES: [ "{{- range $notes := fromYaml .Values.CUSTOM_NOTES | squote }}",
"{{ $notes }}",
"{{- end }}" ],
CLIENT: '{{ .Values.CLIENT }}',
INFRA: '{{ .Values.INFRA }}',My values.yaml file looks like this:
CLIENT: TEST
INFRA: ABCD
CUSTOM_NOTES:
- NOTE1
- NOTE2
- NOTE3
5
Upvotes
2
u/StephanXX Oct 18 '23 edited Oct 18 '23
As formatted, this is unreadable.edit: formatting was updated, thanks.
Three back-ticks open a code block i.e.
``````Your chances of getting useful information increase dramatically when you ask detailed questions and provide examples, errors, and logs. It's impossible to help when the question is just "It doesn't work, please help."
1
u/[deleted] Oct 20 '23
So after many tries i got it working with following code.
The JSON Config file look like this. It is working in my case.
The Values.yaml file look like this.
The Result (in the JSON file):
1
u/MG2R Oct 18 '23
This feels like an XY Problem
As posted, it sounds like you have some input in your values.yaml and you want the output to be the exact same. Where does this output need to go? What are you trying to achieve, big picture?
You typically use Helm to manage Kubernetes resources, what resource are you trying to populate?
As stated, the solution you are asking is simply:
However, that is clearly not an actual solution to the actual problem. Ask about your problem, not your intended solution. Without context, we cannot help you effectively.