Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Make kubebuilder go install-able #4481

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

migueleliasweb
Copy link

Closes #4079

This PR makes kubebuilder go installable.

Changes:

  • Renamed main package originally from cmd/ to cmd
  • Renamed main function previously inside cmd/cmg.go to Run - following Go Cobra's pattern
  • Created new main file at the root of the project
  • Renamed package on doc.go to main
  • Fixed building make build target
  • Fixed GoReleaser config

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 10, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @migueleliasweb!

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
Copy link
Contributor

Hi @migueleliasweb. 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 size/M Denotes a PR that changes 30-99 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jan 10, 2025
doc.go Outdated
@@ -18,4 +18,4 @@ limitations under the License.

// Package kubebuilder contains pkged files compiled into the
// go binaries.
package kubebuilder
package main
Copy link
Author

Choose a reason for hiding this comment

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

I couldn't find any references to this go:generate command anywhere. Also github.com/markbates/pkger/cmd/pkger is archived for a while.

Maybe this can be removed?

Copy link
Member

Choose a reason for hiding this comment

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

Can we make this change?
We will need to check it further.
Because I believe that is what generates : https://pkg.go.dev/sigs.k8s.io/kubebuilder/v4

So, can we change the name of the package?

Copy link
Author

Choose a reason for hiding this comment

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

I'm really not sure that is generates anything right now. The package itself is not mentioned in go.mod and the go generate command fails for me.

Looking at the repo for Pcker:

Screenshot from 2025-01-12 22-17-51

the code seems to be supposed to be a predecessor of go embed commands that are now part of the standard library.

Note that https://github.com/gobuffalo/packr is also archived in favour of go embed native.

Have a look at the commit fe73ff7b99 and it seems it was initially tied to a command inside the alpha subcommand kubebuilder alpha config-gen - this doesn't seem to be available now and I assume was renamed later to kubebuilder alpha generate?

Sadly, changing the name of the package of doc.go to kubebuilder again would prevent the existance of the new main.go as both files would have different package names.

If you really want to leave this file alone, there are still two alternatives that although much less nice, would mean we don't have to touch this file: #4079 (comment).

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if this file must be present at the root, if not, it could be moved somewhere else?

Copy link
Member

@camilamacedo86 camilamacedo86 Jan 12, 2025

Choose a reason for hiding this comment

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

Hi @migueleliasweb

I will need to have some time to check this one properly.

Copy link
Member

Choose a reason for hiding this comment

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

I created : #4504

if the docs are generated all fine, then we get it removed
if after we discover that it is used in some place and has a purpose, then we can quickly revert.
Thank you for highlighting that.

@migueleliasweb migueleliasweb changed the title (:bug:) Make kubebuilder go install-able 🐛 Make kubebuilder go install-able Jan 10, 2025
@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 Jan 12, 2025
@camilamacedo86
Copy link
Member

Hi @migueleliasweb

You can see that the changes made broke the e2e tests.
The [pull-kubebuilder-e2e-k8s-1-32-0](https://prow.k8s.io/view/gs/kubernetes-ci-logs/pr-logs/pull/kubernetes-sigs_kubebuilder/4481/pull-kubebuilder-e2e-k8s-1-32-0/1878418648549298176) you can ignore because it is a bug with prow and the 1.32 is not working yet.

But all other failures would be required be solved

@migueleliasweb
Copy link
Author

I'll have a look at the failing tests tomorrow 🫡

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: migueleliasweb, Scutua
Once this PR has been reviewed and has the lgtm label, please assign varshaprasad96 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

@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package main
package cmd
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems to version getting form the info.Main.Version should be adopted here like in the controller-tools project https://github.com/kubernetes-sigs/controller-tools/blob/main/pkg/version/version.go

Otherwise, the version printed after the go install ... will be always unknown.

Copy link
Author

@migueleliasweb migueleliasweb Jan 16, 2025

Choose a reason for hiding this comment

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

I'm not sure if Kubebuilder itself tracks the same version as controller runtime. That might be a change in behaviour. If one of the maintainers wants to make that change, it's fine for me. scratch that.

Copy link
Contributor

@dmvolod dmvolod Jan 16, 2025

Choose a reason for hiding this comment

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

It's already done with the LD_FLAG on the build release stage and should be aligned here. Otherwise, for some cases it will be useless task, as we need to identify version on update or maintenance steps...

Copy link
Member

Choose a reason for hiding this comment

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

@migueleliasweb can you please address this one ?

Copy link
Author

@migueleliasweb migueleliasweb Jan 17, 2025

Choose a reason for hiding this comment

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

I'm not sure I fully understand what needs to be done here. Using debug.ReadBuildInfo() might yield a change in behaviour compared to the current setup.

Would it be okay to address this in a separate PR? (I'm just trying to make this one specific for the go-installable feature for kubebuilder.

If we still want to move ahead, I'm happy to mimic the same logic as in https://github.com/kubernetes-sigs/controller-tools/blob/main/pkg/version/version.go.

Copy link
Author

@migueleliasweb migueleliasweb Jan 17, 2025

Choose a reason for hiding this comment

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

Is this what we're looking for?

If the kubeBuilderVersion is not set, fallback to info.Main.Version.

 // versionString returns the CLI version
 func versionString() string {
+       if kubeBuilderVersion == "" {
+               if info, ok := debug.ReadBuildInfo(); ok && info.Main.Version != "" {
+                       kubeBuilderVersion = info.Main.Version
+               }
+       }
+
        return fmt.Sprintf("Version: %#v", version{
                kubeBuilderVersion,
                kubernetesVendorVersion,

Copy link
Author

Choose a reason for hiding this comment

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

Pushed a change about this. Let me know if it looks good so I can squash everything before the merge. 🫡

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.

Hi @migueleliasweb

I think to get this one merged we just need:

a) address this comment https://github.com/kubernetes-sigs/kubebuilder/pull/4481/files#r1920699959.

b) can you please squash the commits? we have the policy of 1 commit per PR

c) we should get this one merged #4504 and then this one here rebased with so you will add the main.go in the root. If we need to revert for any reason that will be helpful, thank you a lot 🥇

Than you a lot for your help here.

cmd/version.go Outdated Show resolved Hide resolved
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jan 18, 2025

@migueleliasweb: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubebuilder-e2e-k8s-1-32-0 cb4d09d link true /test pull-kubebuilder-e2e-k8s-1-32-0

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

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. ok-to-test Indicates a non-member PR verified by an org member that 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.

Make Kubebuilder go install-able
5 participants