Skip to content

Conversation

@robinlioret
Copy link

Motivation

I'm using mise-en-place to manage my tools versions. When I want to create a new kubebuilder project. I start by creating a mise.toml file with the versions of go and kubebuilder I want to use. Then run the kubebuilder init ... command. Since .toml files are allowed, I get the error

ERROR CLI run failed error=error executing command: failed to initialize project: unable to run pre-scaffold tasks of "base.go.kubebuilder.io/v4": error walking directory: target directory is not empty and contains a disallowed file "mise.toml". files with the following extensions [.go, .yaml, .mod, .sum] are not allowed to avoid conflicts with the tooling

I would like to be able to use mise tool stack, so we need to allow tools management files like mise-en-place and asdf.

Description of the change

Adding a simple check of the filename against an hardcoded list. It's the same principle as for the extension check but against the whole filename.

Prerequisites

  • make test-unit : FAILED, even on master I was not able to run the unit tests successfully
  • make install
  • make lint
  • make check-testdata
  • make test-e2e-local: FAILED, even on master I was not able to run the e2e tests successfully ( unlinkat /usr/bin/kustomize: permission denied, i didn't look further)
  • Manual test using the compiled binary (empty dir with mise.toml, then kubebuilder init, ok)

…it v4

Signed-off-by: Robin LIORET <robin.lioret.epro@gmail.com>
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 23, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @robinlioret!

It looks like this is your first PR to kubernetes-sigs/kubebuilder 🎉. 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/kubebuilder 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 size/S Denotes a PR that changes 10-29 lines, ignoring generated files. 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 Oct 23, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @robinlioret. Thanks for your PR.

I'm waiting for a github.com 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.

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 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 Oct 23, 2025
@robinlioret robinlioret changed the title ✨ add allowed files about tools version management files in go init v4 ✨ (golang/v4): Add allowed files about tools version management files in go init v4 Oct 23, 2025
allowedFiles := []string{
// User might use tool versions management tools to set up the environment including kubebuilder and go version
"mise.toml", // mise-en-place configuration file
".tool-versions", // asdf configuration file
Copy link
Member

Choose a reason for hiding this comment

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

Thank you so much for raising this one 🎉

Could we check why it’s being blocked instead?
It seems we shouldn’t block these since they’re not in disallowedExtensions.

If we start creating a full list like that, it could get huge —
so it might be better to only block the specific required cases.

What do you think? Could you please take a look? 🙂

Copy link
Author

Choose a reason for hiding this comment

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

You're welcome!

Actually, I think the variable disallowedExtensions is misnamed. It should be allowedExtensions since it is treated as a guard clause before returning the error.

I agree, init should block the files that are created by kubebuilder and leave the rest be. But, maybe there were a reason why this was implemented in the first place.

I'll dig into the repo to find out why andupdate this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you a lot !!!. Sure, the reason is:

We cannot initialize or scaffold files when the target directory already contains files that the tool itself is meant to scaffold. Doing so can lead to conflicts during the command execution — and, even worse, it may overwrite existing files with different content.

To avoid these issues, the initialization process must ensure that the directory is either empty or does not contain files that overlap with those that will be generated by the scaffolding tool.

Signed-off-by: Robin LIORET <robin.lioret.epro@gmail.com>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Oct 23, 2025
Signed-off-by: Robin LIORET <robin.lioret.epro@gmail.com>
Signed-off-by: Robin LIORET <robin.lioret.epro@gmail.com>
@robinlioret
Copy link
Author

robinlioret commented Oct 23, 2025

I reworked the function so it only checks for kubebuilder reserved files and directories.
Since my tests are failing when I run them locally. I tested it manually.

make install
mkdir testdata/project-v4-invalid-dir && cd testdata/project-v4-invalid-dir

touch .devcontainer Makefile mise.toml .tools-version go.mod
mkdir accepted && touch accepted/Makefile

kubebuilder init --domain=dummy.io --repo=github.com/dummy-io --license=apache2  --plugins go/v4
#>  target directory contains kubebuilder reserved directory or file: ".devcontainer" (.devcontainer, .github, api, bin, cmd, config, dist, hack, internal, test, .dockerignore, .gitignore, .golangci.yml, Dockerfile, Makefile, PROJECT, README.md, grafana)

rm .devcontainer
kubebuilder init --domain=dummy.io --repo=github.com/dummy-io --license=apache2  --plugins go/v4
#> target directory contains kubebuilder reserved directory or file: "Makefile" (...)

rm Makefile
kubebuilder init --domain=dummy.io --repo=github.com/dummy-io --license=apache2  --plugins go/v4
# No error

make generate
# It works

cd ..
rm -rf project-v4-invalid-dir

Signed-off-by: Robin LIORET <robin.lioret.epro@gmail.com>
@robinlioret robinlioret changed the title ✨ (golang/v4): Add allowed files about tools version management files in go init v4 ✨ (go/v4): Add allowed files about tools version management files in go init v4 Oct 23, 2025
".sum",

// Do not allow kubebuilder reserved directories or files
reservedNames := []string{
Copy link
Member

Choose a reason for hiding this comment

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

That is definitely an option.
I will need some time to think about it.

Copy link
Member

Choose a reason for hiding this comment

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

The main issue here is how to maintain this list.
Moreover: In a multi-repository project, there will typically be a .github directory — and that’s probably fine. However, the tool would need to scaffold files inside that directory, which raises the question of how to manage and keep the list consistent across repositories.

camilamacedo86
camilamacedo86 previously approved these changes Oct 24, 2025
".sum",

// Do not allow kubebuilder reserved directories or files
reservedNames := []string{
Copy link
Member

Choose a reason for hiding this comment

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

The main issue here is how to maintain this list.
Moreover: In a multi-repository project, there will typically be a .github directory — and that’s probably fine. However, the tool would need to scaffold files inside that directory, which raises the question of how to manage and keep the list consistent across repositories.

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2025
@camilamacedo86 camilamacedo86 dismissed their stale review October 24, 2025 11:26

I need time to evaluate not sure if that is the best approach

@camilamacedo86 camilamacedo86 removed the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

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

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

@robinlioret
Copy link
Author

I understand, I'm not experienced enough with more complex usage of Kubebuilder. This approch is the opposite of the previous one.

May be it is possible to dynamically build the list from the templates.

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