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 openapi: preserve manually modified/added CRD validation #1155

Closed

Conversation

estroz
Copy link
Member

@estroz estroz commented Feb 28, 2019

Description of the change: preserve manually modified/added CRD validation fields.

Motivation for the change: the generate openapi command fully overwrites CRD manifest validation blocks and any additional validation fields a user might have added. This change preserves any modifications made after scaffolding CRD manifests while adding new fields.

Note that modified fields will not be updated, even if a Go type is changed. Thoughts on this drawback?

@estroz estroz added the kind/feature Categorizes issue or PR as related to a new feature. label Feb 28, 2019
@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Feb 28, 2019
@estroz estroz changed the title Kubebuilder noclobber generate openapi: preserve manually modified/added CRD validation Feb 28, 2019
@joelanford
Copy link
Member

@estroz Other than the issue related to overriding the type validation (as alluded to in #1143), are there other validation fields that cannot be controlled and generated from kubebuilder annotations?

If not, I think kubebuilder annotations should be the one and only way to populate the CRD validations.

If I understand this merge correctly, it seems like users could inadvertently get themselves into interesting situations that are difficult to resolve:

  • As you mentioned, old validations will persist after go types change.
  • Kubebuilder annotations not being honored because a different value already exists in dstCRD.spec.validations (I think this would include trying to change a kubebuilder validation annotation).

@estroz
Copy link
Member Author

estroz commented Mar 1, 2019

@joelanford there are other validations for which no kubebuilder tags exist. There are some cases, like the one you encountered in #1143, where overriding a type is advantageous, although that case can be attributed to lack of validation directive support for overriding types. One solution I can think of
is to implement a custom merge that would override every manifest validation that kubebuilder generated from *_types.go files, which is more work but better reflects the original feature request.

@hasbro17 you originally had issue with overwriting manually modified validations. Any thoughts on @joelanford's concerns?

@joelanford
Copy link
Member

One solution I can think of
is to implement a custom merge that would override every manifest validation that kubebuilder generated from *_types.go files

@estroz I'm pretty sure that would solve the concern with my second point in that we would prefer the kubebuilder annotation value over the existing value.

To solve the issue with changing Go types, would the merge function also be able to delete fields from dstCRD.spec.validations if they are not found in the validations produced from the kubebuilder annotations?

@hasbro17
Copy link
Contributor

hasbro17 commented Mar 1, 2019

So I agree that we should prefer the validation generated by the kubebuilder tag if present for a particular field.

And in the case when *_types.go is modified to remove a field I think the controller-tools crd generator will not generate any validation for that field. We can use that as an indicator that all fields not found in the validation generated by the controller-tools crd generator should be removed from the existing validation block in *_crd.yaml.

So for e.g if status.nodes had custom validation added by the user and it is changed to status.pods in *_types.go then we can see that there is no validation.openAPIV3Schema.properties.status.properties.nodes in the new validation block so we don't preserve it in the merge.

@estroz I'm not sure of the actual implementation of the custom merge yet but I think it should be possible to compare and weed out validation fields for which there is no corresponding spec/status field.

@estroz
Copy link
Member Author

estroz commented Mar 1, 2019

@joelanford @hasbro17 that's doable.

@shawn-hurley
Copy link
Member

shawn-hurley commented Mar 3, 2019 via email

@openshift-ci-robot openshift-ci-robot added 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. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 4, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 4, 2019
@lilic
Copy link
Member

lilic commented Mar 20, 2019

What did we decide with this, are we going to contribute upstream, or is this ready for a review? :)

@estroz
Copy link
Member Author

estroz commented Mar 25, 2019

@lilic opened an issue upstream: kubernetes-sigs/controller-tools#156
We can hold off on reviewing this for now.

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 25, 2019
@openshift-ci-robot openshift-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2019
@openshift-ci-robot openshift-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 2, 2019
@hasbro17
Copy link
Contributor

hasbro17 commented Apr 5, 2019

@estroz Since we're planning to add support for all validation directives upstream, we can close this PR since we don't need to merge and preserve manual additions to the CRD manifest's validation block.

@estroz estroz closed this Apr 5, 2019
@estroz estroz deleted the kubebuilder-noclobber branch April 5, 2019 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/feature Categorizes issue or PR as related to a new feature. 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.

6 participants