Skip to content

Commit 58a62a8

Browse files
chore(alpha update command): add option to use ai with gh models
Assisted-by: ChatGPT (OpenAI) Co-authored-by: Vitor Floriano <vitorfloriano@users.noreply.github.com>
1 parent f56402f commit 58a62a8

File tree

13 files changed

+680
-125
lines changed

13 files changed

+680
-125
lines changed

docs/book/src/getting-started.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,19 @@ The [Manager][manager] in the `cmd/main.go` file is responsible for managing the
408408
```
409409
</details>
410410
411+
### Use Kubebuilder plugins to scaffold additional options
412+
413+
Now that you have a better understanding of how to create your own API and controller,
414+
let’s scaffold in this project the plugin [`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin]
415+
so that your project can be kept up to date with the latest Kubebuilder releases scaffolding changes
416+
and consequently adopt improvements from the ecosystem.
417+
418+
```shell
419+
kubebuilder edit --plugins="autoupdate/v1-alpha"
420+
```
421+
422+
Inspect the file `.github/workflows/auto-update.yml` to see how it works.
423+
411424
### Checking the Project running in the cluster
412425
413426
At this point you can check the steps to validate the project
@@ -444,3 +457,4 @@ implemented for your controller.
444457
[deploy-image]: ./plugins/available/deploy-image-plugin-v1-alpha.md
445458
[GOPATH-golang-docs]: https://golang.org/doc/code.html#GOPATH
446459
[go-modules-blogpost]: https://blog.golang.org/using-go-modules
460+
[autoupdate-plugin]: ./plugins/available/autoupdate-v1-alpha.md
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Auto Update
2+
3+
# The 'kubebuilder alpha update 'command requires write access to the repository to create a branch
4+
# with the update files and allow you to open a pull request using the link provided in the issue.
5+
# The branch created will be named in the format kubebuilder-update-from-<from-version>-to-<to-version> by default.
6+
# To protect your codebase, please ensure that you have branch protection rules configured for your
7+
# main branches. This will guarantee that no one can bypass a review and push directly to a branch like 'main'.
8+
permissions:
9+
contents: write
10+
issues: write
11+
models: read
12+
13+
on:
14+
workflow_dispatch:
15+
schedule:
16+
- cron: "0 0 * * 2" # Every Tuesday at 00:00 UTC
17+
18+
jobs:
19+
auto-update:
20+
runs-on: ubuntu-latest
21+
env:
22+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23+
24+
# Step 1: Checkout the repository.
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v4
28+
with:
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
fetch-depth: 0
31+
32+
# Step 2: Configure Git to create commits with the GitHub Actions bot.
33+
- name: Configure Git
34+
run: |
35+
git config --global user.name "github-actions[bot]"
36+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
37+
38+
# Step 3: Set up Go environment.
39+
- name: Set up Go
40+
uses: actions/setup-go@v5
41+
with:
42+
go-version: stable
43+
44+
# Step 4: Install Kubebuilder.
45+
- name: Install Kubebuilder
46+
run: |
47+
curl -L -o kubebuilder "https://go.kubebuilder.io/dl/latest/$(go env GOOS)/$(go env GOARCH)"
48+
chmod +x kubebuilder
49+
sudo mv kubebuilder /usr/local/bin/
50+
kubebuilder version
51+
52+
# Step 5: Install Models extension for GitHub CLI
53+
- name: Install/upgrade gh-models extension
54+
run: |
55+
gh extension install github/gh-models --force
56+
gh models --help >/dev/null
57+
58+
# Step 6: Run the Kubebuilder alpha update command.
59+
# More info: https://kubebuilder.io/reference/commands/alpha_update
60+
- name: Run kubebuilder alpha update
61+
run: |
62+
# Executes the update command with specified flags.
63+
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
64+
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
65+
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
66+
# --open-gh-issue: Creates a GitHub Issue with a link for opening a PR for review.
67+
# --open-gh-models: Adds an AI-generated comment to the created Issue with
68+
# a short overview of the scaffold changes and conflict-resolution guidance (If Any).
69+
kubebuilder alpha update \
70+
--force \
71+
--push \
72+
--restore-path .github/workflows \
73+
--open-gh-issue \
74+
--use-gh-models

docs/book/src/getting-started/testdata/project/PROJECT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ domain: example.com
77
layout:
88
- go.kubebuilder.io/v4
99
plugins:
10+
autoupdate.kubebuilder.io/v1-alpha: {}
1011
helm.kubebuilder.io/v1-alpha: {}
1112
projectName: project
1213
repo: example.com/memcached

docs/book/src/plugins/available/autoupdate-v1-alpha.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ refresh your project scaffold, and wraps it in a GitHub Actions workflow that op
1111

1212
- When you don’t deviate too much from the default scaffold — ensure that you see the note about customization [here](https://book.kubebuilder.io/versions_compatibility_supportability#project-customizations).
1313
- When you want to reduce the burden of keeping the project updated and well-maintained.
14+
- When you want to guidance and help from AI to know what changes are needed to keep your project up to date
15+
as to solve conflicts.
1416

1517
## How to Use It
1618

17-
0 If you want to add the `autoupdate` plugin to your project:
19+
- If you want to add the `autoupdate` plugin to your project:
1820

1921
```shell
2022
kubebuilder edit --plugins="autoupdate.kubebuilder.io/v1-alpha"
@@ -28,12 +30,26 @@ kubebuilder init --plugins=go/v4,autoupdate/v1-alpha
2830

2931
## How It Works
3032

31-
This will scaffold and GitHub Actions workflow that runs the [kubebuilder alpha update][alpha-update-command] command.
32-
Then, whenever a new Kubebuilder release is available, it will open an Issue with a
33-
Pull Request compare link so you can create the PR and review it, such as:
33+
This will scaffold a GitHub Actions workflow that runs the [kubebuilder alpha update][alpha-update-command] command.
34+
Whenever a new Kubebuilder release is available, the workflow will automatically open an **Issue** with a Pull Request compare link so you can easily create the PR and review it, such as:
3435

3536
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
3637

38+
Moreover, AI models are used to help you understand what changes are needed to keep your project up to date,
39+
and to suggest resolutions if conflicts are encountered, as in the following example:
40+
41+
<img width="663" height="613" alt="AI Comment Example" src="https://github.com/user-attachments/assets/49562851-2936-4204-a11d-8205fcef9370" />
42+
43+
You will also see a list of files changed, making it easier to review the updates:
44+
45+
<img width="692" height="590" alt="AI files changed" src="https://github.com/user-attachments/assets/9518f1ba-3718-4e51-a1fb-0735b56aa0f9" />
46+
47+
If conflicts arise, AI-generated comments will guide you step by step through the resolution process:
48+
49+
<img width="691" height="311" alt="Conflict Example" src="https://github.com/user-attachments/assets/036663d2-dd69-4f99-a63d-c10a96458815" />
50+
51+
### Workflow details
52+
3753
The workflow will check once a week for new releases, and if there are any, it will create an Issue with a Pull Request compare link so you can create the PR and review it.
3854
The command called by the workflow is:
3955

@@ -45,12 +61,14 @@ The command called by the workflow is:
4561
# --force: Completes the merge even if conflicts occur, leaving conflict markers.
4662
# --push: Automatically pushes the resulting output branch to the 'origin' remote.
4763
# --restore-path: Preserves specified paths (e.g., CI workflow files) when squashing.
48-
# --open-gh-issue: Creates a GitHub issue with a link to the generated PR for review.
64+
# --open-gh-models: Adds an AI-generated comment to the created Issue with
65+
# a short overview of the scaffold changes and conflict-resolution guidance (If Any).
4966
kubebuilder alpha update \
5067
--force \
5168
--push \
5269
--restore-path .github/workflows \
53-
--open-gh-issue
70+
--open-gh-issue \
71+
--use-gh-models
5472
```
5573

5674
<aside class="warning">

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

Lines changed: 69 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ not re-applying your code.
99
By default, the final result is **squashed into a single commit** on a dedicated output branch.
1010
If you prefer to keep the full history (no squash), use `--show-commits`.
1111

12-
<aside class="note">
13-
<h1>Automate your Updates</h1>
14-
15-
You can reduce the burden of keeping your project up to date by using the
12+
> **Tip:** You can reduce the burden of keeping your project up to date by using the
1613
[`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin] plugin which
1714
automates the process of running `kubebuilder alpha update` on a schedule
1815
workflow when new Kubebuilder releases are available.
19-
20-
</aside>
16+
>
17+
> Moreover, you will be able to get help from AI models to understand what changes are needed to keep your project up to date
18+
and how to solve conflicts if any be faced.
2119

2220
## When to Use It
2321

@@ -27,6 +25,7 @@ Use this command when you:
2725
- Prefer automation over manual file editing
2826
- Want to review scaffold changes on a separate branch
2927
- Want to focus on resolving merge conflicts (not re-applying your custom code)
28+
- Want an **AI-generated** overview of changes and guidance for resolving conflicts
3029

3130
## How It Works
3231

@@ -64,6 +63,9 @@ The command creates three temporary branches:
6463
- `--output-branch`: pick a custom branch name.
6564
- `--push`: push the result to `origin` automatically.
6665
- `--git-config`: sets git configurations.
66+
- `--open-gh-issue`: create a GitHub issue with a checklist and compare link (requires `gh`).
67+
- `--use-gh-models[=<model>]`: add an AI overview **comment** to that issue using `gh models`
68+
(requires the `gh-models` extension). If used without a value, default
6769

6870
### Step 5: Cleanup
6971
- Once the output branch is ready, all the temporary working branches are deleted.
@@ -143,7 +145,53 @@ make manifests generate fmt vet lint-fix
143145
make all
144146
```
145147

146-
### Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
148+
## Using with GitHub Issues (`--open-gh-issue`) and AI (`--use-gh-models`) assistance
149+
150+
Pass `--open-gh-issue` to have the command create a GitHub **Issue** in your repository
151+
to assist with the update. Also, if you also pass `--use-gh-models`, the tool posts a follow-up comment
152+
on that Issue with an AI-generated overview of the most important changes plus brief conflict-resolution
153+
guidance.
154+
155+
### Examples
156+
157+
Create an Issue with a compare link:
158+
```shell
159+
kubebuilder alpha update --open-gh-issue
160+
```
161+
162+
Create an Issue **and** add an AI summary using the default model:
163+
```shell
164+
kubebuilder alpha update --open-gh-issue --use-gh-models
165+
```
166+
Choose a specific GitHub-hosted model:
167+
168+
```shell
169+
kubebuilder alpha update --open-gh-issue --use-gh-models=openai/gpt-4o
170+
```
171+
172+
### What you’ll see
173+
174+
The command opens an Issue that links to the diff so you can create the PR and review it, for example:
175+
176+
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
177+
178+
With `--use-gh-models`, an AI comment highlights key changes and suggests how to resolve any conflicts:
179+
180+
<img width="663" height="613" alt="AI Comment Example" src="https://github.com/user-attachments/assets/49562851-2936-4204-a11d-8205fcef9370" />
181+
182+
You’ll also get a concise list of changed files to streamline the review:
183+
184+
<img width="692" height="590" alt="AI files changed" src="https://github.com/user-attachments/assets/9518f1ba-3718-4e51-a1fb-0735b56aa0f9" />
185+
186+
If conflicts arise, AI-generated comments call them out and provide next steps:
187+
188+
<img width="691" height="311" alt="Conflict Example" src="https://github.com/user-attachments/assets/036663d2-dd69-4f99-a63d-c10a96458815" />
189+
190+
### Automation
191+
192+
This integrates cleanly with automation. The [`autoupdate.kubebuilder.io/v1-alpha`][autoupdate-plugin] plugin can scaffold a GitHub Actions workflow that runs the command on a schedule (e.g., weekly). When a new Kubebuilder release is available, it opens an Issue with a compare link so you can create the PR and review it.
193+
194+
## Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
147195

148196
By default, `kubebuilder alpha update` applies safe Git configs:
149197
`merge.renameLimit=999999`, `diff.renameLimit=999999`.
@@ -171,18 +219,20 @@ kubebuilder alpha update \
171219

172220
## Flags
173221

174-
| Flag | Description |
175-
|--------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
176-
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
177-
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
178-
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
179-
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
180-
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--preserve-path`. |
181-
| `--restore-path` | Repeatable. Paths to preserve from the base branch (repeatable). Not supported with --show-commits. (e.g., `.github/workflows`). |
182-
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
183-
| `--push` | Push the output branch to the `origin` remote after the update completes. |
184-
| `--git-config` | Repeatable. Pass per-invocation Git config as `-c key=value`. **Default** (if omitted): `-c merge.renameLimit=999999 -c diff.renameLimit=999999`. Your configs are applied on top. To disable defaults, include `--git-config disable` |
185-
| `-h, --help` | Show help for this command. |
222+
| Flag | Description |
223+
|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
224+
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
225+
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
226+
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
227+
| `--git-config` | Repeatable. Pass per-invocation Git config as `-c key=value`. **Default** (if omitted): `-c merge.renameLimit=999999 -c diff.renameLimit=999999`. Your configs are applied on top. To disable defaults, include `--git-config disable`. |
228+
| `--open-gh-issue` | Create a GitHub issue with a pre-filled checklist and compare link after the update completes (requires `gh`). |
229+
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
230+
| `--push` | Push the output branch to the `origin` remote after the update completes. |
231+
| `--restore-path` | Repeatable. Paths to preserve from the base branch when squashing (e.g., `.github/workflows`). **Not supported** with `--show-commits`. |
232+
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--restore-path`. |
233+
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
234+
| `--use-gh-models` | Post an AI overview as an issue comment using `gh models`. Provide a model name; if the flag is used without a value it defaults to `openai/gpt-4o`. Requires `gh` + `gh-models` extension. Effective only when `--open-gh-issue` is also set. |
235+
| `-h, --help` | Show help for this command. |
186236

187237
<aside class="note warning">
188238
<h1>You might need to upgrade your project first</h1>

hack/docs/internal/getting-started/generate_getting_started.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ func (sp *Sample) GenerateSampleProject() {
219219
"--resource", "--controller",
220220
)
221221
hackutils.CheckError("Creating the API", err)
222+
223+
slog.Info("Adding AutoUpdate Plugin")
224+
err = sp.ctx.Edit(
225+
"--plugins", "autoupdate/v1-alpha",
226+
)
227+
hackutils.CheckError("Initializing the getting started project", err)
222228
}
223229

224230
// CodeGen will call targets to generate code

0 commit comments

Comments
 (0)