News for hackers. Stuff that matters.
Re:Ask HN: If Kubernetes is the solution, why are there so m... by heretogetout on Wednesday June 01, 2022 @10:52AM (#31582634)
I hear you about feeling dumb. I think some early decisions in the k8s ecosystem led to a lot of wasted time and effort, and this frustration.

YAML: significant whitespace is always unwelcome but YAML also introduces unexpected problems, like how it deals with booleans. For example, say you have this array:

    foo:
    - x
    - y
    - z
You might think this is an array of strings, but you'd be wrong.

It's also difficult to read through a YAML config and understand the parent of each key, especially in code reviews or just on GH.

I believe k8s life would have been easier with JSON configs, where it's impossible to confuse e.g. booleans for strings and where it's easier to understand the object's hierarchy.

Helm's use of gotpl: this choice exacerbates the problems with YAML. Now you're treating a structured language with a text template library. You have to spend energy thinking about indentation levels and how the values will be interpreted by both the templater and k8s.

I think helm would be less frustrating if they chose some templating library that made objects first class citizens. Where you can inject values at specific locations with one-liners or simple blocks of code (e.g. `ingress.spec.rules[0].append(yadda yadda)`)

I'm sure there was debate about these choices early on and I don't have any unique ideas here, so I don't want to be too critical. These are just a couple of pain points I've personally experienced.

Re:Ask HN: If Kubernetes is the solution, why are there so m... by rustyminnow on Wednesday June 01, 2022 @12:49PM (#31584602)
Technically YAML is a superset of JSON - all valid JSON is valid YAML. So you could write all your configs in JSON and they'd work just fine.
Re:Ask HN: If Kubernetes is the solution, why are there so m... by krapp on Wednesday June 01, 2022 @01:07PM (#31584879)
This discussion from a couple of weeks ago suggests it isn't that simple: not all valid JSON is always valid YAML if your definition of superset requires that JSON would be parsed the same with a YAML parser as with a JSON parser.

If you're going to use JSON for config, it's better to use an actual JSON parser.

https://john-millikin.com/json-is-not-a-yaml-subset https://news.ycombinator.com/item?id=31406473

Re:Ask HN: If Kubernetes is the solution, why are there so m... by rustyminnow on Wednesday June 01, 2022 @01:22PM (#31585096)
Thanks! That's really interesting.

You could mitigate some of the issues and get JSONs "strictness as a feature" by passing the document through e.g. `jq . $file` as a CI step, but I don't think that'd resolve the 1e2 issue. TBH I didn't know you could write numbers in JSON like that, so I imagine it'd be an issue that doesn't come up often. But it's disappointing that it wouldn't just work.

Re:Ask HN: If Kubernetes is the solution, why are there so m... by bmn__ on Wednesday June 01, 2022 @02:18PM (#31585908)
> Technically YAML is a superset of JSON

That's false. http://p3rl.org/JSON::XS#JSON-and-YAML

Re:Ask HN: If Kubernetes is the solution, why are there so m... by rustyminnow on Wednesday June 01, 2022 @06:31PM (#31588982)
I'd like to amend my statement:

Technically YAML is (supposed to be) a superset of JSON - (almost) all valid JSON is valid YAML. So you could write all your configs in JSON and they'd (probably) work just fine (assuming you keep things relatively simple).

Re:Ask HN: If Kubernetes is the solution, why are there so m... by jtchang on Wednesday June 01, 2022 @11:22AM (#31583180)
Is that yaml not an array of strings?

["x","y","z"]

Re:Ask HN: If Kubernetes is the solution, why are there so m... by Filligree on Wednesday June 01, 2022 @11:26AM (#31583251)
I don't happen to have a YAML parser at hand, but I believe it's...

["x", True, "z"]

Re:Ask HN: If Kubernetes is the solution, why are there so m... by heretogetout on Wednesday June 01, 2022 @11:26AM (#31583253)
It's not, y is treated as boolean true.
Re:Ask HN: If Kubernetes is the solution, why are there so m... by karmajunkie on Wednesday June 01, 2022 @11:45AM (#31583577)
Is that a k8s thing? Because when I load it in this page[1] it comes out as a string...

[1] https://yaml-online-parser.appspot.com/?yaml=foo%3A+%0A-+x%0...

Re:Ask HN: If Kubernetes is the solution, why are there so m... by Thiez on Wednesday June 01, 2022 @11:54AM (#31583747)
In YAML 1.2 they fixed it (and also the Norway-problem of "no" meaning false) but many places are still using an older version.
Re:Ask HN: If Kubernetes is the solution, why are there so m... by aliswe on Wednesday June 01, 2022 @11:16AM (#31583078)
for what its worth, and if im not mostaken, there is some support for JSON, ie. kubectl get deployment xyz -o json
Re:Ask HN: If Kubernetes is the solution, why are there so m... by neurostimulant on Wednesday June 01, 2022 @11:47AM (#31583606)
JSON has a different set of problems, e.g. not having multi-line string support.