Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

自动更新(autoupdate/v1-alpha)

让你的 Kubebuilder 项目跟上最新改进不应成为负担。只需少量配置,即可在有新的 Kubebuilder 发布时收到自动 Pull Request建议——使项目保持可维护、安全,并与生态变化对齐。

该自动化使用 kubebuilder alpha update 命令,采用三方合并策略刷新项目脚手架,并将其封装在 GitHub Actions workflow 中:会打开一个带有 Pull Request 比较链接的 Issue,便于你创建 PR 并审查。

何时使用它

  • 当你希望减轻保持项目更新与良好维护的负担时。

如何使用它

  • 若要向项目添加 autoupdate 插件:
kubebuilder edit --plugins="autoupdate/v1-alpha"

它是如何工作的

该插件会脚手架生成一个 GitHub Actions workflow,每周检查新的 Kubebuilder 发布。有可用更新时,它会:

  1. 创建包含合并变更的新分支
  2. 打开带有 PR 对比链接的 GitHub Issue

示例问题:

Example Issue

冲突帮助(需要时):

Conflicts

自定义工作流

生成的 workflow 使用带默认标志的 kubebuilder alpha update 命令。你可以通过编辑 .github/workflows/auto_update.yml 添加额外标志来自定义 workflow:

使用的默认标志:

  • --force - Continue even if conflicts occur (automation-friendly)
  • --push - 自动将输出分支推送到远程
  • --restore-path .github/workflows - Preserve CI workflows from base branch
  • --open-gh-issue - 创建带有 PR 对比链接的 GitHub Issue

其他可用标志:

  • --merge-message - Custom commit message for clean merges
  • --conflict-message - Custom commit message when conflicts occur
  • --from-version - 指定要从哪个版本升级
  • --to-version - 指定要升级到的版本
  • --output-branch - Custom output branch name
  • --show-commits - Keep full history instead of squashing
  • --git-config - Pass per-invocation Git config

关于所有可用标志的完整文档,请参见 kubebuilder alpha update 参考。

示例:自定义提交信息

编辑 .github/workflows/auto_update.yml:

- name: 运行 kubebuilder alpha update
  run: |
    kubebuilder alpha update \
      --force \
      --push \
      --restore-path .github/workflows \
      --open-gh-issue \
      --merge-message "chore: update kubebuilder scaffold" \
      --conflict-message "chore: update with conflicts - review needed"

Demonstration