Skip to content

🐛 fix(crd): panic when parsing type aliases from indirectly imported packages#1399

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-issue-import
Open

🐛 fix(crd): panic when parsing type aliases from indirectly imported packages#1399
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-issue-import

Conversation

@camilamacedo86
Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 commented Apr 27, 2026

Problem

controller-gen may be crashing when a type alias points to a package that is not directly imported.

Example

panic: runtime error: invalid memory address or nil pointer dereference
at Parser.NeedPackage

When this happens

  • Package A uses a type from package B
  • Package B defines it as an alias to a type in package C
  • Package A imports B, but not C
  • The real type lives in C

Result: generator cannot find the package and crashes

Solution

Make type resolution smarter.

  • Use Go type info to find where the type actually comes from
  • If not in direct imports, search through imported packages recursively
  • If still not found, return a clear error instead of crashing

Why this works

Before:

  • Only checked direct imports
  • Missing package caused a nil pointer → panic

Now:

  • Walks the full import graph
  • Correctly resolves types through aliases

Fixes #1063

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 27, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: camilamacedo86
Once this PR has been reviewed and has the lgtm label, please assign joelanford 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

@k8s-ci-robot k8s-ci-robot requested a review from vincepri April 27, 2026 11:55
@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. labels Apr 27, 2026
@camilamacedo86 camilamacedo86 changed the title WIP fix(crd): panic when parsing type aliases from indirectly imported packages 🐛 fix(crd): panic when parsing type aliases from indirectly imported packages Apr 27, 2026
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 27, 2026
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. 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.

Panic parsing resources not directly imported

2 participants