Skip to content

Bug 1825330: support creating v1beta CRDs to avoid data loss #1470

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

Merged
merged 2 commits into from
Apr 28, 2020

Conversation

exdx
Copy link
Member

@exdx exdx commented Apr 21, 2020

Description of the change:
Supporting v1 CRDs originally intended to create and update all CRDs at v1 - converting those provided at v1beta1. However, due to some issues around the validation, and the fact that CRDs are not fully backward-compatible, OLM will have to create v1beta1 CRDs with the v1beta1 client. This PR adds back support for creating v1beta1 CRDs.

Motivation for the change:

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

@exdx exdx requested review from ecordell and njhale April 21, 2020 00:23
@exdx exdx changed the title fix: support creating v1beta CRDs to avoid data loss Bug 1825330: support creating v1beta CRDs to avoid data loss Apr 21, 2020
@openshift-ci-robot openshift-ci-robot added bugzilla/high bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. labels Apr 21, 2020
@openshift-ci-robot
Copy link
Collaborator

@exdx: This pull request references Bugzilla bug 1825330, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state ASSIGNED, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1825330: support creating v1beta CRDs to avoid data loss

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.

@njhale
Copy link
Member

njhale commented Apr 21, 2020

It would be nice to have a test that reproduces the issue so we can be certain of the cause and catch it in the future.

@njhale
Copy link
Member

njhale commented Apr 21, 2020

Putting this here for record keeping purposes: kubernetes/kubernetes#87231

@exdx exdx force-pushed the fix/bug-1825330 branch from 13817b7 to 9b3ea60 Compare April 21, 2020 14:59
@sttts
Copy link
Contributor

sttts commented Apr 22, 2020

/hold

Here is so much wrong about conversion.

@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 Apr 22, 2020
@exdx
Copy link
Member Author

exdx commented Apr 22, 2020

Closing this in favor of adding a v1beta1 codepath (something we had originally done in prior versions of the v1 support PR). There will be no client-side conversion between v1beta1 and v1 CRD types in OLM.

@exdx exdx closed this Apr 22, 2020
@exdx exdx reopened this Apr 22, 2020
@openshift-ci-robot
Copy link
Collaborator

@exdx: This pull request references Bugzilla bug 1825330, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.5.0) matches configured target release for branch (4.5.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

In response to this:

Bug 1825330: support creating v1beta CRDs to avoid data loss

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.

return nil
}
convertedCRD := &apiextensions.CustomResourceDefinition{}
if err := apiextensionsv1beta1.Convert_v1beta1_CustomResourceDefinition_To_apiextensions_CustomResourceDefinition(newCRD, convertedCRD, nil); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

here is still a conversion.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we convert to the internal version to do static schema validation. Specifically, the NewSchemaValidator which creates an openapi schema validator for the given CRD validation, expects an internal CRD type to be provided to it, so OLM does the conversion here when validating the new CRD.

The internal CRD is never written to the cluster again. We can make a follow-up BZ to use dry-run APIs instead of using the internal validation package, if necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, would prefer dry-run (follow-up). The schema validator is also a component considered private.

Copy link
Member

@ecordell ecordell Apr 27, 2020

Choose a reason for hiding this comment

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

How can we dry-run against an CRD API that has not been applied to the cluster yet?

The goal is to catch the mistake before the CRD has been created.

There seems to be little practical issue with using the internal types, correct? We could just as easily read the json schema from the CRD spec and use an off-the-shelf schema validator to accomplish the same goals.

…n to v1. Due to data loss during client side conversions OLM will support two different paths for v1 and v1beta1 CRDs.
@exdx exdx force-pushed the fix/bug-1825330 branch 2 times, most recently from ea2997d to 5f054ee Compare April 27, 2020 20:12
return nil
}
convertedCRD := &apiextensions.CustomResourceDefinition{}
if err := apiextensionsv1beta1.Convert_v1beta1_CustomResourceDefinition_To_apiextensions_CustomResourceDefinition(newCRD, convertedCRD, nil); err != nil {
Copy link
Member

@ecordell ecordell Apr 27, 2020

Choose a reason for hiding this comment

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

How can we dry-run against an CRD API that has not been applied to the cluster yet?

The goal is to catch the mistake before the CRD has been created.

There seems to be little practical issue with using the internal types, correct? We could just as easily read the json schema from the CRD spec and use an off-the-shelf schema validator to accomplish the same goals.

@exdx
Copy link
Member Author

exdx commented Apr 28, 2020

/test e2e-gcp

2 similar comments
@exdx
Copy link
Member Author

exdx commented Apr 28, 2020

/test e2e-gcp

@exdx
Copy link
Member Author

exdx commented Apr 28, 2020

/test e2e-gcp

Copy link
Member

@ecordell ecordell left a comment

Choose a reason for hiding this comment

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

/lgtm

return crd, nil
}

// UnmarshalV1 takes in a CRD manifest and returns a v1beta1 versioned CRD object.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// UnmarshalV1 takes in a CRD manifest and returns a v1beta1 versioned CRD object.
// UnmarshalV1Beta1 takes in a CRD manifest and returns a v1beta1 versioned CRD object.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2020
@benluddy
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: benluddy, exdx

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 28, 2020
@openshift-merge-robot openshift-merge-robot merged commit 15f5ba3 into operator-framework:master Apr 28, 2020
@openshift-ci-robot
Copy link
Collaborator

@exdx: All pull requests linked via external trackers have merged: operator-framework/operator-lifecycle-manager#1470. Bugzilla bug 1825330 has been moved to the MODIFIED state.

In response to this:

Bug 1825330: support creating v1beta CRDs to avoid data loss

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.

njhale added a commit to njhale/operator-framework-api that referenced this pull request Apr 29, 2020
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).
njhale added a commit to njhale/operator-framework-api that referenced this pull request Apr 29, 2020
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).
ankitathomas pushed a commit to ankitathomas/operator-framework-olm that referenced this pull request Apr 6, 2021
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).

(cherry picked from commit 7d6ac12ec8bc5a864646bae56bf80d138c922b61)
ankitathomas pushed a commit to ankitathomas/operator-framework-olm that referenced this pull request Apr 6, 2021
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).

(upstream api commit: 7d6ac12ec8bc5a864646bae56bf80d138c922b61)
ankitathomas pushed a commit to ankitathomas/operator-framework-olm that referenced this pull request Apr 9, 2021
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).

(upstream api commit: 7d6ac12ec8bc5a864646bae56bf80d138c922b61)
openshift-merge-robot pushed a commit to openshift/operator-framework-olm that referenced this pull request Jul 14, 2021
Replace hub and spoke CRD conversion with direct unmarshaling to v1.
This follows advice to avoid the internal k8s types and conversions
client-side (see operator-framework/operator-lifecycle-manager#1470 (comment)).

Upstream-repository: api
Upstream-commit: 7d6ac12ec8bc5a864646bae56bf80d138c922b61
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. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants