kubernetes / kubernetes

Production-Grade Container Scheduling and Management

Home Page:https://kubernetes.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Code-generator does not work outside of $GOPATH

ialidzhikov opened this issue · comments

What happened:
k8s.io/code-generator is not able to generate code for projects using Go modules (cloned outside $GOPATH).

What you expected to happen:
k8s.io/code-generator to be able to generate code for projects using Go modules (cloned outside $GOPATH).

How to reproduce it (as minimally and precisely as possible):

1. k8s.io/sample-apiserver located in $GOPATH

  1. Setup k8s.io/sample-apiserver in $GOPATH
$ mkdir -p $GOPATH/src/k8s.io/
$ cd $GOPATH/src/k8s.io/
$ git clone git@github.com:kubernetes/sample-apiserver.git
$ cd sample-apiserver
$ go mod vendor
  1. Remove the generated code
$ rm -rf pkg/generated/
$ git diff --shortstat
 38 files changed, 5407 deletions(-)
  1. And generate it once again
$ ./hack/update-codegen.sh
Generating deepcopy funcs
Generating clientset for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/clientset
Generating listers for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/listers
Generating informers for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/informers
go: directory ../code-generator/cmd/defaulter-gen outside available modules
go: directory ../code-generator/cmd/conversion-gen outside available modules
go: directory ../code-generator/cmd/client-gen outside available modules
go: directory ../code-generator/cmd/lister-gen outside available modules
go: directory ../code-generator/cmd/informer-gen outside available modules
go: directory ../code-generator/cmd/deepcopy-gen outside available modules
go: directory ../code-generator/cmd/openapi-gen outside available modules
  1. Ensure that the generation works
$ git diff --shortstat
 1 file changed, 6 insertions(+)

2. k8s.io/sample-apiserver located outside $GOPATH

  1. Setup k8s.io/sample-apiserver outside $GOPATH
$ cd $HOME/git/
$ git clone git@github.com:kubernetes/sample-apiserver.git
$ cd sample-apiserver
$ go mod vendor
  1. Remove the generated code
$ rm -rf pkg/generated/
$ git diff --shortstat
 38 files changed, 5407 deletions(-)
  1. And generate it once again
$ ./hack/update-codegen.sh
Generating deepcopy funcs
Generating clientset for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/clientset
Generating listers for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/listers
Generating informers for wardle:v1alpha1,v1beta1 at k8s.io/sample-apiserver/pkg/generated/informers
go: directory ../code-generator/cmd/defaulter-gen outside available modules
go: directory ../code-generator/cmd/conversion-gen outside available modules
go: directory ../code-generator/cmd/client-gen outside available modules
go: directory ../code-generator/cmd/lister-gen outside available modules
go: directory ../code-generator/cmd/informer-gen outside available modules
go: directory ../code-generator/cmd/deepcopy-gen outside available modules
go: directory ../code-generator/cmd/openapi-gen outside available modules
  1. Ensure that the generation generated nothing
$ git diff --shortstat
 39 files changed, 1 insertion(+), 5407 deletions(-)

Anything else we need to know?:

Environment:

  • Kubernetes version (use kubectl version):
  • Cloud provider or hardware configuration:
  • OS (e.g: cat /etc/os-release):
  • Kernel (e.g. uname -a):
  • Install tools:
  • Network plugin and version (if this is a network-related bug):
  • Others:

/area code-generation
/sig api-machinery

cc @nikhita

Potential fix in #85559

@fedebongio: GitHub didn't allow me to assign the following users: wlynch.

Note that only kubernetes members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

In response to this:

/assign @wlynch

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

/remove-lifecycle stale

/assign

I will take a look at it.

how about rewriting this even further to use go 1.18 generics?