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

Make the CRD Puller more robust #66

Merged
merged 2 commits into from
May 11, 2021
Merged

Make the CRD Puller more robust #66

merged 2 commits into from
May 11, 2021

Conversation

davidfestal
Copy link
Member

Make the CRD Puller more robust:

  • correctly get the OpenAPI v2 model based on the GVK (instead of of guessing it erroneously)
  • avoid pulling resource types that are part of the kcp control plane
  • avoid stack overflow for recursive OpenAPI V2 schemas
  • support resources with non structural OpenAPI schemas, but disable validation in imported resource type
  • support protected community groups by adding the required annotation in imported CRD.

- correctly get the OpenAPI v2 model based on the GVK
(insteaof of guessing it erroneously)
- avoid pulling resource types that are part of the kcp control plane
- avoid stack overflow for recursive OpenAPI V2 schemas
- support resources with non structural OpenAPI schemas,
but disable validation in imported resource type
-  support protected community groups by adding the required annotation
in imported CRD.

Signed-off-by: David Festal <dfestal@redhat.com>
Copy link
Contributor

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

avoid stack overflow for recursive OpenAPI V2 schemas

Do we have examples of recursive schemas like this? This seems like a useful test case.

pkg/crdpuller/discovery.go Show resolved Hide resolved
@@ -92,133 +107,161 @@ func (sp *schemaPuller) PullCRDs(context context.Context, resourceNames ...strin
for _, apiResourcesList := range apiResourcesLists {
gv, err := schema.ParseGroupVersion(apiResourcesList.GroupVersion)
if err != nil {
klog.Errorf("skipping discovery due to error parsing GroupVersion %s: %v", apiResourcesList.GroupVersion, err)
klog.Errorf("CRDPuller: Skipping discovery due to error parsing GroupVersion %s: %v", apiResourcesList.GroupVersion, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

If klog is used here mainly to get line numbers, I think we could remove the CRDPuller prefix, wdyt?

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me remove them, right.

pkg/crdpuller/discovery.go Outdated Show resolved Hide resolved
pkg/crdpuller/discovery.go Outdated Show resolved Hide resolved

break
apiextensionsv1.SetDefaults_CustomResourceDefinition(crd)
if apihelpers.IsProtectedCommunityGroup(gv.Group) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment describing why we're doing this here, and how it's related to that PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@davidfestal
Copy link
Member Author

avoid stack overflow for recursive OpenAPI V2 schemas

Do we have examples of recursive schemas like this? This seems like a useful test case.

The CustomResourceDefinition resource was a typical example (JsonSchemaProps schema is recursive), which I used to test this use-case. However with the other changes in this PR, it will not even be imported since we now skip all the resources that are already known by KCP internally.

Signed-off-by: David Festal <dfestal@redhat.com>
@davidfestal
Copy link
Member Author

@imjasonh Can you confirm whether it's OK for you now ?

@imjasonh imjasonh merged commit 65ce2ee into kcp-dev:main May 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants