argoproj-labs / argocd-image-updater

Automatic container image update for Argo CD
https://argocd-image-updater.readthedocs.io/en/stable/
Apache License 2.0
1.29k stars 265 forks source link

Retain YAML formatting when using the Git write-back method #501

Open sa-spag opened 1 year ago

sa-spag commented 1 year ago

Is your feature request related to a problem? Please describe. When the Image Updater updates a .argocd-source-<appName>.yaml or kustomiztion.yaml file, it does not retain their indentation. For instance, it may generate the following diff:

 apiVersion: kustomize.config.k8s.io/v1beta1
 resources:
-  - some-resource.yaml
+- some-resource.yaml
 images:
...

Describe the solution you'd like Instead, the Image Updater should retain the existing formatting.

It turns out the issue is pretty common for other projects that edit YAML (see issues linked to https://github.com/kubernetes-sigs/kustomize/issues/3946). Since version 0.11.1, kyaml enables retaining the source file indention (see https://github.com/kubernetes-sigs/kustomize/pull/4043). This feature has been integrated in Flux's Image Automation Controller (see https://github.com/fluxcd/image-automation-controller/pull/366), and I believe we can implement a similar feature for the Image Updater.

Describe alternatives you've considered None.

Additional context None.

nabadger commented 1 year ago

Potentially related: https://github.com/argoproj-labs/argocd-image-updater/issues/502

zagr0 commented 5 months ago

Would be really great to have the original file content retained, and the only replaced parts are changed. In our scenario when we write back to git helm values file for new tag, all the values become sorted and reformatted.

chengfang commented 1 month ago

Need to check how to implement this in https://github.com/argoproj-labs/argocd-image-updater/blob/master/pkg/argocd/git.go#L338