I've been working on a CustomResourceDefinition (CRD) with a controller built using Kubebuilder. Recently, we added an optional field called `newField` to the CRD schema without bumping the API version—it's still `apiVersion: mycrd.example.com/v1beta1`. In a testing environment, we faced issues since the old CRD schema was retained, while the controller was trying to access the new field. This led to data being lost; for example, when the controller set `obj.Status.NewField = "foo"`, it didn't persist because the API server pruned unknown fields on retrieval, leaving `NewField` as an empty string instead of `"foo"`. I'm looking for reliable strategies to minimize such schema mismatches in the future, and I have a couple of ideas. One is to have the controller check if the CRD schema matches its expectations at the start of `Reconcile()`, so it can throw a meaningful error if there's a discrepancy. The second idea involves the controller updating or installing the CRD itself, similar to what Cilium and some other projects do to keep the schema up to date. Any suggestions or best practices would be appreciated!
1 Answer
I had a similar experience with client-go. If you’re getting warnings about unknown fields, you can set a default warning handler to get better error logs. Using something like `SetDefaultWarningHandler()` could enhance your debugging experience. Just remember, these warnings can get ignored if they are just info logs.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically