akuity / kargo

Application lifecycle orchestration
https://kargo.akuity.io/
Apache License 2.0
1.73k stars 143 forks source link

json-update step #2961

Open jessesuen opened 2 hours ago

jessesuen commented 2 hours ago

Proposed Feature

We just introduced the yaml-update step, which is a great improvement over helm-update-image. Now we should add an equivalent json-update step to deal with json files.

Motivation

This would enable users who use other config management tools like .jsonnet or grafana tanka. Somone using jsonnet could patch an image tag to a .json. Technically they could even patch a .jsonnet file, as long as that file was pure json and did not use any jsonnet syntax.

Suggested Implementation

Step syntax can follow the same syntax as yaml-update but understand how to manipulate a JSON file.

As a future improvement, we could consider leaving room for different patching types (JSON Patch, JSON Merge Patch), but I would not consider this required for MVP. Also, I do not think we should support strategic merge patch, which is a can of worms I would not want to go down.

krancour commented 2 hours ago

Adding a note here that, as we discussed offline, I think it's important to preserve formatting and field order. (We took great care to do so with YAML.) If we don't it creates noise in the diffs.

Fortunately, I think this is accomplished somewhat easily with this lib: https://github.com/tidwall/sjson