Skip to content

pkg/registry: use v1beta1.CustomResourceDefinition, as the apiextensions type is internal#86

Merged
openshift-merge-robot merged 1 commit intooperator-framework:masterfrom
estroz:fix-crd-encoding
Oct 12, 2019
Merged

pkg/registry: use v1beta1.CustomResourceDefinition, as the apiextensions type is internal#86
openshift-merge-robot merged 1 commit intooperator-framework:masterfrom
estroz:fix-crd-encoding

Conversation

@estroz
Copy link
Copy Markdown
Member

@estroz estroz commented Sep 11, 2019

The type apiextensions.CustomResourceDefinition is an internal type that should not be used for unmarshaling. Instead v1beta1.CustomResourceDefinition should be used. When unmarshaling the former type, fields are not properly populated, ex. objectmeta.name is missing. Using a runtime.Decoder with Scheme will not cause JSON number issues (at least with one manual test).

/cc @ecordell @njhale

@openshift-ci-robot openshift-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Sep 11, 2019
Comment thread pkg/registry/bundle.go Outdated
return err
crd := &v1beta1.CustomResourceDefinition{}
dec := serializer.NewCodecFactory(Scheme).UniversalDeserializer()
_, _, err = dec.Decode(cb, nil, crd)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will throw an error if a CRD version created in the future wasn't registered with Scheme. This is could be considered a feature ("we don't explicitly support that CRD version yet, throw an error"); simply using json.Unmarshal may cause silent marshaling errors like the one I describe in the PR comments. Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That was the reasoning behind using the internal types in the first place, but it's reasonable to only support certain types.

Copy link
Copy Markdown
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.

Thanks for fixing this!

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 12, 2019
@openshift-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ecordell, estroz

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details 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 Oct 12, 2019
@openshift-merge-robot openshift-merge-robot merged commit 628ebd4 into operator-framework:master Oct 12, 2019
@estroz estroz deleted the fix-crd-encoding branch October 30, 2019 19:40
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. lgtm Indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants