Skip to content

🐛 fix(controller-gen): correctly handle individual file paths (e.g.,paths=./apis/v1/types.go) instead of only accepting directories or recursive patterns.#1389

Open
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-path-loader
Open

🐛 fix(controller-gen): correctly handle individual file paths (e.g.,paths=./apis/v1/types.go) instead of only accepting directories or recursive patterns.#1389
camilamacedo86 wants to merge 1 commit into
kubernetes-sigs:mainfrom
camilamacedo86:fix-path-loader

Conversation

@camilamacedo86
Copy link
Copy Markdown
Member

@camilamacedo86 camilamacedo86 commented Apr 21, 2026

What was broken

The loader treated all filesystem paths as directories, causing errors when individual files were specified:

# This failed with "not a directory" error
controller-gen object paths=./apis/v1beta1/some_types.go
                                                                              
Error: load packages in root ".../some_types.go": err: fork/exec
/usr/local/go/bin/go: not a directory                                         

What this fixes

Added file detection logic to distinguish between files and directories. Now individual file paths work correctly:

  controller-gen object paths=./apis/v1beta1/some_types.go                      
  controller-gen object paths=./apis/v1          # still works                  
  controller-gen object paths=./apis/...         # still works    

PS: We are increasing the coverage as well to ensure that it works well with all scenarios.

Closes: #837

@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 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

@k8s-ci-robot k8s-ci-robot requested a review from chrischdi April 21, 2026 06:42
@k8s-ci-robot k8s-ci-robot added 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. labels Apr 21, 2026
@sbueringer
Copy link
Copy Markdown
Member

Please remove the controller-gen binary from this PR

…hs=./apis/v1/types.go) instead of only accepting directories or recursive patterns.
@camilamacedo86
Copy link
Copy Markdown
Member Author

Please remove the controller-gen binary from this PR

Good catcher. We need to add it to the .gitignore
I will do that in a follow-up.
Done, it can get merged now.

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.

controller-gen fails to handle individual file in paths

3 participants