Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

We've been using Jsonnet to generate Pods for our complex DAGs at Opsgenie, wrote a similar one using Tekton: https://mustafaakin.dev/posts/2020-04-26-using-jsonnet-to-ge...

But if I was doing it again now, I would just use https://cuelang.org/ or https://dagger.io Jsonnet is really hard to debug.



> Jsonnet is really hard to debug.

yes! As always, it's mostly a tooling issue. Surely, some aspects of the language like lazy evaluation, make it even harder, but fundamentally there is no reason we cannot significantly improve on the overall experience.

And this is not just about debugging when things go wrong. It's also hard to navigate the codebase and understand where are the templates that you care about. Things can happen at multiple levels (that's the feature!) and so it can be quite hard to figure out which files you need to touch if you want to change something in the output. I'm working on a tool to answer that question: "if I wanted to change this field in the generated out put, what are the places in the input files that contribute to produce this value"

    $ ursonnet testdata/child.jsonnet '$.deployment.spec.template.spec.containers[0].resources.limits.cpu'   
    testdata/common.libsonnet:27 
    testdata/base.jsonnet:5 
    testdata/common.libsonnet:23 
    testdata/common.libsonnet:22 
    testdata/config.libsonnet:5
The tool lives in https://github.com/mkmik/ursonnet . I got the basics working but it doesn't work on my larger codebases due to some bug I didn't have yet time hunting down. Having some interest/feedback/help from the community would help making this a reality.


Agreed.

I dislike that it's json to transform json, it becomes a rats nest. I had similar experiences with xslt back in the day.


Its not JSON though, its more of a stripped down purely functional language - functions are quite central.


In that case why not just use Ocaml (or F#) to create objects in a real language and then just serialize them to JSON?


Its mind-bogging amount of work to write correct algebraic types that make sense for most JSON and YAML config files. Pretty much every property is optional, but not really as some combinations are allowed while others not. If you are lucky there might be a JSON Schema with `oneof`s you can automatically map to unions, if not there will just be documentation (e.g. Concourse YAML). Sometimes there will even be two algebraic datatypes encoded in one object, so you would need 2 -> 1 value mapping (or 4 union tags for the possible combinations, whatever suits your fancy)

Since jsonnet is side-effect free, types are somewhat less needed. You can instead execute your code, which will generate values and which can report arbitrary runtime errors (all the way to the language server, even)

(Types would still be awesome for writing funcitons, though)


I can't seem to wrap my head around CUE. Most of my Jsonnet is creating a nice abstraction layer using functions. It seems CUE specifically does not like that approach. Maybe I'm just looking at it the wrong way.


Yeah, code functions aren’t the right mindset for CUE. The essence of it is narrowing constraints and defaults. You have a bunch of constraints that make a template, like Server. Then something extends that, like StageServer. Then it has to get so specific (MyAppStageServer) that all the values are concrete or can be filled with defaults. The constraint narrowing for a field is something like int, 1-8, 1-4, 2. This makes multiple template use (like multiple inheritance) not a nightmare.


Similar experience. I ended up switching to hocon with some extensions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: