-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
✨ Ensure 'kubebuilder alpha generate' rescaffolds with outdated plugins #4572
base: master
Are you sure you want to change the base?
Conversation
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sarthaksarthak9 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 |
Hi @sarthaksarthak9. 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 Once the patch is verified, the new status will be reflected by the 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. |
|
||
for i, plugin := range plugins { | ||
if plugin == "go.kubebuilder.io/v3" { | ||
plugins[i] = "go.kubebuilder.io/v4" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we add a break here?
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's a possibility that "go.kubebuilder.io/v3" appears multiple times in plugins, then we should not add a break, as we need to update all occurrences.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it can appears just once.
We can either check the layout, see: https://github.com/kubernetes-sigs/kubebuilder/blob/master/testdata/project-v4/PROJECT#L7
log.Warnf("Detected 'go.kubebuilder.io/v3' in PROJECT file.") | ||
log.Warnf("Kubebuilder v4 no longer supports this. It will be replaced with 'go.kubebuilder.io/v4'.") | ||
|
||
fmt.Print("Do you want to proceed? (y/N): ") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is very cool 🥇 🚀
When we scaffold the controllers/API (kubebuilder create API) we asked if we should scaffold both controller + API. So, we have some code utils for that already, Could we try to use those? See:
- https://github.com/kubernetes-sigs/kubebuilder/blob/master/pkg/plugin/util/stdin.go#L28-L40
kubebuilder/pkg/plugins/golang/v4/api.go
Lines 130 to 139 in 74ef8af
reader := bufio.NewReader(os.Stdin) if !p.resourceFlag.Changed { log.Println("Create Resource [y/n]") p.options.DoAPI = util.YesNo(reader) } if !p.controllerFlag.Changed { log.Println("Create Controller [y/n]") p.options.DoController = util.YesNo(reader) }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, to allow us to test out this option with scripts, could we create a flag so that we do not need to ask if the flag is set? --allow-best-effort OR we can use --force true OR any other term if you have a better idea/suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great job 🥇 🎉
I added some comments, and I think we need to add a test for this case.
Otherwise, it is all amazing !!!
if c.cmd.CalledAs() == "alpha generate" { | ||
err := updateProjectFileForAlphaGenerate() | ||
if err != nil { | ||
return fmt.Errorf("failed to update PROJECT file: %w", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have tests here: https://github.com/kubernetes-sigs/kubebuilder/tree/master/test/e2e/alphagenerate
We can create a new project and add 1 API
Then, update the PROJECT file to replace go.kubebuilder.io/v4
with go.kubebuilder.io/v2 or go.kubebuilder.io/v3 and then call the command with the flag that --force OR allow upgrade the PROJECT file without the need to say Y so we can ensure that works fine.
WDYT?
@camilamacedo86 I noticed that updating the plugin list in getInitArgs() automatically updates the PROJECT file, even though I don’t explicitly see a save function. How is this happening? Could you help me confirm where the file update is triggered?. Also, is there still a need for updateProjectFileForAlphaGenerate() in this case? |
|
||
// No need to update if v3 is not found | ||
if !strings.Contains(projectStr, "go.kubebuilder.io/v3") { | ||
return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need fix the lint issues.
You can run locally make fix-lint
Fixes: #4433