-
Notifications
You must be signed in to change notification settings - Fork 1.6k
✨ (alpha update command): add --force flag #4936
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -61,6 +61,12 @@ kubebuilder alpha update \ | |||
--from-branch=main | ||||
``` | ||||
|
||||
Force update even with merge conflicts: | ||||
|
||||
```sh | ||||
kubebuilder alpha update --force | ||||
``` | ||||
|
||||
<aside class="note warning"> | ||||
<h1>You might need to upgrade your project first</h1> | ||||
|
||||
|
@@ -81,17 +87,58 @@ Once updated, you can use `kubebuilder alpha update` for future upgrades. | |||
| `--from-version` | **Required for projects initialized with versions earlier than v4.6.0.** Kubebuilder version your project was created with. If unset, uses the `PROJECT` file. | | ||||
| `--to-version` | Version to upgrade to. Defaults to the latest version. | | ||||
| `--from-branch` | Git branch that contains your current project code. Defaults to `main`. | | ||||
| `--force` | Force the update even if conflicts occur. Conflicted files will include conflict markers, and a commit will be created automatically. Ideal for automation (e.g., cronjobs, CI). | | ||||
| `-h, --help` | Show help for this command. | | ||||
|
||||
<aside class="note warning"> | ||||
<h1>Projects generated with </h1> | ||||
|
||||
<aside class="note"> | ||||
Projects generated with **Kubebuilder v4.6.0** or later include the `cliVersion` field in the `PROJECT` file. | ||||
This field is used by `kubebuilder alpha update` to determine the correct CLI | ||||
version for upgrading your project. | ||||
</aside> | ||||
|
||||
## Merge Conflicts with `--force` | ||||
|
||||
When you use the `--force` flag with `kubebuilder alpha update`, Git will complete the merge even if there are conflicts. The resulting commit will include conflict markers like: | ||||
``` | ||||
<<<<<<< HEAD | ||||
Your changes | ||||
======= | ||||
Incoming changes | ||||
>>>>>>> branch-name | ||||
``` | ||||
These conflicts will be committed in the | ||||
`tmp-kb-update-merge` branch. | ||||
|
||||
<aside class="note warning"> | ||||
You must manually resolve these conflicts before merging into your main branch. | ||||
|
||||
```suggestion | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
The suggestion should not be added |
||||
<aside class="note warning"> | ||||
<H1>If you face conflicts (using or not the --force flag) </H1> | ||||
If the merge introduces conflicts, you must resolve them and **ensure** you execute the following command to regenerate the manifests and organise the files properly: | ||||
|
||||
```bash | ||||
make manifests generate fmt vet lint-fix | ||||
``` | ||||
|
||||
Alternatively, you may want to run: | ||||
|
||||
```bash | ||||
make all | ||||
``` | ||||
</aside> | ||||
|
||||
|
||||
## When to Use `--force` | ||||
Use `--force` only in scenarios like: | ||||
- Automated environments (e.g., CI pipelines or cron jobs) | ||||
- When you need to create a PR even if conflicts are present | ||||
- When a human will resolve the conflicts later | ||||
`kubebuilder alpha update --force` | ||||
|
||||
This ensures the update proceeds without manual blocking but shifts responsibility for conflict resolution to a follow-up manual step. | ||||
|
||||
This approach is typically used in automation workflows where conflict markers are later addressed by a human, or where preserving the conflicting changes is acceptable for follow-up processing. | ||||
|
||||
## Requirements | ||||
|
||||
- A valid [PROJECT][project-config] file at the root of your project | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,9 +50,8 @@ The process uses Git branches: | |
- upgrade: scaffold from the target version | ||
- merge: result of the 3-way merge | ||
|
||
If conflicts occur during the merge, resolve them manually in the 'merge' branch. | ||
Once resolved, commit and push it as a pull request. This branch will contain the | ||
final upgraded project with the latest Kubebuilder layout and your custom code. | ||
If conflicts occur during the merge, the command will stop and leave the merge branch for manual resolution. | ||
Use --force to commit conflicts with markers instead. | ||
|
||
Examples: | ||
# Update from the version specified in the PROJECT file to the latest release | ||
|
@@ -64,6 +63,9 @@ Examples: | |
# Update from a specific version to an specific release | ||
kubebuilder alpha update --from-version v4.5.0 --to-version v4.7.0 | ||
|
||
# Force update even with merge conflicts (commit conflict markers) | ||
kubebuilder alpha update --force | ||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
`, | ||
|
||
PreRunE: func(_ *cobra.Command, _ []string) error { | ||
|
@@ -93,5 +95,9 @@ Examples: | |
updateCmd.Flags().StringVar(&opts.FromBranch, "from-branch", "", | ||
"Git branch to use as current state of the project for the update.") | ||
|
||
updateCmd.Flags().BoolVar(&opts.Force, "force", false, | ||
"Force the update even if conflicts occur. Conflicted files will include conflict markers, and a "+ | ||
"commit will be created automatically. Ideal for automation (e.g., cronjobs, CI).") | ||
|
||
return updateCmd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, could we add the e2e tests as before? Therefore, from 4.5.2 to 4.6.0, we should not have conflicts, as from 4.5.0 or 4.4.0 to 4.6.0, we will likely encounter them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets do one thing |
||
} |
Uh oh!
There was an error while loading. Please reload this page.