yannh / kubeconform

A FAST Kubernetes manifests validator, with support for Custom Resources!
Apache License 2.0
2.15k stars 121 forks source link

Support providing preloaded schemas #215

Open tmcg-gusto opened 1 year ago

tmcg-gusto commented 1 year ago

Our goal is to be able to provide schemas that we've compiled to the validator, in order to prevent needing to read/write to a cache on the filesystem.

Context: We're distributing a command line tool that will generate k8s manifests for various projects, and would like it to work in an offline environment. Rather than distribute the schemas separately from the tool, we plan to embed them in the binary with go:embed. We could dump them to disk and then provide that path to the validator constructor, but we'd rather skip the middleman and just provide the schemas directly.

The approach we were thinking of would be to support passing in a pre-populated inMemory Cache via Opts, and setting that on the validator in New. If that doesn't sound too bad, I can put together a pull request for it.

edit: another alternative approach would be to allow providing a Registry implementation that would take precedence over the others so that we could provide our schemas if they're present in the project. That feels like it might be slightly nicer, but is a bit more complex.

tmcg-gusto commented 1 year ago

Ended up going with the alternative approach of providing a custom Registry as it ended up being a simpler approach on our end.