Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Automation Controller is reformatting inline blocks in a single line #528

Closed
ruiengana opened this issue May 31, 2023 · 14 comments
Closed

Comments

@ruiengana
Copy link

ruiengana commented May 31, 2023

When a manifest has block configuration like below and is updated by image automation controller, blocks are overwritten as a single line of code making it unreadable. Code blocks should not be reformatted.

For example, this is pipe block

  config: |
    _format_version: "2.1"
    _transform: true
    services:
    - name: example
      url: https://example.org
      routes:
      - name: example
        paths:
        - /example

After image automation controller commit becomes

  config: "_format_version: \"2.1\"\n    _transform: true\n    services:\n    - name: example\n      url: https://example.org\n      routes:\n      - name: example\n        paths:\n        - /example\n"

This behaviour is unexpected, we would like blocks to stay exactly as they were before.

@stefanprodan
Copy link
Member

This behaviour is unexpected, we would like blocks to stay exactly as they were before.

We use kustomize kyaml to mutate the YAMLs and this is how it behaves. I suggest you move the images block that's being patched, to a Flux Kustomization e.g.

apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
  name: podinfo
  namespace: default
spec:
  images:
    - name: ghcr.io/stefanprodan/podinfo
      newName: ghcr.io/stefanprodan/podinfo # {"$imagepolicy": "flux-system:podinfo:name"}
      newTag: 5.0.0 # {"$imagepolicy": "flux-system:podinfo:tag"}

@ruiengana
Copy link
Author

We use kustomize kyaml to mutate the YAMLs and this is how it behaves. I suggest you move the images block that's being patched, to a Flux Kustomization e.g.

We use the image automation controller mainly with HelmReleases managed by Helm Controller to override the images and tags values from helm.

I don't think I understood how I could apply your solution to it.

@stefanprodan
Copy link
Member

You can create a kustomizeconfig to teach Kustomize how to use images in custom resources, docs here https://github.com/kubernetes-sigs/kustomize/blob/master/examples/transformerconfigs/images/README.md

@ruiengana
Copy link
Author

We use kustomize kyaml to mutate the YAMLs and this is how it behaves. I suggest you move the images block that's being patched, to a Flux Kustomization e.g.

We also have annotations with code blocks in the same YAML and interestingly the annotations are being left intact. Can you help me understand why code blocks in annotations are treated differently?

@stefanprodan
Copy link
Member

Another solution is to move the config to a ConfigMap and use valuesFrom in the HelmRelease, so when Flux patches the images, it will not mess up the config as it's not there.

@ruiengana
Copy link
Author

ruiengana commented May 31, 2023

Another solution is to move the config to a ConfigMap and use valuesFrom in the HelmRelease, so when Flux patches the images, it will not mess up the config as it's not there.

Yes, I think that will work.

Still unsure why inline blocks in annotations are not being messed up while other inline blocks elsewhere are. Isn't that strange?

@stefanprodan
Copy link
Member

Still unsure why inline blocks in annotations are not being messed up while other inline blocks elsewhere are. Isn't that strange?

It is, I can't find the issue now, but it's here somewhere https://github.com/kubernetes-sigs/kustomize/issues?q=is%3Aissue+is%3Aopen+ as I said, we don't edit the YAMLs with our code, we use Kustomize kyaml in Flux.

@ruiengana
Copy link
Author

ruiengana commented May 31, 2023

Still unsure why inline blocks in annotations are not being messed up while other inline blocks elsewhere are. Isn't that strange?

It is, I can't find the issue now, but it's here somewhere https://github.com/kubernetes-sigs/kustomize/issues?q=is%3Aissue+is%3Aopen+ as I said, we don't edit the YAMLs with our code, we use Kustomize kyaml in Flux.

I can provide a HelmRelease with a simple deployment to demonstrate so this issue can be linked to kustomize repo.
Let me know if that helps?

@ruiengana
Copy link
Author

@stefanprodan this is becoming a real problem for us. We have large inline block pieces being reformatted in a single line and messing everything :( we currently reverting the commit side effect manually which isn't sustainable. Do you know if this is already open in kustomize ?

@ruiengana ruiengana changed the title Image Automation Controller is reformatting pipe blocks in a single line Image Automation Controller is reformatting inline blocks in a single line Jun 1, 2023
@ruiengana
Copy link
Author

ruiengana commented Jun 15, 2023

@stefanprodan any update on this? Thank you in advance

@AchazRyus
Copy link

This issue is still relevant for me also. Would love to hear any update !

@stefanprodan
Copy link
Member

This should've been fixed in #605

You can try it out using ghcr.io/fluxcd/image-automation-controller:preview-13413b26

@AchazRyus
Copy link

Great ! Thanks you

@stefanprodan
Copy link
Member

This should be fixed in Flux 2.2.0, please open a new issue if that's not the case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants