Skip to content

Conversation

@camilamacedo86
Copy link
Member

@camilamacedo86 camilamacedo86 commented Oct 29, 2025

Fixes #5143

Problem

kubebuilder init would fail if the target directory contained common
development tool configuration files like:

  • .envrc (direnv)
  • mise.toml (mise)
  • .tool-versions (asdf)
  • go.mod (from running go mod init first)

This forced users to work around the validation by moving files out,
running init, then moving them back.

Solution

Only block initialization if key kubebuilder files already exist:

  • PROJECT (kubebuilder config file)
  • Makefile
  • cmd/main.go

All other files are allowed. Users get a warning if the directory isn't
empty, but scaffolding proceeds.

Result

Users can now initialize kubebuilder projects in directories with existing
tooling configs without errors.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Oct 29, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: camilamacedo86

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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 added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Oct 29, 2025
@camilamacedo86 camilamacedo86 force-pushed the fix-init branch 2 times, most recently from 982e9d3 to 6dcd44b Compare November 2, 2025 11:37
@camilamacedo86 camilamacedo86 changed the title WIP fix: allow any file less those that should be not (fix): (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files Nov 2, 2025
@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 Nov 2, 2025
@camilamacedo86 camilamacedo86 changed the title (fix): (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files 🐛 (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files Nov 2, 2025
@camilamacedo86 camilamacedo86 changed the title 🐛 (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files WIP: 🐛 (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files Nov 2, 2025
@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 Nov 2, 2025
@camilamacedo86 camilamacedo86 force-pushed the fix-init branch 3 times, most recently from 3449c98 to f7fede3 Compare November 2, 2025 11:55
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 2, 2025
@camilamacedo86 camilamacedo86 changed the title WIP: 🐛 (go/v4): Fixed: Init command incorrectly rejects directories with non-conflicting configuration files WIP: 🐛 (go/v4): (go/v4): Simplify init directory validation to only block PROJECT file Nov 2, 2025
@camilamacedo86 camilamacedo86 changed the title WIP: 🐛 (go/v4): (go/v4): Simplify init directory validation to only block PROJECT file 🐛 (go/v4): Simplify init directory validation to only block PROJECT file Nov 2, 2025
@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 Nov 2, 2025
@camilamacedo86 camilamacedo86 force-pushed the fix-init branch 2 times, most recently from e624b6d to decd337 Compare November 2, 2025 12:09
@robinlioret
Copy link

It looks a lot more permissive that what is in place at the moment. Will kubebuilder override existing files ?
I'm thinking about custom GitHub workflow files or git ignore or any common files.

I don't thinks it'll an issue for experienced people since we just have to look a the git diff and reset the files we want to keep as is. But it may be a good idea to add this hack to the documentation, what do you think ?

@camilamacedo86
Copy link
Member Author

/hold

We need think more about.
Maybe warning and make clear that the project has not a empty dir and files can be overwrite OR conflicts be faced

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 2, 2025
@robinlioret
Copy link

I have no idea what amount of work it could represent hut why not adding a step before generating the files ?

Something like:

  1. Queue files to generate in a list
  2. Check if one of them is going to be overwritten
  3. Display a warning with a interactive choice for the user

This way, we get rid of the need for hack documentation while keeping flexibility and automated maintenance of the kubebuilder "reserved" files.

@camilamacedo86 camilamacedo86 changed the title 🐛 (go/v4): Simplify init directory validation to only block PROJECT file 🐛 (go/v4): Simplify init directory validation to only block kubebuilder files Nov 12, 2025
@camilamacedo86
Copy link
Member Author

camilamacedo86 commented Nov 12, 2025

/hold cancel

@robinlioret

Thank you so much for your patience! 🙏
I've refined the validation logic to make it both more practical and easier to maintain.

The previous logic was both inverted and too strict—it didn’t reliably prevent actual conflicts and made maintenance difficult.
By focusing on the few critical files that kubebuilder generates, we:

  • Avoid false positives
  • Keep the logic clear and maintainable
  • Allow users more flexibility and trust them to manage their own workspace

Would love your thoughts on this updated approach! ✨

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 12, 2025
break
}
// Skip dot directories
if info.IsDir() && strings.HasPrefix(info.Name(), ".") {

Choose a reason for hiding this comment

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

Why remove warnings on dot directories?
As a user, I think I would like to be warn if my GitHub workflow was about to be overridden. Or am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thank you! 🙏 I tried to improve it, but just a heads-up — the warning might show up quite a bit, since .idea files (and others) can cause false positives. We have a ton of those.

Please let me know if you spot any important cases that we should actually handle.

Examples:

  • .github/workflows/ci.yml⚠️ warning shown
  • .git, .vscode, .idea → ✅ skipped (no warning)
  • Only .gitignore, go.mod, go.sum → ✅ ignored (no warning)

Choose a reason for hiding this comment

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

That's what I was missing ! I forgot that the code doesn't check only for kubebuilder files !

Copy link
Member Author

Choose a reason for hiding this comment

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

Hi @robinlioret

WDYT?

Could we win your LGTM now to get this one merged?

Copy link

@robinlioret robinlioret Nov 13, 2025

Choose a reason for hiding this comment

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

Well. I thinks we should keep the warnings for all the files including the dot files. I feel that skipping them may confuse users.

Imagine the following

  1. The user tries to initialize in a repo with a .GitHub dir
  2. They receive a set of warnings, they assumes that the list is complete.
  3. They accept the warning and get a replaced .github.

If the user doesn't check their git diff, they'll miss the change and could cause issues later on.

This makes sense because nowadays, dot files have very important roles.

Copy link
Member Author

@camilamacedo86 camilamacedo86 Nov 13, 2025

Choose a reason for hiding this comment

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

.github/workflows/ci.yml seems like the only place where this actually makes
sense. For the other directories, raising a warning doesn’t seem useful and
would just create noise. If we warn on everything, we end up training people
to ignore warnings entirely, which isn’t great practice. It’s better to only
warn when it’s meaningful.

Copy link

@robinlioret robinlioret Nov 13, 2025

Choose a reason for hiding this comment

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

You're right. The best option would be to add a preparation step that list the files about to be created by kubebuilder and check against this list. Maybe such a list could be statically created at build time?

For the time being, I don't know if it is worth the effort. So the solution in this PR could be a quick win. Let's merge!

return nil
}
// Track if any non-hidden files/directories exist
if !strings.HasPrefix(info.Name(), ".") {

Choose a reason for hiding this comment

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

Same here

@camilamacedo86 camilamacedo86 force-pushed the fix-init branch 2 times, most recently from 6e87652 to eac71b8 Compare November 12, 2025 18:33
@camilamacedo86 camilamacedo86 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2025
…d files

Allow existing config files; only block PROJECT, Makefile, cmd/main.go, and config/default/kustomization.yaml to prevent conflicts.
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2025
@k8s-ci-robot
Copy link
Contributor

New changes are detected. LGTM label has been removed.

@camilamacedo86 camilamacedo86 added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 13, 2025
@k8s-ci-robot k8s-ci-robot merged commit 3682ddd into kubernetes-sigs:master Nov 13, 2025
18 checks passed
@camilamacedo86 camilamacedo86 deleted the fix-init branch November 13, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants