🐛 crd: add regression test for type alias deps not directly imported#1344
🐛 crd: add regression test for type alias deps not directly imported#1344meliezer wants to merge 1 commit intokubernetes-sigs:mainfrom
Conversation
Signed-off-by: Menashe Eliezer <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: meliezer The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
|
|
Welcome @meliezer! |
|
Hi @meliezer. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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-sigs/prow repository. |
| @@ -0,0 +1,91 @@ | |||
| package crd_test | |||
There was a problem hiding this comment.
Sorry not sure I follow why this test cannot be added like all our other tests
There was a problem hiding this comment.
Thanks for taking a look! The only reason this test runs controller-gen from pkg/crd/testdata is that pkg/crd/testdata is its own Go module (module testdata.kubebuilder.io/cronjob in pkg/crd/testdata/go.mod).
The repro packages live under that module (testdata.kubebuilder.io/cronjob/issue1063/...). If the test runs controller-gen with cmd.Dir set to the repo root (main module), go/packages ends up trying to resolve those imports from the main module and fails with “no required module provides package …/issue1063/repro2”. Running from the testdata module root makes the imports resolve exactly as intended and matches how this repository already structures other fixtures under pkg/crd/testdata.
I can add a short comment in the test explaining this (pkg/crd/testdata is a separate module; run controller-gen from there so package resolution uses that go.mod) if that helps readability.
If you prefer a different pattern that keeps cmd.Dir at repo root (e.g. setting GOMOD/-C), I’m happy to adjust, but I wasn’t able to make that work reliably with go/packages without executing inside the testdata module.
There was a problem hiding this comment.
I was just naively wondering what makes this test different from the ones in parser_integration_test.go
This PR adds a regression test for the scenario reported in #1063.
In controller-tools v0.16.x, CRD generation could panic when a root API type
contained a field defined via a type alias whose target type lived in a package
not directly imported by the root package.
The scenario no longer reproduces on main (and v0.20.1), likely fixed as a side
effect of #1122. This PR adds explicit regression coverage to ensure the behavior
remains supported.
The test runs controller-gen within the existing testdata module
(testdata.kubebuilder.io/cronjob) to exercise real package resolution and avoid
introducing additional test-only modules.