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 (Flux 2.2.0) #616

Open
ruiengana opened this issue Dec 14, 2023 · 12 comments

Comments

@ruiengana
Copy link

related to #528

@stefanprodan we just upgraded to Flux 2.2.0 and problem is still occurring.

All our HelmRelease files getting picked up by the Image Automation Controller are getting inline blocks reformatted to single line blocks.

When a HelmRelease manifest has a 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

Can you post here flux check for the cluster where you are running image-automation-controller.

@ruiengana
Copy link
Author

Can you post here flux check for the cluster where you are running image-automation-controller.

$ flux check
► checking prerequisites
✔ Kubernetes 1.27.7-eks-4f4795d >=1.26.0-0
► checking version in cluster
✔ distribution: flux-v2.2.0
✔ bootstrapped: true
► checking controllers
✔ helm-controller: deployment ready
► ghcr.io/fluxcd/helm-controller:v0.37.0
✔ image-automation-controller: deployment ready
► ghcr.io/fluxcd/image-automation-controller:v0.37.0
✔ image-reflector-controller: deployment ready
► ghcr.io/fluxcd/image-reflector-controller:v0.31.1
✔ kustomize-controller: deployment ready
► ghcr.io/fluxcd/kustomize-controller:v1.2.0
✔ notification-controller: deployment ready
► ghcr.io/fluxcd/notification-controller:v1.2.2
✔ source-controller: deployment ready
► ghcr.io/fluxcd/source-controller:v1.2.2
► checking crds
✔ alerts.notification.toolkit.fluxcd.io/v1beta3
✔ buckets.source.toolkit.fluxcd.io/v1beta2
✔ gitrepositories.source.toolkit.fluxcd.io/v1
✔ helmcharts.source.toolkit.fluxcd.io/v1beta2
✔ helmreleases.helm.toolkit.fluxcd.io/v2beta2
✔ helmrepositories.source.toolkit.fluxcd.io/v1beta2
✔ imagepolicies.image.toolkit.fluxcd.io/v1beta2
✔ imagerepositories.image.toolkit.fluxcd.io/v1beta2
✔ imageupdateautomations.image.toolkit.fluxcd.io/v1beta1
✔ kustomizations.kustomize.toolkit.fluxcd.io/v1
✔ ocirepositories.source.toolkit.fluxcd.io/v1beta2
✔ providers.notification.toolkit.fluxcd.io/v1beta3
✔ receivers.notification.toolkit.fluxcd.io/v1
✔ all checks passed

@stefanprodan
Copy link
Member

Ok can you paste there the HelmRelease as it is in your Git repo, I want to see where the markers are.

@AchazRyus
Copy link

AchazRyus commented Dec 14, 2023

I found a solution working for me ! In fact it's when there is a space after a : when non needed in your deployment file.
For example if you have :
annotations:
something: ""
If you have a space after annotations: , or any other key, flux will commit and add \n everywhere

@ruiengana
Copy link
Author

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

Please find below a extract of the HelmRelease.
Essentially we have an umbrella chart with couple subcharts, let's say subchart A and subchart B. Subchart A has a inline block config and no image automation markers. Subchart B doesn't have inline block configs but has image automation markers.

When image automation controller picks a change on subchart B, it also changes subchart A inline block config to single line.

apiVersion: helm.toolkit.fluxcd.io/v2beta2
kind: HelmRelease
spec:
  releaseName: <release>
  values:
    subchart-a:
      config: |
        _format_version: "2.1"
        _transform: true
        services:
        - name: example
          url: https://example.org
          routes:
          - name: example
            paths:
            - /example
    subchart-b:
      enabled: true
      image:
        repository: <repo> # {"$imagepolicy": "flux-system:repo:name"}
        tag: <tag> # {"$imagepolicy": "flux-system:repo:tag"}

PS: We also have inline configs in annotations, but those are always kept OK.

@stefanprodan
Copy link
Member

@ruiengana do you mixed indentation in your YAML, tabs and spaces? If so, then that will trigger a full reformat.

@ruiengana
Copy link
Author

@ruiengana do you mixed indentation in your YAML, tabs and spaces? If so, then that will trigger a full reformat.

We may very well have. Isn't that supported? Which one should we adopt to avoid the full reformat, tab or spaces?

@stefanprodan
Copy link
Member

I've used tabs to write a test for these issues 0502196

@cimillas
Copy link

In our case, the use of space is strictly necessary. Is there any intention to add support for yaml files with tabs and spaces mixed?

@stefanprodan
Copy link
Member

Is there any intention to add support for yaml files with tabs and spaces mixed?

No, this restriction comes from Kubernetes Go YAML package, Flux does not uses it's own YAML formatter.

@stefanprodan
Copy link
Member

@cimillas I suggest moving the subchart-a values to a ConfigMap, and use valuesFrom, this way you can format the HelmRelease properly.

@wgorczyca
Copy link

Reformat which causes merge multiple line to one line is still being triggered if there is space/whitespace at the end of any line, so make sure you don't have it to avoid this issue

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

5 participants