The replace mechanism only supports selecting the YAML path by object key and array index (e.g. foo.bar.[0].baz). This is quite fragile if you have to replace within arrays.
Example:
# kustomizazion.yaml
images:
- name: frontend
newTag: v2
- name: backend
newTag: v2
or
# values.yaml
myapp:
env:
- name: FOO
value: foo
- name: BAR
value: bar
Replacing the image tags or the env values requires the array to be in a stable order. Also the replacement path is hard to read if you don't know the YAML file: myapp.env.[1].value -> are we replacing FOO or BAR here?
Possible solution:
JsonPath has filter expressions. Selecting the value of FOO would look like this: myapp.env[?(@.name=='FOO')].value
There is a python library jsonpath-ng which can output the matching paths:
>>> jsonpath_expr = parse('foo[*].baz')
# Matches remember where they came from
>>> [str(match.full_path) for match in jsonpath_expr.find({'foo': [{'baz': 1}, {'baz': 2}]})]
['foo.[0].baz', 'foo.[1].baz']
Those returned full_path strings are exactly the simplified YAML path supported by the GitOpsCLI. We could just plug this library in between and translate complicated JsonPath expressions.
The library even has a short form to specify the filters: myapp.env[?name=='FOO'].value
This solution would be backwards compatible. However, we could also choose to just enable this JsonPath translation feature via CLI flag. Any opinions on that?
The replace mechanism only supports selecting the YAML path by object key and array index (e.g.
foo.bar.[0].baz). This is quite fragile if you have to replace within arrays.Example:
or
Replacing the image tags or the env values requires the array to be in a stable order. Also the replacement path is hard to read if you don't know the YAML file:
myapp.env.[1].value-> are we replacingFOOorBARhere?Possible solution:
JsonPath has filter expressions. Selecting the value of
FOOwould look like this:myapp.env[?(@.name=='FOO')].valueThere is a python library jsonpath-ng which can output the matching paths:
Those returned
full_pathstrings are exactly the simplified YAML path supported by the GitOpsCLI. We could just plug this library in between and translate complicated JsonPath expressions.The library even has a short form to specify the filters:
myapp.env[?name=='FOO'].valueThis solution would be backwards compatible. However, we could also choose to just enable this JsonPath translation feature via CLI flag. Any opinions on that?