-
Notifications
You must be signed in to change notification settings - Fork 411
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
🐛 Don't generate description on metadata of CRD structural schema #511
🐛 Don't generate description on metadata of CRD structural schema #511
Conversation
/assign @DirectXMan12 |
@kevindelgado: GitHub didn't allow me to request PR reviews from the following users: tamalsaha. Note that only kubernetes-sigs members and repo collaborators can review this PR, and authors cannot review their own PRs. 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. |
25aec56
to
1e01ebf
Compare
1e01ebf
to
3e8c2d0
Compare
3e8c2d0
to
ba4545c
Compare
Was waiting for #499 to land with the basic gen_integration_test before nudging this, but that's merged now, can you take a look @DirectXMan12 |
ba4545c
to
4618eac
Compare
friendly ping @DirectXMan12 |
/lgtm |
/hold |
/lgtm cancel we should be doing this in the output openapi, not in the input godoc |
4618eac
to
621bc14
Compare
621bc14
to
a826e7f
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.
metadata description is now stripped on the output open API schema instead of the input godoc.
It definitely doesn't feel as clean as the one line fix on the input, but I get that we might want to hang onto the raw godoc for as long as possible.
Let me know if you have any suggestions to clean this up. PTAL @DirectXMan12
pkg/crd/gen.go
Outdated
if m, ok := v.Properties["metadata"]; ok { | ||
meta := &m | ||
if meta.Description != "" { | ||
fmt.Fprintf(os.Stderr, "Warning: metadata description unsupported. Removing description: %s\n", meta.Description) |
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.
Is this warning actually useful or can we assume that users know their ObjectMeta godoc comments will not make it into the CRD schema?
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.
Hi, I test your code in myself environment but it don't work well because of the other fields may container the struct JSONSchemaProps
also. I try to changed the code as follow and it works. That's only a suggestion.
if v == nil {
return
}
for str, property := range v.Properties {
if str == "metadata" {
if property.Description != "" {
fmt.Fprintf(os.Stderr, "Warning: version metadata description unsupported. Removing description: %s\n", property.Description)
property.Description = ""
}
}
if property.Items != nil {
removeDescriptionFromMetadataProps(property.Items.Schema)
for i := range property.Items.JSONSchemas {
removeDescriptionFromMetadataProps(&property.Items.JSONSchemas[i])
}
}
if property.AdditionalProperties != nil {
removeDescriptionFromMetadataProps(property.AdditionalProperties.Schema)
}
if property.AdditionalItems != nil {
removeDescriptionFromMetadataProps(property.AdditionalItems.Schema)
}
removeDescriptionFromMetadataProps(&property)
v.Properties[str] = property
}
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.
friendly ping @kevindelgado
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.
Thanks!
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.
top-level metadata shouldn't have any fields -- it's explicitly stripped because the kubernetes API server replaces/ignores most of it.
AFAIK, the API server only enforces this constraint on the top-level metadata field, not any embedded metadata, so it should be sufficient to simply clear description from the the root metadata field, and leave it at that.
@whalecold if this doesn't work, can you please provide an example that's giving you issues
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 warning might actually just confuse people too, so prob best to remove it -- it's gonna hit a lot of codebases and doesn't really have a material impact on them.
if crdVersions[i] == "v1beta1" { | ||
removeDefaultsFromSchemas(crd.(*apiextlegacy.CustomResourceDefinition)) | ||
removeDescriptionFromMetadataLegacy(crd.(*apiextlegacy.CustomResourceDefinition)) |
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.
Not loving the duplicated functions for v1 and v1beta1, but I couldn't find a cleaner way to make it work. I thought of passing the generic runtime.Object
into a single removeDescriptionFromMetadata()
function, but it didn't seem any better since we already have to do the crdVersions check for removing defaults. Let me know if there's a better way.
PTAL @DirectXMan12 |
9f6c0f9
to
d77973a
Compare
pkg/crd/gen.go
Outdated
} | ||
// property var reference is fine -- we handle the persistence of the modfications on the line below | ||
//nolint:gosec | ||
removeDescriptionFromMetadataProps(&property) |
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.
why are we recursing here?
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.
See feedback from @whalecold here
I took it to mean that there could be objects embedded within the object (e.g. within the spec field), is that wrong? See the first commit for the non-recursive approach.
@whalecold can you provide an example of where this breaks if you don't recurse the fields that contain addition JSONSchemaProps
?
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.
Reverted back to modifying only the top level metadata description, as @DirectXMan12 and I tested that kube apiserver accepts embedded objects with metadata descriptions.
0615953
to
474f612
Compare
cdb18f4
to
d7d8fd1
Compare
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: DirectXMan12, kevindelgado 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 |
What
Ensures that generated CRDs do not have a description generated from godoc comments on the ObjectMeta of the corresponding go type.
Why
Fixes #386
CRD structural schema requires that if metadata is specified, then only restrictions on metadata.name and metadata.generateName are allowed.
metadata.description is not allowed
xref: kubernetes/kubernetes#86800