-
Notifications
You must be signed in to change notification settings - Fork 428
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
Add crdschema generator #183
Add crdschema generator #183
Conversation
/assign @DirectXMan12 @damemi @droot |
@sttts: GitHub didn't allow me to assign the following users: damemi. Note that only kubernetes-sigs members and repo collaborators can be assigned and that issues/PRs can only have 10 assignees at the same time. In response to this:
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/test-infra repository. |
f9cf6cb
to
2535f8f
Compare
We've actually been working on a similar refactoring that might help you, because other users want to be able to generate stand-alone validation schemas. Hopefully that should make this easier. As it stands, this code is a bit too hacky to merge, IMO, but the refactor should make it much nicer. /hold |
discussed a bit more with @sttts TL;DR: I like the idea of being able to generate a schema by itself (we actually have other people that want it too). Generating a stand-alone schema, or a schema as a patch, should be fine. Any patching should probably just be done using kustomize instead. @mengqiy is working on a refactor that should make this less hacky. cc @damemi as well |
4b5814e
to
5bd4a20
Compare
@DirectXMan12 @damemi ported this to the new generator pattern. |
5bd4a20
to
eef7dc0
Compare
96bedf6
to
d0d9d53
Compare
@DirectXMan12 @damemi @droot could you have another look? |
f5b6a90
to
f210224
Compare
👍 on this, this would help us a lot in many operators doing schema generation. |
+1 |
yeah, I'm super-sorry about this one. I've just been really swamped recently, and it kinda fell off my radar. |
f210224
to
300e96e
Compare
ok, I've pushed some changes to this that bring it to a position where I'm more comfortable merging this (I'm still a bit uncomfortable with all the raw YAML manipulation, but it's hard to avoid that with your usecase constraints). Namely:
The "no reordering of maps" properties are still preserved, as are comments and flow vs block style. I'd like to have @droot take a quick look at this too, since I've refactored a bunch of stuff myself. |
5e8ebd1
to
4452725
Compare
pkg/schemapatcher/gen.go
Outdated
// - It needs to make "stable" changes that don't mess with map key ordering | ||
// (in order to facilitate validating that no change has occurred) | ||
// - It needs to collapse identical schema versions into a top-level schema, | ||
// if all versions are identical |
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 not special for schemapatcher, but a general requirement for multi-version, schemaful CRDs.
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'll make this clearer in the comment -- I was mainly just trying to motivate why "stick the output of parser.NeedFlattenedSchema
into a single JSON patch operation" is insufficient.
@DirectXMan12 your rewrite looks good. I am having problems to run the tests though, and also to run the binary (probably the same issue):
|
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.
looks good to me.
cmd/controller-gen/main.go
Outdated
@@ -134,6 +136,9 @@ func main() { | |||
# Generate deepcopy/runtime.Object implementations for a particular file | |||
controller-gen object paths=./apis/v1beta1/some_types.go | |||
|
|||
# Generate OpenAPI v3 schemas for API packages and merge them into existing CRD manifests | |||
controller-gen crdschema paths=./pkg/apis/... crdschema:manifests=./manifests output:dir=./manifests |
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.
s/crdschema/schemapatch
whoops, didn't actually get merged here. Will fix this up this week and get this merged. |
This updates schemapatcher (formerly crdschema) rather drastically, reducing its scope a bit and cleaning up its code to bring it in line with the rest of controller-tools. Functionality changes: - change verification is removed -- use diff - yaml.v3 is used, which should preserve comments, style, etc - CRDs are written unconditionally. Doing this for unchanged CRDs should be a no-op, modulo slight whitespace changes.
4452725
to
3687756
Compare
ok, fixed up now. The reason your invocation didn't work is because you've got an extra |
tested against the openshift cluster network operator repo too, just in case. |
and now, the rare, arcane, not-quite-self-approval, a secret technique pass down from ancient aeons: /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/hold cancel |
@DirectXMan12 this is fantastic news! Thanks for finishing this up and get it merged 🎉🚀 |
While the crd generator creates complete CRD manifests from tags, the crdschema generator is much less opinionated and only updates validation schemas in a given directory of CRD manifests.
# Generate OpenAPI v3 schemas for API packages and merge them into existing CRD manifests $ controller-gen crdschema paths=./pkg/apis/... crdschema:manifests=./manifests output:dir=./manifests