|
2 | 2 |
|
3 | 3 | ## Overview
|
4 | 4 |
|
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. |
6 | 6 |
|
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: |
9 | 8 |
|
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) |
13 | 13 |
|
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. |
16 | 15 |
|
17 | 16 | <aside class="note warning">
|
18 | 17 | <h1>Creates branches and deletes files</h1>
|
19 | 18 |
|
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. |
22 | 21 |
|
23 | 22 | </aside>
|
24 | 23 |
|
25 |
| -## When to Use It? |
| 24 | +## When to Use It |
26 | 25 |
|
27 |
| -Use this command when: |
| 26 | +Use this command when you: |
28 | 27 |
|
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) |
33 | 32 |
|
34 | 33 | ## How It Works
|
35 | 34 |
|
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). |
37 | 37 |
|
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** |
43 | 42 |
|
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. |
46 | 48 |
|
47 | 49 | ## How to Use It
|
48 | 50 |
|
49 |
| -Run the command from your project directory: |
| 51 | +Run from your project root: |
50 | 52 |
|
51 |
| -```sh |
| 53 | +```shell |
52 | 54 | kubebuilder alpha update
|
53 | 55 | ```
|
54 | 56 |
|
55 |
| -If needed, set a specific version or branch: |
| 57 | +Pin versions and base branch: |
56 | 58 |
|
57 |
| -```sh |
| 59 | +```shell |
58 | 60 | 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 |
62 | 64 | ```
|
| 65 | +Automation-friendly (proceed even with conflicts): |
63 | 66 |
|
64 |
| -Force update even with merge conflicts: |
65 |
| - |
66 |
| -```sh |
| 67 | +```shell |
67 | 68 | kubebuilder alpha update --force
|
68 | 69 | ```
|
69 | 70 |
|
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 |
| - |
98 | 71 | ## Merge Conflicts with `--force`
|
99 | 72 |
|
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 |
102 | 77 | <<<<<<< HEAD
|
103 | 78 | Your changes
|
104 | 79 | =======
|
105 | 80 | Incoming changes
|
106 |
| ->>>>>>> branch-name |
| 81 | +>>>>>>> tmp-original-… |
107 | 82 | ```
|
108 |
| -These conflicts will be committed in the |
109 |
| -`tmp-kb-update-merge` branch. |
110 | 83 |
|
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. |
113 | 86 |
|
114 | 87 | <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> |
117 | 90 |
|
118 |
| -```bash |
| 91 | +```shell |
119 | 92 | make manifests generate fmt vet lint-fix
|
120 |
| -``` |
121 |
| - |
122 |
| -Alternatively, you may want to run: |
123 |
| - |
124 |
| -```bash |
| 93 | +# or |
125 | 94 | make all
|
126 | 95 | ```
|
| 96 | + |
127 | 97 | </aside>
|
128 | 98 |
|
| 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. |
129 | 114 |
|
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. |
136 | 117 |
|
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. |
138 | 122 |
|
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> |
140 | 124 |
|
141 |
| -## Requirements |
| 125 | +## Demonstration |
142 | 126 |
|
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> |
146 | 128 |
|
147 | 129 | ## Further Resources
|
148 | 130 |
|
149 |
| -- [WIP: Design proposal for update automation](https://github.com/kubernetes-sigs/kubebuilder/pull/4302) |
| 131 | +- WIP: Design proposal for update automation — https://github.com/kubernetes-sigs/kubebuilder/pull/4302 |
150 | 132 |
|
151 | 133 | [project-config]: ../../reference/project-config.md
|
0 commit comments