Skip to content

Conversation

@jinbum-kim
Copy link

@jinbum-kim jinbum-kim commented Jan 14, 2026

Why are these changes needed?

This PR is related to #4352

Currently, hack/update-codegen.sh relies solely on go list -m to locate k8s.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 via go list -m.

This ensures code generation works reliably in both module and vendor workflows.

Related issue number

Closes #4352

Checks

  • I've made sure the tests are passing.
  • Testing Strategy
    • Unit tests
    • Manual tests
    • This PR is not tested :(

@jinbum-kim
Copy link
Author

Hi @win5923
I updated the relative path to an absolute path—could you please take a look when you get a chance? Thanks!

@jinbum-kim
Copy link
Author

@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. 😅

Copy link
Member

@win5923 win5923 left a 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.

@jinbum-kim

This comment was marked as resolved.

@win5923
Copy link
Member

win5923 commented Jan 16, 2026

For example, if someone has a stale vendor/ directory but isn't using vendor mode

Doesn't CODEGEN_PKG=$(go list -m -f "{{.Dir}}" k8s.io/code-generator 2>/dev/null || true) cover that?

I think we can just follow the official Kubernetes sample-controller pattern.

@jinbum-kim
Copy link
Author

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.

@jinbum-kim jinbum-kim force-pushed the enhancement/codegen-vendor-fallback branch from 10fbcea to 4e20649 Compare January 16, 2026 19:16
@jinbum-kim
Copy link
Author

@win5923 PTAL, thank you!

Copy link
Member

@win5923 win5923 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I tested both vendor and non-vendor mode, thanks!
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][code-generator] update-codegen.sh fails when go vendor is enabled

2 participants