Closed Danil-Grigorev closed 2 weeks ago
Attention: Patch coverage is 5.55556%
with 68 lines
in your changes missing coverage. Please review.
Project coverage is 74.6%. Comparing base (
179936a
) to head (4eec7d8
). Report is 5 commits behind head on main.
Files with missing lines | Patch % | Lines |
---|---|---|
kube-derive/src/custom_resource.rs | 5.8% | 66 Missing :warning: |
kube-derive/src/lib.rs | 0.0% | 2 Missing :warning: |
Hey this is great! Thanks a lot for doing this.
I was wondering if you could elaborate a bit on a couple of things:
Unfortunately due to limitations of derive macros, a new #[proc_macro_attribute] is required to allow adjustments of the annotations on the fields, currently named #[cel_validation] (working prototype name),
is this to ensure precedence of annotations?
is there possibly something we could do to simplify these requirements by perhaps referencing a common rewrite rule in kube-core (like we do in schema.rs for structural rewriting)?
is this to ensure precedence of annotations?
yes, I was trying to replace #[validated]
with schemars within the CustomResource derive, but it didn't work (even though there is an implicit derive order and CustomResource comes before JsonSchema). So the macro performs replacement in the first place.
If the keyword comes after derive, no macro will be able to process replaced #[schemars] annotations.
I'll close it for now to find more suitable approach.
Motivation
CRDs allow to declare server-side validation rules using CEL. This functionality is supported via
#[schemars(schema_with = "<schemagen-wrapper>")]
, but requires defining a method with handling logic, which may be error-prone.Since
kube
owns CRD generation code, the idea is to simplify this process for added validation rules and achieve more declarative approach, similar to thekubebuilder
library. This approach will be compatible withkopium
generation based on existing CRD structures, already using CEL expressions.Solution
Allow for a more native handling of CEL validation rules on the CRDs via a field macro.
Unfortunately due to limitations of derive macros, a new
#[proc_macro_attribute]
is required to allow adjustments of the annotations on the fields, currently named#[cel_validation]
(working prototype name),Similar approach may also be used to allow for server-side defaults and other custom modifications of the CRD in the future, if decided.