Add item to an nested array which uses an environment variable #1685
unmarshall
started this conversation in
General
Replies: 2 comments
-
When i try and add a map to an array then it works but obviously that is not a desired result that i look for. export server_name=main-local && yq '.spec.template.spec.containers[0].args += {"server-name": strenv(server_name)}' test.yaml This will give: spec:
template:
spec:
containers:
- args:
- start-app
- --tls-enabled=true
- server-name: main-local
image: app-image:dev
imagePullPolicy: IfNotPresent
- command:
- ctl
- bingo
- --tls-enabled=true
- --schedule=42 16 * * *
image: another-app-image:dev
imagePullPolicy: IfNotPresent So it seems that env substitution does not work for array when you want to add an element to an array which is not a map. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You just need to use string concatenation to get it to work:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Consider the following yaml
I wanted to add an element to an array '.spec.template.spec.containers[0].args' the value to be added is constructed using an environment variable.
I tried
But this appends
--server-name=env(server_name)
and does not evaluate/expand the environment variable.I also played around with using
eval
orwith
operator but could not make this work.However if i had to add an object to '.spec.template.spec.volumes' then the following works:
So it seems that using env operator has different behavior when adding an object to an existing array and when adding a string to an existing array. Confused a bit on why is this or am i missing something?
Beta Was this translation helpful? Give feedback.
All reactions