Skip to content

Commit 6c93f85

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 6c93f85

File tree

13 files changed

+682
-119
lines changed

13 files changed

+682
-119
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/8c6f125c-b223-4dff-8c51-759e947abbb8" />
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/eb73341b-6bce-4a8b-ae5e-8aeb120da78d" />
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/9b7356e6-7287-4be7-866a-caa9d1e21a61" />
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: 71 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ You can reduce the burden of keeping your project up to date by using the
1717
automates the process of running `kubebuilder alpha update` on a schedule
1818
workflow when new Kubebuilder releases are available.
1919

20+
Moreover, you will be able to get help from AI models to understand what changes are needed to keep your project up to date
21+
and how to solve conflicts if any be faced.
22+
2023
</aside>
2124

2225
## When to Use It
@@ -27,6 +30,7 @@ Use this command when you:
2730
- Prefer automation over manual file editing
2831
- Want to review scaffold changes on a separate branch
2932
- Want to focus on resolving merge conflicts (not re-applying your custom code)
33+
- Want an **AI-generated** overview of changes and guidance for resolving conflicts
3034

3135
## How It Works
3236

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

6875
### Step 5: Cleanup
6976
- Once the output branch is ready, all the temporary working branches are deleted.
@@ -143,7 +150,56 @@ make manifests generate fmt vet lint-fix
143150
make all
144151
```
145152

146-
### Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
153+
## Using with GitHub Issues (`--open-gh-issue`) and AI (`--use-gh-models`) assistance
154+
155+
Pass `--open-gh-issue` to have the command create a GitHub **Issue** in your repository with:
156+
- a pre-filled checklist of follow-up steps, and
157+
- a compare link so you can open a PR and review the update.
158+
159+
If you also pass `--use-gh-models[=<model>]`, the tool posts a follow-up comment on that Issue with an AI-generated overview of the most important changes plus brief conflict-resolution guidance. When the flag is provided without a value, the default model is `openai/gpt-4o`. The AI comment uses simple, Kubebuilder-style wording and, when relevant, adds a short **Conflicts** section with commands to regenerate files. *(If the `gh models` command isn’t available, the Issue is still created; only the AI comment is skipped.)*
160+
161+
> **Tip:** You can run with `--dry-run` first to preview changes locally, then re-run with `--open-gh-issue` (and optionally `--use-gh-models`) when you’re ready to file the Issue.
162+
163+
### Examples
164+
165+
Create an Issue with a compare link:
166+
```shell
167+
kubebuilder alpha update --open-gh-issue
168+
```
169+
170+
Create an Issue **and** add an AI summary using the default model:
171+
```shell
172+
kubebuilder alpha update --open-gh-issue --use-gh-models
173+
```
174+
Choose a specific GitHub-hosted model:
175+
176+
```shell
177+
kubebuilder alpha update --open-gh-issue --use-gh-models=openai/gpt-4o
178+
```
179+
180+
### What you’ll see
181+
182+
When a new Kubebuilder release is available, the command opens an Issue that links to the diff so you can create the PR and review it, for example:
183+
184+
<img width="638" height="482" alt="Example Issue" src="https://github.com/user-attachments/assets/589fd16b-7709-4cd5-b169-fd53d69790d4" />
185+
186+
With `--use-gh-models`, an AI comment highlights key changes and suggests how to resolve any conflicts (e.g., which files to regenerate and which commands to run):
187+
188+
<img width="663" height="613" alt="AI Comment Example" src="https://github.com/user-attachments/assets/8c6f125c-b223-4dff-8c51-759e947abbb8" />
189+
190+
You’ll also get a concise list of changed files to streamline the review:
191+
192+
<img width="692" height="590" alt="AI files changed" src="https://github.com/user-attachments/assets/eb73341b-6bce-4a8b-ae5e-8aeb120da78d" />
193+
194+
If conflicts arise, AI-generated comments call them out and provide next steps:
195+
196+
<img width="691" height="311" alt="Conflict Example" src="https://github.com/user-attachments/assets/9b7356e6-7287-4be7-866a-caa9d1e21a61" />
197+
198+
### Automation
199+
200+
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.
201+
202+
## Changing Extra Git configs only during the run (does not change your ~/.gitconfig)_
147203

148204
By default, `kubebuilder alpha update` applies safe Git configs:
149205
`merge.renameLimit=999999`, `diff.renameLimit=999999`.
@@ -171,18 +227,20 @@ kubebuilder alpha update \
171227

172228
## Flags
173229

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. |
230+
| Flag | Description |
231+
|--------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
232+
| `--force` | Continue even if merge conflicts happen. Conflicted files are committed with conflict markers (CI/cron friendly). |
233+
| `--from-branch` | Git branch that holds your current project code. Defaults to `main`. |
234+
| `--from-version` | Kubebuilder release to update **from** (e.g., `v4.6.0`). If unset, read from the `PROJECT` file when possible. |
235+
| `--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`. |
236+
| `--open-gh-issue` | Create a GitHub issue with a pre-filled checklist and compare link after the update completes (requires `gh`). |
237+
| `--output-branch` | Name of the output branch. Default: `kubebuilder-update-from-<from-version>-to-<to-version>`. |
238+
| `--push` | Push the output branch to the `origin` remote after the update completes. |
239+
| `--restore-path` | Repeatable. Paths to preserve from the base branch when squashing (e.g., `.github/workflows`). **Not supported** with `--show-commits`. |
240+
| `--show-commits` | Keep full history (do not squash). **Not compatible** with `--restore-path`. |
241+
| `--to-version` | Kubebuilder release to update **to** (e.g., `v4.7.0`). If unset, defaults to the latest available release. |
242+
| `--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. |
243+
| `-h, --help` | Show help for this command. |
186244

187245
<aside class="note warning">
188246
<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)