Skip to content

yaml2jsonnet utility #765

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

Closed
sbarzowski opened this issue Feb 3, 2020 · 5 comments
Closed

yaml2jsonnet utility #765

sbarzowski opened this issue Feb 3, 2020 · 5 comments

Comments

@sbarzowski
Copy link
Collaborator

It would be nice to have a tool which allows converting existing YAML files to equivalent (trivial) Jsonnet. It doesn't need to support the whole YAML (a reasonable subset would still be useful), but it should preserve comments and ordering. This could be very useful when working with some existing YAML-based setup to gradually introduce Jsonnet.

I imagine that would be a completely separate binary. It may be a separate project or part of the standard Jsonnet distribution (both ways make sense for me).

@sbarzowski
Copy link
Collaborator Author

BTW for those who don't care about comments and order that's pretty trivial - it's enough to convert YAML to JSON and the JSON is also a valid Jsonnet program.

@alxarch
Copy link

alxarch commented Apr 30, 2020

I took a stab at sth like this last year, have a look at ycat

@sbarzowski
Copy link
Collaborator Author

Hey, this is a pretty cool tool! it seems to me more like "jq but using Jsonnet" than a conversion tool, though.

The main point for this issue is to have a way of converting the YAML files while preserving the comments and the order, so that for example a Kubernetes user who wrote YAML by hand can trivially migrate (while preserving the comments and the reasonable order of fields).

@waisbrot
Copy link

waisbrot commented Aug 5, 2020

I was writing some Kubernetes resources for myself in Jsonnet and enjoying the experience -- I get a good understanding of what all the resources are and how they fit together. It's also nice because you can mostly just keep kubectl applying the output of jsonnet -y over and over.

Then I grabbed some Helm charts and was frustrated that (1) I'd like to really learn what's going on in these complex charts also and (2) for my toy setup Helm's notion of immutable releases is really inconvenient.

Anyway, I made https://github.com/waisbrot/yaml2jsonnet and was able to transform the nginx-ingress chart into a Jsonnet doc that worked in Kubernetes. It's pretty crude code right now, but if anyone has a use-case that they want me to try I'd be happy to give it a whirl.

@sbarzowski
Copy link
Collaborator Author

Nice! I haven't tried it yet, but based reading the code, it looks like it solves the problem here.

@josdotso, @rustycl0ck, @mpeters FYI

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

No branches or pull requests

3 participants