yaml-update one block in a list #5985
|
I need to update a yaml file that contains a list of multiple blocks e.g. tenants:
- name: tenant1
key: value
- name: tenant2
key: valueIn my promotion I want to update the My thought was something like this - uses: yaml-parse
as: values
config:
path: './src/values.yaml'
outputs:
- name: index
fromExpression: tenants.[name=tenant2]
- uses: yaml-update
config:
path: ./src/values.yaml
updates:
- key: tenants.${{ task.outputs['values'].index }}
value: "newvalue"Is something like this possible? perhaps there is a more Kargo-like solution? |
Replies: 4 comments 3 replies
|
Kargo's docs claim compatibility with this: https://github.com/tidwall/sjson?tab=readme-ov-file#path-syntax, although, in fact, there are very minor differences -- none however that should impact you here. I believe this is what you are looking for: - uses: yaml-update
config:
path: ./src/values.yaml
updates:
- key: tenants.1.key
value: newValues |
Sorry! I'd misunderstood that as one human telling another which part of the example doc is to be updated, for clarity. It had not clicked that you weren't always looking to modify one specific element of the sequence. I get it now. I'm afraid I don't have a good answer for you here. I can actually point you to the fact of there being an entirely separate promotion step for updating Helm subchart dependencies in a There may be a clever expression-based way of approaching this that I've not yet noticed.
Did that example:
OR
|
|
As far as I can tell this is not possible. However I've found a simpler route anyway using yaml anchors :) Now I just update known locations in my yaml file and everything else can alias that e.g. instead of tenants:
- name: tenant1
key: value
- name: tenant2
key: valueI have values:
dev: &1.2.0
prod: &1.1.2
tenants:
- name: tenant1
key: *dev
- name: tenant2
key:*prod |
|
Now I have a problem of writing an anchor into the yaml 😠 |
Just had to tweak my schema a little so Kargo is updating a field in the anchored yaml
Which essentially results in this
Then Kargo uses the
yaml-updatestep to setvalues.dev.valueandvalues.prod.valuein different stages :)