Rubynetes: Using OpenAPI to validate Kubernetes configs
brightbox.com
brightbox.com
I even went as far as trying to set up my own code generator using the OpenAPI generator toolkit. It is not my favourite code. Everything is deeply nested inheritance hierarchies with humptyjillion methods that do oddly specific stuff. I eventually gave up on it.
Now I am at the point where, to map the generated types to the same types described in the original OpenAPI YAML, I have about 50 goofy lines of string juggling and chasing data structures through 4 or 5 levels of nullable references.
I don't know how we wound up here but I wish we hadn't.
The languages I tend to consume OpenAPI in the most are TypeScript (great), Ruby (pretty good), and on-demand JavaScript (really flexible and comfortable) via openapi-js. I've had some luck with the Kotlin generator on the JVM, too.
Go and "oneof" in protos is always fun: https://github.com/jrockway/ekglue/blob/master/pkg/glue/glue...
But it's better than saying "welp, that program is written in c++, so you have to write your tools that interface with it in c++ as well."
Mostly same observations, but I actually made that plugin work. In retrospect writing complete generator from scratch would take far less time and effort.
I believe original authors have never written a compiler nor considered a code-generator to be a compiler (which it is). Hence the funky architectural style - whatever was the conceptual model behind it fits poorly to the problem at hand and likely was patched multiple times to cover niche corner cases.
https://kubernetes.io/docs/reference/access-authn-authz/exte...
For example, you can't modify some fields of a statefulset or a job after they've been created. The read-only state of certain fields depend on the status of the object.
Validating purely with OpenAPI also won't catch things like a volume mount referencing a secret that doesn't exist.
At the company I work for, I built some tools for deploying apps that wrap around kubectl, Helm, etc. To "lint" a Kubernetes manifest for deploy, the tool pipes the data through "kubectl apply --server-dry-run" first. (You can also use --dry-run for pure client-side validation.) Works pretty good.