by Smaug123 · 2y ago · 0 comments
My feeling is we will probably all look back at the over-use of text based DSLs and configuration languages as a giant mistake. Not just with respect to K8s, but IaC, CI/CD config and the rest of the DevOps YAML/config language mess. In retrospect, it has been a case of simplistic instead of simple. "Declarative" config languages are hello world optimized, and what looked great at the beginning of the S-curve is starting to look pretty damn bad.
Configuration languages like yaml, HCL, etc. are more reasonable alternatives.
yaml is a tree serialization format with some human-targeted ergonomic features like comments and multiline strings built in.
it'll work for simple configuration files just as well as format-less .ini files will. for complex configurations, even xml is better, and that's saying a lot.
in practice for object graphs of any sort of complexity, like cloudformation or k8s configs, you want a programming language which can reduce the kolmogorov complexity of your configuration, because that dominates ops in the limit. or, IOW, configuration is code is configuration is code is ...
I worked at an org where an admin went a little rogue and updated the config without using the macro file. Another admin didn't realize. Well, didn't realize until it was too late.
Which, to your point, isn't to say that YAML is "good", but I think there was at least an advancement through minimalism.
I mean, as soon as you template it and need to do `{{ something | indent 4 }}` or some shit to make the template work you know you're on a bad track.
https://github.com/con2/emrichen
If JSON had comments I might lean toward json.
String concatenation may have been a mistake. The concept of a string may have been a mistake. Every sequence of bytes has some structure, and in order to mash two "strings" together they need to be serialized in the correct way. Even when building error messages it would be nice if you can reliably identify the "chrome" from the "content".
Also look at terminal escape sequences. When we print text to a terminal we should probably be replacing non-printable characters with some sort of encoding so that the reader can understand that 1. these are from the content not the application and 2. Not do stuff like delete the output line to trick the reader.
Every time you put two strings together you should think about how you need to properly encode one into the other. Output unaware text templating almost always fails this because it relies on the user to do this for every single interpolation, and that is doomed to fail.
I wrote an even longer rant about this on my blog a while ago: https://kevincox.ca/2022/02/08/escape-everything/
Also, there's the old dirt hack
{"item": "this is a comment",
"item": "//so is this but more obvious",
"item": "because in 99.99% of implementations, last value wins:"
"item": 42}Plus, well, there's a disturbingly high number of people who think that semantic whitespace is a positive.
(Of course the reality is that braces are how you write scoping information and indentation is how you read it, and CQRS is actually a good thing.)
We decided to go with Starlark as the base language for our DSL, and we've had a consistently great experience. Users report that it's very approachable, and the starlark-go library is very pleaeant to deal with.
The main issue is that it make it more difficult to mix hardcoded and inserted values.
labels:
- mylabel
- {{ extraLabels | indent 4 }} # toJson doesn't work here.
Also the small technical concern that YAML isn't actually a superset of JSON. (But you are far less likely to hit these cases than other escaping bugs). labels: {{ append .extraLabels "myLabel" "myOtherLabel" | toJson }}
your commentary talks about json but your code snippet is in yaml, so it's possible one or both of us are solving the wrong problemNo comments and having to escape.... well, practically everything you'd commonly be entering makes JSON suck at this sort of task.
This more shows that one shouldn’t be using string templating to create data structures in the first place.
Failing that if you actually need/want a procedural/non-pure language then I think Kotlin or Ruby take the cake. Both have extremely strong support for DSLs which IMO is key to reaching a modicum of usability.
In that case I preferred to describe infrastructure rather than program it.