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

Formatting support for generated yaml #103

Closed
jcristol opened this issue Feb 10, 2021 · 1 comment
Closed

Formatting support for generated yaml #103

jcristol opened this issue Feb 10, 2021 · 1 comment

Comments

@jcristol
Copy link

jcristol commented Feb 10, 2021

When using the 1.0 installation of flux I have noticed that when the 1.0 flux controller updates the image version of a formatted manifest, the manifest in our case was formatted with prettier, flux doesn't change just the image tag it will enforce its own formatting probably based how the go-yaml package unmarshalls yaml.

What I would like is the ability to have a gitops flux repo where I can enforce formatting using a tool like prettier. I see two options where I can get this.

  1. Add hooks in flux that allow us to run arbitrary commands on the modified yaml when an image patch is committed. This is a bit of a complex problem because the flux docker image wouldn't necessarily have the ability to run prettier so people that want to leverage this would have to run a baked version of the flux were they also install their formatter.

  2. Get a better understanding on how flux is formatting the yaml files today and a means of replicating that with a formatter that I can invoke via bash against a yaml file. This way I could just make my repo formatter consistent with the formatting that flux will use when it generates yaml.

Concrete Example

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    fluxcd.io/automated: "true"
    fluxcd.io/tag.bar: glob:master-*
  labels:
    k8s-app: foo
  name: foo
  namespace: bar
spec:
  replicas: 2
  selector:
    matchLabels:
      k8s-app: foo
  template:
    metadata:
      labels:
        k8s-app: foo
      name: foo
    spec:
      containers:
        - env:
            - name: PORT
              value: "3000"
            - name: NODE_APP_INSTANCE
              value: "qa"
          image: foo:master-fdb57d8
          name: foo

the above was styled by prettier by running prettier ./file-name -w.
below was what flux will generate after bumping the image version.

Notice how the section starting with - env: is unindented.

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    fluxcd.io/automated: "true"
    fluxcd.io/tag.bar: glob:master-*
  labels:
    k8s-app: foo
  name: foo
  namespace: bar
spec:
  replicas: 2
  selector:
    matchLabels:
      k8s-app: foo
  template:
    metadata:
      labels:
        k8s-app: foo
      name: foo
    spec:
      containers:
      - env:
        - name: PORT
          value: "3000"
        - name: NODE_APP_INSTANCE
          value: "qa"
        image: foo:master-elka323d
        name: foo

More Color

I cannot configure prettier to match the current formatting that flux uses according to these issues prettier/prettier#4723 prettier/prettier#9355

@stefanprodan
Copy link
Member

We use kustomize/kyaml to patch the YAML files, please comment on this issue kubernetes-sigs/kustomize#3559

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

2 participants