-
Notifications
You must be signed in to change notification settings - Fork 441
✨ New kubebuilder:schemaModifier CRD marker #1140
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
base: main
Are you sure you want to change the base?
✨ New kubebuilder:schemaModifier CRD marker #1140
Conversation
Welcome @yaroslavborbat! |
Hi @yaroslavborbat. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: yaroslavborbat The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Yaroslav Borbat <[email protected]>
71a1237
to
d0371a8
Compare
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 should have unit-test coverage.
I'd like to understand the use-case some more: Can't this be done by just not setting markers at some fields?
I guess this does not work e.g. for description, but I don't get it for other fields.
Where there are lists, for example an enum, would you need to specify the entire enum with this marker, and how would that look? What separators are used? Does this encourage the use of/give folks the ability to create schemas that aren't valid? I wonder if we want to encourage patching schemas in ways that could be foot guns? WDYT? |
Hi @chrischdi! I'll add test coverage for this soon. This approach works for description and should also work for other fields. CRD markers are processed last, when the full schema has already been generated, so we can traverse it recursively and modify fields as needed. One key use case is when defining a CRD that includes imported types. Since we cannot modify or extend annotations on those types directly, this marker allows us to adjust their schema properties where necessary. |
Hi @JoelSpeed! Here’s an example of how I replaced the required list and the description: // +kubebuilder:schemaModifier:pathPattern=/spec/testObject,required={"field1", "field2", "field3", "field4"},description="new my description" Regarding schema validity, this marker does allow users to generate an invalid schema if used incorrectly, so it should be used with caution. At the same time, it provides additional flexibility in CRD generation. Personally, I found such a marker useful, which is why I created this PR 🙃. |
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Overview
Closes #441
This pull request introduces a new marker
kubebuilder:schemaModifier
, which allows modifying specific fields inJSONSchemaProps
for CustomResourceDefinitions (CRDs). This marker supports flexible rules for targeting specific paths in the CRD schema and allows setting multiple properties at once.Details
New Marker:
kubebuilder:schemaModifier
The
schemaModifier
marker operates on CRD schemas and enables users to apply modifications to specific fields. The targeting of fields is achieved using thePathPattern
attribute, which defines a path-matching rule using a JSONPath-like syntax:*
: Matches any single field name (e.g.,/spec/*/field
).**
: Matches fields across multiple levels of nesting (e.g.,/spec/**/field
).This marker can update multiple properties in
JSONSchemaProps
, such asDescription
,Format
,Maximum
,Nullable
, and others.Example:
// +kubebuilder:schemaModifier:pathPattern=/spec/exampleObject/*,description=""
The above example applies the empty description to all fields matching /spec/exampleObject/*.
How This Was Tested
Currently, no tests have been added for this feature. However, once the structure and approach are approved, I plan to add integration tests to verify the functionality of the
kubebuilder:schemaModifier
marker.