|
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 Kubebuilder version or plugin layout. |
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. |
| 15 | +Optionally, use **`--squash`** to put the merge result into **one commit** on a stable output branch (great for PRs). |
16 | 16 |
|
17 | 17 | <aside class="note warning">
|
18 | 18 | <h1>Creates branches and deletes files</h1>
|
19 | 19 |
|
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. |
| 20 | +This command creates branches like `tmp-kb-update-*` and removes files during the process. |
| 21 | +Make sure your work is committed before you run it. |
22 | 22 |
|
23 | 23 | </aside>
|
24 | 24 |
|
25 |
| -## When to Use It? |
| 25 | +## When to Use It |
26 | 26 |
|
27 |
| -Use this command when: |
| 27 | +Use this command when you: |
28 | 28 |
|
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 |
| 29 | +- Want to move to a newer Kubebuilder version or plugin layout |
| 30 | +- Prefer automation over manual file editing |
| 31 | +- Want to review scaffold changes on a separate branch |
| 32 | +- Want to focus on resolving merge conflicts (not re-applying your custom code) |
33 | 33 |
|
34 | 34 | ## How It Works
|
35 | 35 |
|
36 |
| -The command performs the following steps: |
| 36 | +1. **Detect versions** |
| 37 | + Reads `--from-version` (or the `PROJECT` file) and `--to-version` (or uses the latest). |
37 | 38 |
|
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 |
| 39 | +2. **Create branches & re-scaffold** |
| 40 | + - `tmp-ancestor-*`: clean scaffold from **from-version** |
| 41 | + - `tmp-original-*`: snapshot of your **from-branch** (e.g., `main`) |
| 42 | + - `tmp-upgrade-*`: clean scaffold from **to-version** |
43 | 43 |
|
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. |
| 44 | +3. **3-way merge** |
| 45 | + Creates `tmp-merge-*` from **Upgrade** and merges **Original** into it. |
| 46 | + Runs `make manifests generate fmt vet lint-fix` to normalize outputs. |
| 47 | + |
| 48 | +4. **(Optional) Squash** |
| 49 | + With `--squash`, copies the merge result to a stable output branch and commits **once**: |
| 50 | + - Default output branch: `kubebuilder-alpha-update-to-<to-version>` |
| 51 | + - Or set your own with `--output-branch` |
| 52 | + If there are conflicts, the single commit will include conflict markers. |
| 53 | + |
| 54 | +Push either `tmp-merge-*` (no squash) or the output branch (with `--squash`) to open a PR. |
46 | 55 |
|
47 | 56 | ## How to Use It
|
48 | 57 |
|
49 |
| -Run the command from your project directory: |
| 58 | +Run from your project root: |
50 | 59 |
|
51 |
| -```sh |
| 60 | +```shell |
52 | 61 | kubebuilder alpha update
|
53 | 62 | ```
|
54 | 63 |
|
55 |
| -If needed, set a specific version or branch: |
| 64 | +Pin versions and base branch: |
56 | 65 |
|
57 |
| -```sh |
| 66 | +```shell |
58 | 67 | kubebuilder alpha update \
|
59 |
| - --from-version=v4.5.2 \ |
60 |
| - --to-version=v4.6.0 \ |
61 |
| - --from-branch=main |
| 68 | + --from-version v4.5.2 \ |
| 69 | + --to-version v4.6.0 \ |
| 70 | + --from-branch main |
62 | 71 | ```
|
| 72 | +Automation-friendly (proceed even with conflicts): |
63 | 73 |
|
64 |
| -Force update even with merge conflicts: |
65 |
| - |
66 |
| -```sh |
| 74 | +```shell |
67 | 75 | kubebuilder alpha update --force
|
68 | 76 | ```
|
69 | 77 |
|
| 78 | +Create a **single squashed commit** on a stable PR branch: |
| 79 | + |
| 80 | +```shell |
| 81 | +kubebuilder alpha update --force --squash |
| 82 | +``` |
| 83 | + |
| 84 | +Squash while **preserving** paths from your base branch (keep CI/workflows, docs, etc.): |
| 85 | + |
| 86 | +```shell |
| 87 | +kubebuilder alpha update --force --squash \ |
| 88 | + --preserve-path .github/workflows \ |
| 89 | + --preserve-path docs |
| 90 | +``` |
| 91 | + |
| 92 | +Use a **custom output branch** name: |
| 93 | + |
| 94 | +```shell |
| 95 | +kubebuilder alpha update --force --squash \ |
| 96 | + -output-branch upgrade/kb-to-v4.7.0 |
| 97 | +``` |
| 98 | + |
| 99 | + |
| 100 | +### Commit message used in `--squash` mode |
| 101 | + |
| 102 | +> [kubebuilder-automated-update]: update scaffold from <from> to <to>; (squashed 3-way merge) |
| 103 | +
|
70 | 104 | <aside class="note warning">
|
71 | 105 | <h1>You might need to upgrade your project first</h1>
|
72 | 106 |
|
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`. |
| 107 | +This command uses `kubebuilder alpha generate` under the hood. |
| 108 | +We support projects created with <strong>v4.5.0+</strong>. |
| 109 | +If yours is older, first run `kubebuilder alpha generate` once to modernize the scaffold. |
| 110 | +After that, you can use `kubebuilder alpha update` for future upgrades. |
75 | 111 |
|
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 | 112 | </aside>
|
82 | 113 |
|
83 | 114 | ## Flags
|
84 | 115 |
|
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. | |
| 116 | +| Flag | Description | |
| 117 | +|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------| |
| 118 | +| `--from-version` | **Required for projects initialized before v4.6.0.** Kubebuilder version your project was created with. If unset, taken from the `PROJECT` file. | |
| 119 | +| `--to-version` | Version to upgrade to. Defaults to the latest release. | |
| 120 | +| `--from-branch` | Git branch that has your current project code. Defaults to `main`. | |
| 121 | +| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (useful for CI/cron). | |
| 122 | +| `--squash` | Write the merge result as **one commit** on a stable output branch. | |
| 123 | +| `--preserve-path` | Repeatable. With `--squash`, restore these paths from the base branch (e.g., `--preserve-path .github/workflows`). | |
| 124 | +| `--output-branch` | Branch name to use for the squashed commit (default: `kubebuilder-alpha-update-to-<to-version>`). | |
| 125 | +| `-h, --help` | Show help for this command. | |
| 126 | + |
92 | 127 | <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. |
| 128 | +<h1>CLI Version Tracking</h1> |
| 129 | + |
| 130 | +Projects created with **Kubebuilder v4.6.0+** include `cliVersion` in the `PROJECT` file. |
| 131 | +We use that value to pick the correct CLI for re-scaffolding. |
| 132 | + |
96 | 133 | </aside>
|
97 | 134 |
|
98 | 135 | ## Merge Conflicts with `--force`
|
99 | 136 |
|
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 |
| -``` |
| 137 | +When you use `--force`, Git finishes the merge even if there are conflicts. The commit will include markers like: |
| 138 | + |
| 139 | +```shell |
102 | 140 | <<<<<<< HEAD
|
103 | 141 | Your changes
|
104 | 142 | =======
|
105 | 143 | Incoming changes
|
106 |
| ->>>>>>> branch-name |
| 144 | +>>>>>>> tmp-original-… |
107 | 145 | ```
|
108 |
| -These conflicts will be committed in the |
109 |
| -`tmp-kb-update-merge` branch. |
110 | 146 |
|
111 |
| -<aside class="note warning"> |
112 |
| -You must manually resolve these conflicts before merging into your main branch. |
| 147 | +- **Without `--force`**: the command stops on `tmp-merge-*` and prints guidance; no commit is created. |
| 148 | +- **With `--force`**: the merge is committed (on `tmp-merge-*`, or on the output branch if using `--squash`) and contains the markers. |
113 | 149 |
|
114 | 150 | <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: |
| 151 | +You must resolve these conflicts before merging into `main` (or your base branch). |
| 152 | +<strong>After resolving conflicts, always run:</strong> |
117 | 153 |
|
118 |
| -```bash |
| 154 | +```shell |
119 | 155 | make manifests generate fmt vet lint-fix
|
120 |
| -``` |
121 |
| - |
122 |
| -Alternatively, you may want to run: |
123 |
| - |
124 |
| -```bash |
| 156 | +# or |
125 | 157 | make all
|
126 | 158 | ```
|
127 |
| -</aside> |
128 |
| - |
129 | 159 |
|
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` |
136 |
| - |
137 |
| -This ensures the update proceeds without manual blocking but shifts responsibility for conflict resolution to a follow-up manual step. |
138 |
| - |
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. |
| 160 | +</aside> |
140 | 161 |
|
141 |
| -## Requirements |
| 162 | +## Demonstration |
142 | 163 |
|
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 |
| 164 | +<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 | 165 |
|
147 | 166 | ## Further Resources
|
148 | 167 |
|
149 |
| -- [WIP: Design proposal for update automation](https://github.com/kubernetes-sigs/kubebuilder/pull/4302) |
| 168 | +- WIP: Design proposal for update automation — https://github.com/kubernetes-sigs/kubebuilder/pull/4302 |
150 | 169 |
|
151 | 170 | [project-config]: ../../reference/project-config.md
|
0 commit comments