News for hackers. Stuff that matters.
Re:Why the fuck are we templating YAML? (2019) by throwaway143829 on Tuesday January 23, 2024 @06:18AM (#39101951)
This article made me think it'd be nice to generate k8s JSON using TypeScript. Just a node script that runs console.log(JSON.stringify(config)), and you pipe that to a yaml file in your deploy script. The syntax seems more sane and has more broad appeal than jsonnet, and I'd wager that the dev tooling would be better given good enough typings.

By the way the answer to the question "why are we templating yaml?" is: people are just more familiar with it and don't want to have to translate examples to jsonnet that they copy and paste from the web. Do not underestimate this downside :) Same downside would probably apply to TypeScript-generated configs I bet.

Re:Why the fuck are we templating YAML? (2019) by sigwinch28 on Tuesday January 23, 2024 @07:12AM (#39102360)
I would recommend implementing a similar API to Grafana Tanka: https://tanka.dev

When you "synthesise", the returned value should be an array or an object.

1. If it's an object, check if it has an `apiVersion` and `kind` key. If it does, yield that as a kubernetes object and do not recurse. 2. If it's an array or any other object, repeat this algorithm for all array elements and object values.

This gives a lot of flexibility to users and other engineers because they can use any data structures they want inside their own libraries. TypeScript's type system improves the ergonomics, too.

Re:Why the fuck are we templating YAML? (2019) by grncdr on Tuesday January 23, 2024 @06:35AM (#39102080)
Others have mentioned CDK, but I want to say that this is almost the exact approach I took on a project recently and it worked out fine. Node script that validates a few arguments and generates k8s manifests as JSON to be fed into `kubectl apply`.

IME, here's no need to involve anything more complicated if your deployment can be described solely as k8s manifests.

Re:Why the fuck are we templating YAML? (2019) by geethree on Tuesday January 23, 2024 @06:26AM (#39102000)
Re:Why the fuck are we templating YAML? (2019) by YawningAngel on Tuesday January 23, 2024 @06:30AM (#39102033)
You can convert YAML to JSON programmatically, and JSON is valid jsonnet, so you can pretty much copy paste examples from the web into your jsonnet if you find yourself wanting to do that
Re:Why the fuck are we templating YAML? (2019) by Leo_Verto on Tuesday January 23, 2024 @06:24AM (#39101993)
That's sort of what https://cdks.io does, except the final output is YAML for better readability.
Re:Why the fuck are we templating YAML? (2019) by happymellon on Tuesday January 23, 2024 @06:52AM (#39102204)
Re:Why the fuck are we templating YAML? (2019) by sgarland on Tuesday January 23, 2024 @07:41AM (#39102594)
> copy and paste from the web

Hot take, this is a terrible idea, and is why so much cloud infra is monstrously expensive (and bad).

People need to stop making infra easy. It’s not supposed to be easy, because when you make a bad decision, you don’t get to revert a commit and carry on with life. You don’t understand IOPS and now your gp2 disk is causing CPU starvation from IOWAIT? Guess you’re gonna learn some things about operating within constraints while waiting for a faster disk to arrive at the DC! Buckle up, it’ll be good for you.

I’m fully aware that I sound like a grouchy gatekeeper here, and I’m fine with it. People making stupid infra decisions en masse cause me no end of headaches in my day job, and I’m tired of it.