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

[Suggestion] fix ordering in YAML output #17

Closed
tabern opened this issue Feb 27, 2020 · 3 comments · Fixed by #67
Closed

[Suggestion] fix ordering in YAML output #17

tabern opened this issue Feb 27, 2020 · 3 comments · Fixed by #67
Assignees
Labels
feature-request New/Enhanced functionality wanted

Comments

@tabern
Copy link
Contributor

tabern commented Feb 27, 2020

Is your feature request related to a problem? Please describe.
Synthesized YAML shows up out of order from standard K8s format. It technically works, but for a user familiar with K8s YAML formatting can be confusing to read.

example:

spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: myappnginx37F28063
kind: Service
apiVersion: v1
metadata:
  name: myapp.nginx.service.5f289726

Describe the solution you'd like
Follow K8s YAML formatting conventions

  1. apiVersion
  2. kind
  3. metadata
  4. spec
  5. etc...

example:

apiVersion: v1
kind: Service
metadata:
  name: myapp.nginx.service.5f289726
spec:
  type: LoadBalancer
  ports:
    - port: 80
      targetPort: 8080
  selector:
    app: myappnginx37F28063

There may be a styling guide somewhere but I can't find it - looking at K8s documentation

@tabern tabern added the feature-request New/Enhanced functionality wanted label Feb 27, 2020
@eladb
Copy link
Contributor

eladb commented Mar 9, 2020

@campionfellin campionfellin self-assigned this Mar 10, 2020
@campionfellin
Copy link
Contributor

I'll take this!

I think we can start with kubernetes/examples as our style guide for now and go from there.

For the top-level, I agree with the proposed solution of:

  1. apiVersion
  2. kind
  3. metadata
  4. spec (or other)

Looking at their examples, most generally follow this (though some, like cassandra-statefulset.yaml have 2 different orders in the same document.

I think we can put 1-3 in that order, and after that, order from shortest to longest, and in deeper levels of definitions, follow the shortest to longest as well. As such, when you scroll down in a file, you are reading inward on levels of deepness, and are not popping back out to a higher level without seeing its context.

Will poke around in the code mentioned above to find a solution.

@eladb
Copy link
Contributor

eladb commented Mar 10, 2020

I would take a bit of a more simple approach: apiVersion, kind, metadata, spec and then alpha-sort, and also do that recursively. It is very important that the order will be deterministic since people will likely use "diff" to identify changes to their definitions, so we can't afford any non-determinism.

@eladb eladb closed this as completed in #67 Mar 12, 2020
eladb pushed a commit that referenced this issue Mar 12, 2020
Fixes #17 

Using [`json-stable-stringify`](https://github.com/substack/json-stable-stringify) to sort output alphabetically and recursively. 

Signed-off-by: campionfellin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request New/Enhanced functionality wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants