Skip to content

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

@win5923

Description

@win5923

Search before asking

  • I had searched in the issues and found no similar feature requirement.

Description

go list -m -f "{{.Dir}}" k8s.io/code-generator will get "" when go vendor is enabled.

$ ./hack/update-codegen.sh
 is missing. Running 'go mod download'.
>> Using 
./hack/update-codegen.sh: line 26: /kube_codegen.sh: No such file or directory

CODEGEN_PKG=$(go list -m -f "{{.Dir}}" k8s.io/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

I think it would be beneficial to support Go vendor users as well. For reference, sample-controller handles this by setting:

CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}

We could keep both approaches here to support both Go vendor and non-vendor setups.

https://github.com/kubernetes/sample-controller/blob/master/hack/update-codegen.sh

Use case

No response

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions