Skip to content

Commit 4155789

Browse files
📖 (doc): Update, improve and fix alpha update documentation (#5003)
(doc): Update, improve and fix alpha update documentation
1 parent fdd4b05 commit 4155789

File tree

1 file changed

+72
-90
lines changed

1 file changed

+72
-90
lines changed

docs/book/src/reference/commands/alpha_update.md

Lines changed: 72 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -2,150 +2,132 @@
22

33
## Overview
44

5-
The `kubebuilder alpha update` command helps you upgrade your project scaffold to a newer Kubebuilder version or plugin layout automatically.
5+
`kubebuilder alpha update` upgrades your project’s scaffold to a newer scaffold version.
66

7-
It uses a **3-way merge strategy** to update your project with less manual work.
8-
To achieve that, the command creates the following branches:
7+
It uses a **3-way merge** so you do less manual work. The command creates these branches:
98

10-
- *Ancestor branch*: clean scaffold using the old version
11-
- *Current branch*: your existing project with your custom code
12-
- *Upgrade branch*: scaffold generated using the new version
9+
- **Ancestor**: clean scaffold from the **old** version
10+
- **Original**: your current project (from your base branch)
11+
- **Upgrade**: clean scaffold from the **new** version
12+
- **Merge**: result of merging **Original** into **Upgrade** (this is where conflicts appear)
1313

14-
Then, it creates a **merge branch** that combines everything.
15-
You can review and test this branch before applying the changes.
14+
You can review and test the merge result before applying it to your main branch.
1615

1716
<aside class="note warning">
1817
<h1>Creates branches and deletes files</h1>
1918

20-
This command creates Git branches starting with `tmp-kb-update-` and deletes files during the process.
21-
Make sure to commit your work before running it.
19+
This command creates branches like `tmp-kb-update-*` and removes files during the process.
20+
Make sure your work is committed before you run it.
2221

2322
</aside>
2423

25-
## When to Use It?
24+
## When to Use It
2625

27-
Use this command when:
26+
Use this command when you:
2827

29-
- You want to upgrade your project to a newer Kubebuilder version or plugin layout
30-
- You prefer to automate the migration instead of updating files manually
31-
- You want to review scaffold changes in a separate Git branch
32-
- You want to focus only on fixing merge conflicts instead of re-applying all your code
28+
- Want to move to a newer Kubebuilder version or plugin layout
29+
- Prefer automation over manual file editing
30+
- Want to review scaffold changes on a separate branch
31+
- Want to focus on resolving merge conflicts (not re-applying your custom code)
3332

3433
## How It Works
3534

36-
The command performs the following steps:
35+
1. **Detect versions**
36+
Reads `--from-version` (or the `PROJECT` file) and `--to-version` (or uses the latest).
3737

38-
1. Downloads the older CLI version (from the `PROJECT` file or `--from-version`)
39-
2. Creates `tmp-kb-update-ancestor` with a clean scaffold using that version
40-
3. Creates `tmp-kb-update-current` and restores your current code on top
41-
4. Creates `tmp-kb-update-upgrade` using the latest scaffold
42-
5. Created `tmp-kb-update-merge` which is a merge of the above branches using the 3-way merge strategy
38+
2. **Create branches & re-scaffold**
39+
- `tmp-ancestor-*`: clean scaffold from **from-version**
40+
- `tmp-original-*`: snapshot of your **from-branch** (e.g., `main`)
41+
- `tmp-upgrade-*`: clean scaffold from **to-version**
4342

44-
You can push the `tmp-kb-update-merge` branch to your remote repository,
45-
review the diff, and test the changes before merging into your main branch.
43+
3. **3-way merge**
44+
Creates `tmp-merge-*` from **Upgrade** and merges **Original** into it.
45+
Runs `make manifests generate fmt vet lint-fix` to normalise outputs.
46+
47+
Push either `tmp-merge-*` (no squash) to open a PR.
4648

4749
## How to Use It
4850

49-
Run the command from your project directory:
51+
Run from your project root:
5052

51-
```sh
53+
```shell
5254
kubebuilder alpha update
5355
```
5456

55-
If needed, set a specific version or branch:
57+
Pin versions and base branch:
5658

57-
```sh
59+
```shell
5860
kubebuilder alpha update \
59-
--from-version=v4.5.2 \
60-
--to-version=v4.6.0 \
61-
--from-branch=main
61+
--from-version v4.5.2 \
62+
--to-version v4.6.0 \
63+
--from-branch main
6264
```
65+
Automation-friendly (proceed even with conflicts):
6366

64-
Force update even with merge conflicts:
65-
66-
```sh
67+
```shell
6768
kubebuilder alpha update --force
6869
```
6970

70-
<aside class="note warning">
71-
<h1>You might need to upgrade your project first</h1>
72-
73-
This command uses `kubebuilder alpha generate` internally.
74-
As a result, the version of the CLI originally used to create your project must support `alpha generate`.
75-
76-
This command has only been tested with projects created using **v4.5.0** or later.
77-
It might not work with projects that were initially created using a Kubebuilder version older than **v4.5.0**.
78-
79-
If your project was created with an older version, run `kubebuilder alpha generate` first to re-scaffold it.
80-
Once updated, you can use `kubebuilder alpha update` for future upgrades.
81-
</aside>
82-
83-
## Flags
84-
85-
| Flag | Description |
86-
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
87-
| `--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. |
88-
| `--to-version` | Version to upgrade to. Defaults to the latest version. |
89-
| `--from-branch` | Git branch that contains your current project code. Defaults to `main`. |
90-
| `--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). |
91-
| `-h, --help` | Show help for this command. |
92-
<aside class="note">
93-
Projects generated with **Kubebuilder v4.6.0** or later include the `cliVersion` field in the `PROJECT` file.
94-
This field is used by `kubebuilder alpha update` to determine the correct CLI
95-
version for upgrading your project.
96-
</aside>
97-
9871
## Merge Conflicts with `--force`
9972

100-
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:
101-
```
73+
When you use `--force`, Git finishes the merge even if there are conflicts.
74+
The commit will include markers like:
75+
76+
```shell
10277
<<<<<<< HEAD
10378
Your changes
10479
=======
10580
Incoming changes
106-
>>>>>>> branch-name
81+
>>>>>>> tmp-original-…
10782
```
108-
These conflicts will be committed in the
109-
`tmp-kb-update-merge` branch.
11083

111-
<aside class="note warning">
112-
You must manually resolve these conflicts before merging into your main branch.
84+
- **Without `--force`**: the command stops on `tmp-merge-*` and prints guidance; no commit is created.
85+
- **With `--force`**: the merge is committed (on `tmp-merge-*`) and contains the markers.
11386

11487
<aside class="note warning">
115-
<H1>If you face conflicts (using or not the --force flag) </H1>
116-
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:
88+
You must resolve these conflicts before merging into `main` (or your base branch).
89+
<strong>After resolving conflicts, always run:</strong>
11790

118-
```bash
91+
```shell
11992
make manifests generate fmt vet lint-fix
120-
```
121-
122-
Alternatively, you may want to run:
123-
124-
```bash
93+
# or
12594
make all
12695
```
96+
12797
</aside>
12898

99+
## Flags
100+
101+
| Flag | Description |
102+
|-------------------|--------------------------------------------------------------------------------------------------------------------|
103+
| `--from-version` | Kubebuilder version your project was created with. If unset, taken from the `PROJECT` file. |
104+
| `--to-version` | Version to upgrade to. Defaults to the latest release. |
105+
| `--from-branch` | Git branch that has your current project code. Defaults to `main`. |
106+
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (useful for CI/cron). |
107+
| `-h, --help` | Show help for this command. |
108+
109+
<aside class="note">
110+
<h1>CLI Version Tracking</h1>
111+
112+
Projects created with **Kubebuilder v4.6.0+** include `cliVersion` in the `PROJECT` file.
113+
We use that value to pick the correct CLI for re-scaffolding.
129114

130-
## When to Use `--force`
131-
Use `--force` only in scenarios like:
132-
- Automated environments (e.g., CI pipelines or cron jobs)
133-
- When you need to create a PR even if conflicts are present
134-
- When a human will resolve the conflicts later
135-
`kubebuilder alpha update --force`
115+
If your project was created with an older version,
116+
you can set `--from-version` to the version you used.
136117

137-
This ensures the update proceeds without manual blocking but shifts responsibility for conflict resolution to a follow-up manual step.
118+
However, this command uses `kubebuilder alpha generate` under the hood.
119+
We tested projects created with <strong>v4.5.0+</strong>.
120+
If yours is older, first run `kubebuilder alpha generate` once to modernize the scaffold.
121+
After that, you can use `kubebuilder alpha update` for future upgrades.
138122

139-
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.
123+
</aside>
140124

141-
## Requirements
125+
## Demonstration
142126

143-
- A valid [PROJECT][project-config] file at the root of your project
144-
- A clean Git working directory (no uncommitted changes)
145-
- Git must be installed and available
127+
<iframe width="560" height="315" src="https://www.youtube.com/embed/J8zonID__8k?si=WC-FXOHX0mCjph71" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
146128

147129
## Further Resources
148130

149-
- [WIP: Design proposal for update automation](https://github.com/kubernetes-sigs/kubebuilder/pull/4302)
131+
- WIP: Design proposal for update automationhttps://github.com/kubernetes-sigs/kubebuilder/pull/4302
150132

151133
[project-config]: ../../reference/project-config.md

0 commit comments

Comments
 (0)