Repository navigation
ci(api): add codegen drift check - #2463
Conversation
Run root 'make generate' as a pre-commit hook and as a dedicated CI workflow so missed codegen updates (CRDs, deepcopy, clients, RBAC) are caught instead of merging stale generated files. Pre-commit hook is scoped to files that actually affect codegen (api/, pkg/apis/, hack/update-codegen.sh, hack/boilerplate.go.txt) so unrelated commits are not slowed down. CI job sets up Go from go.mod, runs make generate, and fails on drift with a pointer to the local fix. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
The Options field was added to RestoreJobSpec without re-running 'make generate', leaving zz_generated.deepcopy.go out of sync. Regenerated to include the missing DeepCopyInto handling for the runtime.RawExtension pointer. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughAdds a GitHub Actions workflow and a pre-commit hook that run code generation and fail when generated artifacts drift; also updates generated deepcopy logic to deep-copy Changes
Sequence Diagram(s)sequenceDiagram
participant Dev as Developer (PR)
participant GH as GitHub Actions
participant Repo as Repository (checkout)
participant Go as Go toolchain
participant KG as k8s/code-generator (fetched)
participant Make as make generate
participant Git as git diff
Dev->>GH: Open PR touching codegen inputs
GH->>Repo: actions/checkout
GH->>Go: setup-go (version from go.mod)
GH->>KG: extract pinned version from hack/update-codegen.sh\nand run go get in temp module
GH->>Make: run make generate
Make->>Repo: write generated files
GH->>Git: git diff --exit-code
alt no diff
Git-->>GH: exit 0 (success)
else diff detected
Git-->>GH: exit non-zero (fail), print git status & git diff
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes robust mechanisms to maintain the consistency of generated API code within the repository. By integrating automated checks both locally via a pre-commit hook and in the continuous integration pipeline, it proactively identifies and prevents discrepancies in critical components like CRDs and DeepCopy implementations, thereby enhancing code reliability and developer workflow efficiency. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Ignored Files
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on Gemini (@gemini-code-assist) comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new pre-commit hook, run-make-generate-root, which automates the execution of 'make generate' at the repository root when changes occur in API definitions or codegen scripts. Feedback suggests expanding the file trigger regex to include the Makefile and generated output directories like pkg/generated/ and internal/crdinstall/manifests/ to ensure a more comprehensive drift check.
| git diff --color=always | cat | ||
| ' | ||
| language: system | ||
| files: ^(api/|pkg/apis/|hack/update-codegen\.sh$|hack/boilerplate\.go\.txt$) |
There was a problem hiding this comment.
The files filter should include the generated output directories and the Makefile to ensure that manual edits to generated files are caught and that changes to the build logic trigger a re-generation check. This ensures the drift check is comprehensive and prevents inconsistent manual changes from being committed.
Consider adding pkg/generated/, internal/crdinstall/manifests/, and Makefile to the regex.
files: ^(api/|pkg/apis/|pkg/generated/|internal/crdinstall/manifests/|hack/update-codegen\.sh$|hack/boilerplate\.go\.txt$|Makefile$)There was a problem hiding this comment.
Good call — extended the files: regex on the root hook to include the generated-output directories (pkg/generated/, internal/crdinstall/manifests/, and the four packages/system/*/definitions/ dirs) plus Makefile, so manual edits to generated artifacts or changes to the root generate target also re-run make generate through pre-commit. Commit: 9d552d4.
hack/update-codegen.sh sources kube_codegen.sh from the Go module cache at ~/go/pkg/mod/k8s.io/[email protected]/, but the module is not declared in go.mod so a fresh runner has nothing to source from. Add a workflow step that parses the pinned version out of the script and pulls the module into the cache before running make generate. Assisted-By: Claude <[email protected]> Signed-off-by: Myasnikov Daniil <[email protected]>
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
.pre-commit-config.yaml (1)
13-13: Consider running the local hook for generated-output paths too.Line 13 only matches generator inputs. Since
hack/update-codegen.shalso writes generated clients/OpenAPI/CRDs underpkg/generated,internal/crdinstall/manifests, andpackages/system/.../definitions, staged edits to those generated outputs can bypass the local drift check.Suggested path coverage expansion
- files: ^(api/|pkg/apis/|hack/update-codegen\.sh$|hack/boilerplate\.go\.txt$) + files: ^(api/|pkg/apis/|pkg/generated/|internal/crdinstall/manifests/|packages/system/(cozystack-controller/definitions/|application-definition-crd/definition/|backup-controller/definitions/|backupstrategy-controller/definitions/)|go\.mod$|go\.sum$|hack/update-codegen\.sh$|hack/boilerplate\.go\.txt$)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.pre-commit-config.yaml at line 13, Update the files pattern under the pre-commit hook so it also matches generated-output paths (not just generator inputs): modify the files entry (the regex currently `^(api/|pkg/apis/|hack/update-codegen\.sh$)`) to include the generated output directories created by hack/update-codegen.sh such as `pkg/generated`, `internal/crdinstall/manifests` and `packages/system/.*/definitions` (or equivalent glob/regex for those trees) so staged edits to generated clients/OpenAPI/CRDs cannot bypass the local drift check.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/workflows/codegen-drift.yml:
- Around line 36-42: The current check uses git diff --exit-code which misses
untracked generated files; replace that conditional in the "Fail on drift" step
so it fails when there are any modifications or untracked files (e.g., run git
status --porcelain --untracked-files=all and exit non-zero if it prints
anything, or use git diff --exit-code || git diff --no-index --quiet /dev/null
generated_files || git status --porcelain to detect untracked files). Locate the
existing conditional that calls git diff --exit-code and update it to run git
status --porcelain --untracked-files=all (or equivalent) and exit 1 when output
is non-empty so new generated CRD/client files cause the job to fail.
- Around line 6-13: The workflow's paths list in
.github/workflows/codegen-drift.yml misses generated output directories so PRs
that only change generated clients/CRDs/OpenAPI can skip the check; update the
paths section (the paths: block in that workflow) to include the generated
outputs such as pkg/generated/** and the config/ or output directories where
CRDs/OpenAPI/clients are emitted (for example config/crd/**, config/openapi/**,
pkg/generated/**) so that changes to generated artifacts trigger the workflow.
- Around line 27-34: The CI can fail on cold runners because
hack/update-codegen.sh sources kube_codegen.sh from the module cache before go
run can populate it; add a pre-generation step in the workflow (after
actions/setup-go@v5 and before the "Run make generate" step) that ensures the
k8s code-generator module is downloaded into the module cache (for example by
running a go install or go get for k8s.io/[email protected]), so
kube_codegen.sh is present when hack/update-codegen.sh sources it; reference the
actions/setup-go step, the "Run make generate" step, and hack/update-codegen.sh
/ kube_codegen.sh when adding this new download step.
---
Nitpick comments:
In @.pre-commit-config.yaml:
- Line 13: Update the files pattern under the pre-commit hook so it also matches
generated-output paths (not just generator inputs): modify the files entry (the
regex currently `^(api/|pkg/apis/|hack/update-codegen\.sh$)`) to include the
generated output directories created by hack/update-codegen.sh such as
`pkg/generated`, `internal/crdinstall/manifests` and
`packages/system/.*/definitions` (or equivalent glob/regex for those trees) so
staged edits to generated clients/OpenAPI/CRDs cannot bypass the local drift
check.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6d1a399e-9483-43ae-94bd-7d7d56dc3dac
📒 Files selected for processing (3)
.github/workflows/codegen-drift.yml.pre-commit-config.yamlapi/backups/v1alpha1/zz_generated.deepcopy.go
- Add generated-output dirs (pkg/generated, internal/crdinstall/manifests, packages/system/*/definitions) and Makefile to the workflow paths: filter so PRs that modify only generated artifacts still trigger the drift check. - Mirror the same paths in the root pre-commit hook's files: regex so manual edits to generated files or changes to the root generate target re-run make generate through pre-commit. - Switch drift detection in the workflow from `git diff --exit-code` to `git status --porcelain` so new untracked files produced by make generate (e.g. generated YAML/Go for a new API type) also fail the job; dump `git diff --color=always` on failure for easier debugging. Signed-off-by: Myasnikov Daniil <[email protected]>
What this PR does
make generateat the repo root to catch drift in generated API code (CRDs, DeepCopy, clients, RBAC) before it lands on main.api/,pkg/apis/,hack/update-codegen.sh,hack/boilerplate.go.txt) so unrelated commits are not slowed down..github/workflows/codegen-drift.yml) installs Go fromgo.mod, runsmake generate, and fails on drift with an error pointing contributors to the local fix.RestoreJobSpec.Options(added in feat(dashboard): add RestoreJob list, add page, and sidebar link #2437) had noDeepCopyIntohandling — regenerated.Release note
Summary by CodeRabbit