-
-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow opting out of schema derivation per kind #690
Allow opting out of schema derivation per kind #690
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a better solution. Thanks a lot!
It will force schemars into the dependency tree of people not overriding the schema, but because it's going to be required to have a schema anyway, that's probably OK.
One minor suggestion on docs, but otherwise LGTM.
I don't see how this PR changes anything here? kube-derive doesn't depend on |
oh, right that's in the generated code! that's even better. definitely no need for the feature then 👍 |
f8d5e0b
to
870f536
Compare
@clux I redesigned the attribute a bit so that we now also support custom |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some nits and questions on the new mode
kube-derive/src/custom_resource.rs
Outdated
Disabled, | ||
Custom, | ||
Derived, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally misunderstood the intention of these names, so proposing some new ones:
Disabled
->Elide
(to distance ourselves from the separate requirement of having these)Custom
->Specialize
(to indicate more clearn that a user has to specialize its impl)Derived
->Derive
or(to more indicate no user action needed)Auto
That also potentially reads nicer with a short-hand name:
#[kube(schema = "Elide")]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
although, that said, the imperative form of the verbs, while helpful for Derive
("you do it program"), is probably not so helpful for Specialize
..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we just have two bools instead:
#[kube(schema_specialize)
#[kube(schema_elide)
that matches the internal model (and the bools have no meaningful overlap)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not married to any of the current names, but I'm not sold on any of your proposed changes either.
Disabled -> Elide (to distance ourselves from the separate requirement of having these)
Elide
sounds like lifetime elision to me (in a Rust context).. the lifetimes still exist but we can imply them from the context (which, if anything, is closer to deriving than disabling IMO)
Custom -> Specialize (to indicate more clearn that a user has to specialize its impl)
This sounds like trait/type specialization, and I think the connection might confuse more than it helps..
Derived -> Derive or Auto (to more indicate no user action needed)
Auto
implies to me that we automatically select the mode (which is currently implied when there is no schema_mode
attribute)
two bools
Bleh.
That said, I think this raises the question about whether SchemaMode::Disabled
is operating at the wrong abstraction level.. Maybe the better question would be whether we should have a flag to disable Self::crd()
wholesale (for a given kind)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the other hand, it might be worth keeping SchemaMode::Disabled
around (in some form) as a migration path for people who have used the current override...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rustc issue, not a darling (or syn) one. When I was testing it I was dumping the raw token stream that we get fed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you can dump the full input in kube-derive/lib.rs
and the doc comments before are in fact available to the input, but not the root #[derive(..)]
:-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see derive
if I move them into a separate derive
, but that's useless:
#[derive(CustomResource)]
//
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, JsonSchema)]
struct ExampleSpec {
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we can't do this. rust-lang/rust#40574 (comment)
To be honest, I would have preferred to not special-case the derive at all, and just let people
#[kube(derive(JsonSchema))]
it if they wanted to.
How does this work? Maybe I'm misremembering, but I thought we couldn't modify the input struct. Is it possible to add derive(JsonSchema)
to it? Doesn't the spec struct need derive(JsonSchema)
to have schema generated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does this work?
We cannot modify the input, but we were just thinking about reading that derive property.
The key struct here isn't the spec struct, but the generated root struct, which needs to implement JsonSchema
(with our injected derive on it, or manually by the user) for the schema to get included in the ::crd()
method.
The only remaining possibility here afaikt is that we could use #[kube(derive = "JsonSchema")]
as an indicator of whether to automatically derive JsonSchema
on the root struct (rather than select it as part of a tri-state enum, or, do as we do know and inject it by default if the feature is on). But that would be a pretty big breaking change (and it would break in a way-too-subtle way to introduce at this stage).
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Co-authored-by: kazk <[email protected]> Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Co-authored-by: kazk <[email protected]> Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
bf01aa3
to
92090b1
Compare
I'd like to have this merged in because it's a great improvement, and all actionable issues have been addressed 👍 . The only thing we miss here is resolving the merge conflicts and possibly thinking of better names, but none of my suggestions seem much better either, so lacking any new suggestions, let's merge this? |
Co-authored-by: Eirik A <[email protected]> Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
1594029
to
ca99b44
Compare
The merge conflicts should be fixed now @clux |
LGTM. Although tests need the same replace. Happy to approve at green though! |
Signed-off-by: Teo Klestrup Röijezon <[email protected]>
There's always something, huh. 🤦 |
The feature-flag approach was problematic since it applies to the whole dependency tree: as long as any crate depends on
kube_derive
without disabling default features then the derived schema becomes mandatory.This PR adds a new
#[kube(derive_schema = false)]
attribute that allows you to specify this per kind.