Skip to content

🐛 loader: keep the trailing ... of a filesystem root on Windows - #1485

Open
lusoris wants to merge 3 commits into
kubernetes-sigs:mainfrom
lusoris:fix-loader-windows-trailing-ellipsis
Open

lusoris wants to merge 3 commits into
kubernetes-sigs:mainfrom
lusoris:fix-loader-windows-trailing-ellipsis

Conversation

@lusoris

@lusoris lusoris commented Oct 9, 2026

Copy link
Copy Markdown

On Windows, a filesystem root ending in ... (paths=./x/...) loaded only the package in the root directory (#1484).

LoadRootsWithConfig made the root absolute with filepath.Abs while it still ended in .... On Windows, filepath.Abs resolves the path with GetFullPathNameW, which drops trailing dots, so x\... became x. The check filepath.Base(r) == "..." then failed, and go/packages was called with .\. instead of .\....

This change sets the trailing ... aside before the directory is made absolute and joins it back afterwards with filepath.Join, which only cleans the path lexically. Relative roots resolved against cfg.Dir and absolute roots are unchanged.

TestFilesystemRootKeepsTrailingEllipsisWhenAbsDropsTrailingDots stands in an Abs that drops the trailing element the way Windows does (through the unexported absPath variable), so the regression shows on non-Windows CI.

Before this change (Linux), the test fails:

LoadRoots(./testmod/...) loaded 1 packages [sigs.k8s.io/controller-tools/pkg/loader/testmod], want the 7 the test suite expects

After this change (Linux), go test ./pkg/loader/ passes, and golangci-lint run ./pkg/loader/ reports 0 issues.

On Windows (the official Go 1.27.2 windows/amd64 toolchain under Wine), the loader specs went from 8 Passed | 3 Failed to 11 Passed | 0 Failed; the three specs with filesystem roots ending in ... failed before. A Windows-built controller-gen now gives the same role.yaml for paths=./x/... as on Linux.

Fixes #1484

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Oct 9, 2026
@linux-foundation-easycla

linux-foundation-easycla Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

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

  • ✅ login: lusoris / name: lusoris (64ee60d)

@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @lusoris!

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. 😃

@kubernetes-prow kubernetes-prow Bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Oct 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @lusoris. 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.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 9, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lusoris
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

LoadRootsWithConfig made a relative filesystem root absolute with
filepath.Abs while it still ended in "...". On Windows, filepath.Abs
resolves the path with GetFullPathNameW, which drops trailing dots, so
`x\...` became `x`, the root was treated as a single directory and only
the package in x was loaded.

Set the "..." aside before making the directory absolute and join it
back afterwards. The test stands in an Abs that drops the trailing
element as Windows does, so the regression shows on every platform; the
existing loader specs with filesystem roots ending in "..." now also pass
on Windows.

Signed-off-by: lusoris <lusoris@proton.me>
@lusoris
lusoris force-pushed the fix-loader-windows-trailing-ellipsis branch from 2c4d09b to 64ee60d Compare October 9, 2026 15:53
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 9, 2026
@camilamacedo86

Copy link
Copy Markdown
Member

Hi @lusoris

Thank you for looking on that.

We do not really support Windows.
To support windows we would need to test against which is hard to achieve.

I would be OK with the proposed change if we can ensure that ALL is properly tested to ensure that no regressions or breaking changes are faced for the supported ones Linux/Mac SOs,

Move the cleaning and absolute-path step for a filesystem root into
absRoot, and test it directly:

- where filepath.Abs keeps a trailing "..." (Linux, macOS), absRoot
  returns what the loader computed before this change, for relative,
  absolute, nested and cfg.Dir-relative roots;
- where filepath.Abs drops trailing dots (Windows), a root ending in
  "..." keeps its nested traversal, with and without cfg.Dir.

Add loader specs for an absolute root ending in "..." and for cfg.Dir
with "./...".

Signed-off-by: lusoris <lusoris@proton.me>
@kubernetes-prow kubernetes-prow Bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 19, 2026
@lusoris

lusoris commented Oct 19, 2026

Copy link
Copy Markdown
Author

Thanks @camilamacedo86, that is a fair condition. I ran the whole test suite on Linux, macOS and Windows for this branch and for current main, so the two can be compared directly.

Both runs use the same throwaway workflow on my fork (not part of this PR): test.sh on ubuntu-latest and macos-latest, go test ./... on windows-latest.

Job main this PR
Linux, test.sh pass pass
macOS, test.sh fail fail
Windows, go test ./... fail fail
  • Linux passes on both.
  • macOS fails the same single test on both, TestAppyconfigurations in pkg/applyconfiguration/testdata/cronjob, so it does not come from this change.
  • Windows fails in eight packages on main and in six with this PR. The two that pass now are pkg/loader (the relative-root cases of TestLoader, which is what this PR fixes) and pkg/schemapatcher. The other six packages fail on both runs.

So no package that passes on main fails with this PR on Windows, and no test that passes on main fails with it on Linux or macOS.

The new tests in pkg/loader/abs_internal_test.go run on every platform. I also checked that they catch the bug: with the fix's trailing-... handling removed they fail on Linux, macOS and Windows (https://github.com/lusoris/controller-tools/actions/runs/39286653437), and with the fix they pass on all three (https://github.com/lusoris/controller-tools/actions/runs/39286638162).

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.

loader: on Windows a filesystem root ending in "..." loads only the root directory's package

2 participants