Skip to content
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 in the CRDs #539

Closed

Conversation

dvaldivia
Copy link
Contributor

@dvaldivia dvaldivia commented Jan 27, 2021

This PR makes it so embedded ObjectMeta in the CRD get's properly generated if the generator option generateEmbeddedObjectMeta=true is passed, this is needed because if a CRD has embedded ObjectMeta in any field and preserveUnknowFields is set to false, all the metadata will be lost when doing conversion between versions.

An example on how to have the embedded ObjectMeta generated in the resulting CRD

controller-gen crd:maxDescLen=0,generateEmbeddedObjectMeta=true paths=. output:dir=.

This PR makes it so by default any embedded ObjectMeta is not generated in the resulting CRD, however the top level ObjectMeta belonging to the CRD itself is never generated as the kubernetes API disallows changes to the CRD metadata between conversions.

The generated ObjectMeta is also only a subset of the original set of fields inside ObjectMeta this is due to the fact that other runtime fields are problematic if they are being traded with the kubernetes API, such as creationTimeStamp (rancher/rancher#23857) so this only generates name, namespace, labels, annotations and finalizers which from a design perspective should be enough. This follows the recommendation by @sttts who recommended a EmbeddedObjectMeta but instead of using a different type, we have a reduced set of fields that are "just enough" for a CRD design.

An example of why we need this is for example if a CRD had a volumeClaimTemplate (for an underlying statefulset) which include ObjectMeta such as Labels, Annotations and/org name which are meant to be passed to the PVC where getting lost between conversions.

This PR is based on the work by @arjunrn and @champak following the discussion on #448 and the PR #498 and it's also similar to #395 as it addressed the same problem, but adds the type casting for FieldsV1 and the requested argument to control this feature (per @DirectXMan12 on #395)

@k8s-ci-robot
Copy link
Contributor

Welcome @dvaldivia!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 27, 2021
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 27, 2021
@dvaldivia dvaldivia changed the title ⚠ ⚠️ Generate Embedded ObjectMeta in the CRDs ⚠ Generate Embedded ObjectMeta in the CRDs Jan 27, 2021
@dvaldivia
Copy link
Contributor Author

/assign @DirectXMan12

@dvaldivia
Copy link
Contributor Author

I updated the PR description

Copy link
Contributor

@DirectXMan12 DirectXMan12 left a comment

Choose a reason for hiding this comment

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

really minor comment as per the meeting today, otherwise looks good

if f, ok := KnownPackages["k8s.io/apimachinery/pkg/apis/meta/v1"]; ok {
f(p, pkg)
}
// This is a allow-listed set of properties of ObjectMeta, other runtime properties are not part of this list
Copy link
Contributor

Choose a reason for hiding this comment

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

as per the meeting today, please link to sttts's comment here

Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, I think @DirectXMan12 is referring to this comment #395 (comment). Can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, that's what I was talking about.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@DirectXMan12 @coderanger I'll update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, rebased, squashed and comment added.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: dvaldivia
To complete the pull request process, please ask for approval from directxman12 after the PR has been reviewed.

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 20, 2021
@k8s-ci-robot
Copy link
Contributor

@dvaldivia: 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.

1 similar comment
@k8s-ci-robot
Copy link
Contributor

@dvaldivia: 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.

@DirectXMan12
Copy link
Contributor

subsumed by #557 (with attribution :-) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants