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

panic generating crd: invalid schema type TypeInvalid #372

Open
jaylevin opened this issue Mar 12, 2024 · 19 comments · May be fixed by #448
Open

panic generating crd: invalid schema type TypeInvalid #372

jaylevin opened this issue Mar 12, 2024 · 19 comments · May be fixed by #448
Labels
bug Something isn't working codegen is:triaged v2
Milestone

Comments

@jaylevin
Copy link
Contributor

jaylevin commented Mar 12, 2024

What happened?

I am trying to generate a new Upjet provider from the Elastic Cloud Terraform Provider.

The first resource I would like to generate is ec_deployment but I am encountering an error during make generate:

panic: cannot generate crd for resource ec_deployment: 
cannot build types for ElasticCloudDeployment: 
cannot build the Types for resource "ec_deployment": 
cannot infer type from schema of field apm: invalid schema type TypeInvalid

The only related issue I could find was #121, but it looks like that issue was fixed by #130 and released in the latest version of upjet (that I'm using): v1.1.0.

How can we reproduce it?

Try running make generate in the repository: https://github.com/jaylevin/provider-elastic-cloud

Schema.json: https://github.com/jaylevin/provider-elastic-cloud/blob/main/config/schema.json

Any help would be greatly appreciated, thanks in advance 😃

@jaylevin jaylevin added the bug Something isn't working label Mar 12, 2024
@haarchri
Copy link
Contributor

did you tried v1.2.3 for upjet ? today its only as tag created

@smileisak
Copy link

@haarchri I have the same issue with provider-ovh, trying to update the terraform provider to last version I got the same error, because of a new created resource that have a nested_type.

make generate
14:23:32 [ .. ] generating provider schema for ovh/ovh 0.39.0
14:23:33 [ OK ] generating provider schema for ovh/ovh 0.39.0
14:23:33 [ .. ] verify go modules dependencies have expected content
all modules verified
14:23:33 [ OK ] go modules dependencies verified
14:23:34 [ .. ] go generate linux_arm64
panic: cannot generate crd for resource ovh_cloud_project_alerting: cannot build types for ProjectAlerting: cannot build the Types for resource "ovh_cloud_project_alerting": cannot infer type from schema of field formatted_monthly_threshold: invalid schema type TypeInvalid

go.md

module github.com/edixos/provider-ovh

go 1.22.0

toolchain go1.22.1

require (
	github.com/crossplane/crossplane-runtime v1.14.0-rc.0.0.20231011070344-cc691421c2e5
	github.com/crossplane/crossplane-tools v0.0.0-20230925130601-628280f8bf79
	github.com/crossplane/upjet v1.2.3
	github.com/pkg/errors v0.9.1
	gopkg.in/alecthomas/kingpin.v2 v2.2.6
	k8s.io/apimachinery v0.30.0-beta.0
	k8s.io/client-go v0.28.2
	sigs.k8s.io/controller-runtime v0.16.2
	sigs.k8s.io/controller-tools v0.13.0
)
...

@jaylevin
Copy link
Contributor Author

jaylevin commented Mar 14, 2024

did you tried v1.2.3 for upjet ? today its only as tag created

I am still getting the same error on v1.2.3 as well.

@erhancagirici
Copy link
Collaborator

@jaylevin @smileisak unfortunately upjet does not support protov6 schemas yet, that have nested attributes. Currently it is not possible to generate such resources.

@jaylevin
Copy link
Contributor Author

jaylevin commented Mar 15, 2024

@jaylevin @smileisak unfortunately upjet does not support protov6 schemas yet, that have nested attributes. Currently it is not possible to generate such resources.

Thanks for the update, is this feature already in progress or are we still looking for a contributor?

@danielsinai
Copy link
Contributor

Hi 👋
Joining to @jaylevin question, this can be really helpful

@littlejo
Copy link

Same problem here

@jonasz-lasut
Copy link

Problem still persists in 1.4.0, joining the question

@ma-ble
Copy link

ma-ble commented Jul 1, 2024

I get the same error message when creating the gitlab_group_access_token crds using upjet v1.4.1.

cannot infer type from schema of field rotation_configuration

rotation_configuration is from typ "Attributes".

@tschlaepfer
Copy link

I get the same error message when creating the platform_oidc_identity_mapping crds using upjet v1.4.0. Is there already a road map for supporting nested attributes?

@jeanduplessis
Copy link
Collaborator

jeanduplessis commented Aug 2, 2024

We will discuss this topic at the next Upjet SIG meeting on Aug 14: https://docs.google.com/document/d/1QJfsAk-pdo_j2cKsJtG6W-BOQh_3ilhiRVTYVIGkDXM/edit

@ekarlso
Copy link

ekarlso commented Sep 9, 2024

@jeanduplessis was anything done / mentioned on the issue on the meeting ? I can't see any updates in the document about it.

@mergenci
Copy link
Member

We discussed the topic off-channel with @ulucinar and @erhancagirici separately. Let me summarize as best as I can. Upjet deserializes provider schema from schema.json into a Terraform Plugin SDK schema. Obviously, Terraform Plugin SDK resources have no problem being deserialized. Most of the Terraform Plugin Framework resources don't have any problems either.

Unfortunately, Plugin Framework resources that contain blocks or nested attributes in their schemas cannot be deserialized. Handling such a deserialization doesn't seem to be straightforward. The ideal solution would be to deserialize each resource type into its own schema type, i.e., deserialize Plugin SDK resources into a Plugin SDK schema and Plugin Framework resources into a Plugin Framework schema. Doing so would require architectural changes to code generation pipeline, which is currently oblivious to the resource types — code generation works with only the Plugin SDK schema, which is why all resources are deserialized into one.

A less-substantial solution would involve finding a way of deserializing blocks and nested attributes into a Plugin SDK schema. Doing so would still require special handling of those fields in code generation, but at least the effort would, hopefully, be less compared to the ideal solution.

We didn't discuss the topic in the meeting, because we prioritized the topics of the attendees. We welcome anyone to the meetings for further discussion.

adriansuarez added a commit to adriansuarez/crossplane-provider-nuodbaas that referenced this issue Sep 21, 2024
This commit is the result of following the instructions in the page:
https://github.com/crossplane/upjet/blob/main/docs/generating-a-provider.md

Step 4 of "Configure the Provider Resources" (`make generate`) fails due
to a bug in the Upjet generator that prevents nested attributes from
being used (crossplane/upjet#372).
wejdross pushed a commit to wejdross/upjet-test that referenced this issue Oct 1, 2024
@wejdross
Copy link

wejdross commented Oct 4, 2024

hello, I'm blocked as well here while trying to generate crossplane-provider from this terraform provider: https://registry.terraform.io/providers/exoscale/exoscale/latest can be used as a test case :)

I'd like to ask You to put some more attention into this issue. Best regards

@tomaszkiewicz
Copy link

tomaszkiewicz commented Oct 4, 2024

+1 to the list of blocked people :)

Maybe you can suggest some workaround, like manually generating missing types? Or annotating somehow these nested blocks so code pipeline can reason from them?

Or... just assume it's an object type with "preserve unknown fields" annotation in CRD, this way we can at least generate most of the work and then do workarounds manually.

@ssch1337
Copy link

+1

@vietanhtwdk
Copy link

+1

@hown3d
Copy link

hown3d commented Nov 6, 2024

Or... just assume it's an object type with "preserve unknown fields" annotation in CRD, this way we can at least generate most of the work and then do workarounds manually.

I think it might be useful to just generate these types are interface{} in the CRD as it would at least not block generating the CRDs at all.

@hown3d hown3d linked a pull request Nov 6, 2024 that will close this issue
3 tasks
@bczoma
Copy link

bczoma commented Nov 18, 2024

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codegen is:triaged v2
Projects
None yet
Development

Successfully merging a pull request may close this issue.