Skip to content

Conversation

ashishkpathak-connect
Copy link
Contributor

Fix Kubebuilder executable path not found for kubebuilder alpha generate command.

Fixes #4900

Fix Kubebuilder executable path not found for `kubebuilder alpha generate` command.
Copy link

linux-foundation-easycla bot commented Sep 5, 2025

CLA Signed

  • ✅login: ashishkpathak-connect / name: Ashish K Pathak / (816d650)

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot
Copy link
Contributor

Welcome @ashishkpathak-connect!

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 cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. 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. labels Sep 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @ashishkpathak-connect. 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.

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 Sep 5, 2025
@ashishkpathak-connect
Copy link
Contributor Author

Upon checking os.Executable() api, I found that it has a support for darwin too. Details at https://cs.opensource.google/go/go/+/refs/tags/go1.25.1:src/os/executable_darwin.go

So, I used os.Executable to ensure the binary "kubebuilder" which was invoked to call kubebuilder alpha generate is the one which calls kubebuilder init.

@k8s-ci-robot
Copy link
Contributor

@ashishkpathak-connect: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test all

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.

@ashishkpathak-connect
Copy link
Contributor Author

Upon checking os.Executable() api, I found that it has a support for darwin too. Details at https://cs.opensource.google/go/go/+/refs/tags/go1.25.1:src/os/executable_darwin.go

So, I used os.Executable to ensure the binary "kubebuilder" which was invoked to call kubebuilder alpha generate is the one which calls kubebuilder init.

Below Test shows kubebuilder executable was correctly invoked even though it didn't not exist in PATH.

bash-3.2$ which kubebuilder
bash-3.2$ echo $?
1
bash-3.2$ basename pwd
test4
bash-3.2$ ~/opensource2/kubebuilder/bin/kubebuilder alpha generate
WARN Using current working directory to re-scaffold the project
WARN This directory will be cleaned up and all files removed before the re-generation
INFO Cleaning directory dir=
INFO Running cleanup
INFO Running cleanup
INFO kubebuilder init
INFO Writing kustomize manifests for you to edit...
INFO Writing scaffold for you to edit...
INFO Get controller runtime
INFO Update dependencies

}

return realPath, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Will it work fine for Mac os as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes Camila. Below is a test from Mac os which shows it worked successfully:

bash-3.2$ sw_vers | head -n 2
ProductName:            macOS
ProductVersion:         15.6.1
bash-3.2$ basename `pwd`
test4
bash-3.2$ which kubebuilder
bash-3.2$ echo $?
1
bash-3.2$ ~/opensource2/kubebuilder/bin/kubebuilder alpha generate
WARN Using current working directory to re-scaffold the project 
WARN This directory will be cleaned up and all files removed before the re-generation 
INFO Cleaning directory dir=/tmp/test4
INFO Running cleanup 
INFO Running cleanup 
INFO kubebuilder init 
INFO Writing kustomize manifests for you to edit... 
INFO Writing scaffold for you to edit... 
INFO Get controller runtime 
INFO Update dependencies 
Next: define a resource with:
$ kubebuilder create api
INFO Grafana plugin not found, skipping migration 
INFO Auto Update plugin not found, skipping migration 
INFO Deploy-image plugin not found, skipping migration 
INFO Running make manifests 
mkdir -p /tmp/test4/bin
Downloading sigs.k8s.io/controller-tools/cmd/controller-gen@v0.19.0
/tmp/test4/bin/controller-gen rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
INFO Running make generate 
/tmp/test4/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
INFO Running make fmt 
go fmt ./...
INFO Running make vet 
go vet ./...
INFO Running make lint-fix 
Downloading github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
/tmp/test4/bin/golangci-lint run --fix
0 issues.
bash-3.2$ echo $?
0

@camilamacedo86
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 6, 2025
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

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

/lgtm
/ok-to-test

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 7, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ashishkpathak-connect, 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 the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 7, 2025
@camilamacedo86 camilamacedo86 changed the title 🐛 Fix Kubebuilder executable path for alpha generate. 🐛 (alpha generate command): Ensure kubebuilder reuses its own binary instead of relying on $PATH Sep 7, 2025
@k8s-ci-robot k8s-ci-robot merged commit 53ede7b into kubernetes-sigs:master Sep 7, 2025
18 checks passed
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kubebuilder alpha generate calls kubebuilder cmd from path instead of it's own
3 participants