Skip to content

🐛 crd: add regression test for type alias deps not directly imported#1344

Open
meliezer wants to merge 1 commit intokubernetes-sigs:mainfrom
meliezer:issue-1063-regression-test
Open

🐛 crd: add regression test for type alias deps not directly imported#1344
meliezer wants to merge 1 commit intokubernetes-sigs:mainfrom
meliezer:issue-1063-regression-test

Conversation

@meliezer
Copy link

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.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: meliezer
Once this PR has been reviewed and has the lgtm label, please assign sbueringer for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Feb 16, 2026

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: meliezer / name: Menashe Eliezer (87cdff2)

@k8s-ci-robot
Copy link
Contributor

Welcome @meliezer!

It looks like this is your first PR to kubernetes-sigs/controller-tools 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/controller-tools has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 16, 2026
@k8s-ci-robot
Copy link
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 16, 2026
@@ -0,0 +1,91 @@
package crd_test
Copy link
Member

Choose a reason for hiding this comment

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

Sorry not sure I follow why this test cannot be added like all our other tests

Copy link
Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

I was just naively wondering what makes this test different from the ones in parser_integration_test.go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants