-
Notifications
You must be signed in to change notification settings - Fork 429
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
✨ Generate embedded ObjectMeta with schemapatch as well #563
✨ Generate embedded ObjectMeta with schemapatch as well #563
Conversation
Welcome @markusthoemmes! |
/assign @DirectXMan12 |
@@ -142,6 +147,12 @@ func (g Generator) Generate(ctx *genall.GenerationContext) (result error) { | |||
fullSchema = *fullSchema.DeepCopy() | |||
crdgen.TruncateDescription(&fullSchema, *g.MaxDescLen) | |||
} | |||
|
|||
// Fix top level ObjectMeta regardless of the settings. | |||
if _, ok := fullSchema.Properties["metadata"]; ok { |
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 doesn't seem quite right, because top-level metadata is actually allowed to contain a couple validations, and this is one of the things schemapatch enables.
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.
Interesting, I basically copied the approach over from the crd
generator, where this exact change is done unconditionally as well 🤔.
See
controller-tools/pkg/crd/gen.go
Lines 137 to 138 in 97ee66c
// Prevent the top level metadata for the CRD to be generate regardless of the intention in the arguments | |
FixTopLevelMetadata(crdRaw) |
and
controller-tools/pkg/crd/gen.go
Lines 281 to 290 in 97ee66c
func FixTopLevelMetadata(crd apiext.CustomResourceDefinition) { | |
for _, v := range crd.Spec.Versions { | |
if v.Schema != nil && v.Schema.OpenAPIV3Schema != nil && v.Schema.OpenAPIV3Schema.Properties != nil { | |
schemaProperties := v.Schema.OpenAPIV3Schema.Properties | |
if _, ok := schemaProperties["metadata"]; ok { | |
schemaProperties["metadata"] = apiext.JSONSchemaProps{Type: "object"} | |
} | |
} | |
} | |
} |
Could you elaborate on why this should be different in schemapatch
?
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.
oh hmm this might've been me reviewing too fast. My thought was that maybe people had put in place custom validation, but schemapatch is gonna overwrite that anyway. nevermind :-)
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, markusthoemmes 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 |
Quite similar to #557, this applies the very same options now available on the CRD generator to be available on the
schemapatch
command. Since this option only really affects the generation of the schema anyway, it seems like it should be available on both equally.