Skip to content

kube_codegen.sh does not resolve "local" GOBIN when invoking the tools #132377

@bartoszmajsak

Description

@bartoszmajsak

What happened?

Required binaries are installed using go install, which relies on the predefined GOBIN. But when codegen tools are invoked in the script, the resolved gobin variable might not be pointing to the right location, as it's only resolving the environment variable ($GOBIN) or fall back to $GOPATH/bin explicitly, missing the value which might be set for go env GOBIN without exporting it.

What did you expect to happen?

The correct location is used, and so the binary is invoked (or the desired version of it).

How can we reproduce it (as minimally and precisely as possible)?

Fails with custom GOBIN

cd staging/src/k8s.io/code-generator
❯ go env -w GOBIN=$(mktemp -d)

❯ ls $(go env GOBIN)

❯ go env GOPATH
/home/bartek/go

❯ rm $(go env GOPATH)/bin/*

❯ bash -c '
source kube_codegen.sh
kube::codegen::gen_helpers examples/crd
'
Generating deepcopy code for 4 targets
kube_codegen.sh: line 142: /home/bartek/go/bin/deepcopy-gen: No such file or directory

❯ ls $(go env GOBIN)
 conversion-gen   deepcopy-gen   defaulter-gen

"works" when using fallback to $GOPATH/bin

❯ go env -w GOBIN=
❯ go env GOBIN

❯ rm $(go env GOPATH)/bin/*

❯ bash -c '
source kube_codegen.sh
kube::codegen::gen_helpers examples/crd
'
Generating deepcopy code for 4 targets
F0618 21:24:53.671523 1948721 main.go:107] Error: failed making a parser: error(s) in "k8s.io/code-generator/examples/crd/apis/conflicting/v1":
-: module k8s.io/code-generator@latest found (v0.0.0-00010101000000-000000000000, replaced by ./staging/src/k8s.io/code-generator), but does not contain package k8s.io/code-generator/examples/crd/apis/conflicting/v1
error(s) in "k8s.io/code-generator/examples/crd/apis/example/v1":
-: module k8s.io/code-generator@latest found (v0.0.0-00010101000000-000000000000, replaced by ./staging/src/k8s.io/code-generator), but does not contain package k8s.io/code-generator/examples/crd/apis/example/v1
error(s) in "k8s.io/code-generator/examples/crd/apis/example2/v1":
-: module k8s.io/code-generator@latest found (v0.0.0-00010101000000-000000000000, replaced by ./staging/src/k8s.io/code-generator), but does not contain package k8s.io/code-generator/examples/crd/apis/example2/v1
error(s) in "k8s.io/code-generator/examples/crd/apis/extensions/v1":
-: module k8s.io/code-generator@latest found (v0.0.0-00010101000000-000000000000, replaced by ./staging/src/k8s.io/code-generator), but does not contain package k8s.io/code-generator/examples/crd/apis/extensions/v1

❯ ls $(go env GOPATH)/bin
 conversion-gen   deepcopy-gen   defaulter-gen   validation-gen

Anything else we need to know?

No response

Kubernetes version

$ kubectl version
Client Version: v1.33.1
Kustomize Version: v5.6.0
Server Version: v1.33.1

OS version

# On Linux:
$ cat /etc/os-release
NAME="Fedora Linux"
VERSION="41 (Workstation Edition)"
RELEASE_TYPE=stable
ID=fedora
VERSION_ID=41
VERSION_CODENAME=""
PLATFORM_ID="platform:f41"
PRETTY_NAME="Fedora Linux 41 (Workstation Edition)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:41"
DEFAULT_HOSTNAME="fedora"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f41/"
SUPPORT_URL="https://ask.fedoraproject.org/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=41
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=41
SUPPORT_END=2025-12-15
VARIANT="Workstation Edition"
VARIANT_ID=workstation

$ uname -a
Linux hydropad 6.14.9-200.fc41.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 29 14:33:20 UTC 2025 x86_64 GNU/Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugCategorizes issue or PR as related to a bug.sig/api-machineryCategorizes an issue or PR as relevant to SIG API Machinery.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions