Skip to content

✨ metadata field changes for structural schema #263

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

Closed

Conversation

droot
Copy link
Contributor

@droot droot commented Jul 17, 2019

This PR handles generating schema for metadata as per structural schema.
https://github.com/kubernetes/enhancements/blob/master/keps/sig-api-machinery/20190425-structural-openapi.md

Partial fix for #216

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 17, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: droot

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 17, 2019
@droot
Copy link
Contributor Author

droot commented Jul 17, 2019

/cc @DirectXMan12 @sttts @mengqiy

@k8s-ci-robot k8s-ci-robot requested review from mengqiy and sttts July 17, 2019 18:50
ident.Package.ID == metav1Pkg && ident.Name == "ObjectMeta":
return &apiext.JSONSchemaProps{
Type: "object",
Properties: map[string]apiext.JSONSchemaProps{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these two are possible, but not needed in a structural schema.

return nil
// TODO(droot): enable it once we move k8s 1.15
// return &apiext.JSONSchemaProps{
// // XEmbeddedResource: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this @DirectXMan12 brought up the point of partial ObjectMeta. There is no requirement that the metadata is complete for an embedded resource. /cc @liggitt

We either want a way to mark an embedded ObjectMeta as partial, or we relax the validation we do today (if that is possible now in beta). @liggitt wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is currently required that we would want to relax?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as far as I remember, only kind/apiVersion were required

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's about ObjectMeta: name, namespace as far as I see.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name must be optional in openapi because of generateName, and iirc our server-side implementation put a dummy name in place when validating if no name was provided

namespace must already be optional (both server-side and in openapi) because of cluster-scoped resources

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I think I misunderstood @DirectXMan12 in Slack. He was talking about TypeMeta (and I remember the dummy name value we put it to work around the check).

So the question is whether without TypeMeta it is really an embedded object.

@droot
Copy link
Contributor Author

droot commented Jul 18, 2019

@sttts @DirectXMan12 @mengqiy I reevaluated my approach and thought of another approach:

By default, do not generate any validation for ObjectMeta (irrespective of it being a root or embedded). Let users specify marker // +kubebuilder:validation:embedded if we want to enable validation for embedded objects. This is how users do it for enabling any validation for the fields in the spec today, so it's inline with that. This will also avoid the partial objectMeta issue that @stts commented above where in current flattenVisitor it doesn't have a good way to track if objectMeta has sibling node TypeMeta or not. Thoughts ?

@DirectXMan12
Copy link
Contributor

sgtm on the marker

@DirectXMan12
Copy link
Contributor

that doesn't actually resolve the problem though -- the x-kubernetes-embedded, IIRC requires apiVersion and kind to be specified too, so won't work for things like the template field in Deployment/CronJob/etc.

@sttts @liggitt

but we can tackle that later

@droot droot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 18, 2019
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 18, 2019
@k8s-ci-robot
Copy link
Contributor

@droot: 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/test-infra repository.

@droot
Copy link
Contributor Author

droot commented Jul 19, 2019

closing this in favor of #266

@droot droot closed this Jul 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants