-
Notifications
You must be signed in to change notification settings - Fork 689
Update the codegen script to be vendor-aware #4394
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Update the codegen script to be vendor-aware #4394
Conversation
|
Hi @win5923 |
|
@win5923 I fixed a ShellCheck lint issue in a previous PR and verified that all checks have passed. It was a bit of change, but I should’ve been more careful. 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I'm wondering if we need this level of complexity. Could we simplify this using Shell Parameter Expansion like:
CODEGEN_PKG=$(go list -m -f "{{.Dir}}" k8s.io/code-generator 2>/dev/null || true)
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
if [[ ! -d ${CODEGEN_PKG} ]]; then
echo "${CODEGEN_PKG} is missing. Running 'go mod download'."
go mod download
CODEGEN_PKG=$(go list -m -f "{{.Dir}}" k8s.io/code-generator)
fi
This way we don't need to explicitly detect vendor mode, the behavior is determined by the result, not by pre-checking the mode.
This comment was marked as resolved.
This comment was marked as resolved.
Doesn't I think we can just follow the official Kubernetes sample-controller pattern. |
|
You're right. I misinterpreted what was happening in my local env. Reviewing the logs, my local vendor/modules.txt was corrupted during testing, so go list failed and CODEGEN_PKG ended up empty. I’ll remove complex logic and update the script to follow the sample-controller pattern. |
10fbcea to
4e20649
Compare
|
@win5923 PTAL, thank you! |
win5923
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.

Why are these changes needed?
This PR is related to #4352
Currently, hack/update-codegen.sh relies solely on
go list -mto locatek8s.io/code-generator.This can break in vendor mode (
-mod=vendor), where module resolution may be restricted.This PR makes the script vendor-aware: when running in vendor mode it uses the vendored path (
./vendor/k8s.io/code-generator), and otherwise it resolves the path in module mode viago list -m.This ensures code generation works reliably in both module and vendor workflows.
Related issue number
Closes #4352
Checks