Add nullable to optional fields with x-kubernetes-int-or-string#1885
Conversation
… in CRD schemas Signed-off-by: doxxx93 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1885 +/- ##
=======================================
+ Coverage 76.0% 76.1% +0.1%
=======================================
Files 85 85
Lines 8285 8313 +28
=======================================
+ Hits 6296 6321 +25
- Misses 1989 1992 +3
🚀 New features to boost your workflow:
|
|
@clux Just curious - when do you think the next release might be? Would it coincide with the next k8s-openapi release (the "Add v1.35.0 and drop v1.30" commit from https://github.com/Arnavion/k8s-openapi)? |
|
Yeah, was planning on releasing with that. (Usually there are a lot of confused people who tries to use the new k8s-openapi with the current kube who gets mismatches if it's too out of sync). If it's not by this week/next week I'll probably cherry pick some stuff into a 2-x branch and do another release. |
|
Will merge in this at least. Thank you! |
|
as a side-note. I guess if I'm considering cherry picking, we could probably merge all the outstanding breaking ones now. |
|
yeah I think so too |
|
Upstream 1.35 OpenAPI spec hasn't had any bugfixes after 1.35.0 that would cause further backward-incompatible changes in k8s-openapi, so I'll probably cut a new k8s-openapi release this weekend. |
Newer versions of k8s-openapi surface a schemars bug for optional quantities. See: kube-rs/kube#1869 See also kube-rs/kube#1885 (comment)
* chore(stackable-operator): Revert and pin k8s-openapi to 0.26.0 Newer versions of k8s-openapi surface a schemars bug for optional quantities. See: kube-rs/kube#1869 See also kube-rs/kube#1885 (comment) * chore: Update changelog
…-rs#1885) feat(schema): add OptionalIntOrString transform for nullable handling in CRD schemas Signed-off-by: doxxx93 <[email protected]>
…-rs#1885) feat(schema): add OptionalIntOrString transform for nullable handling in CRD schemas Signed-off-by: doxxx93 <[email protected]>
Motivation
Fixes #1869
When using
Option<IntOrString>orOption<Quantity>(k8s-openapi 0.26.x) in CRD specs, the generated schema is missingnullable: true, causing server-side apply to fail with:Invalid value: "null": spec.foo in body must be of type integer,string: "null"
The root cause is that schemars'
AddNullabletransform only addsnullable: trueto schemas with atypeproperty. However,IntOrStringandQuantityschemas only havex-kubernetes-int-or-string: truewithout atype, so they're skipped.Solution
Add
OptionalIntOrStringtransform that:requiredlist that havex-kubernetes-int-or-string: truenullable: trueif not already presentThis mirrors how Go's controller-tools handles nullable for pointer types (
*IntOrString).Before:
{ "x-kubernetes-int-or-string": true }After: