kubernetes: main module (k8s.io/kubernetes) does not contain package k8s.io/kubernetes/hack/tools/ncpu

What happened?

I am not able to run tests through make rules if the repo isn’t located under $GOPATH/src/k8s.io.

❯ make test GOFLAGS="-v -failfast -count=1" KUBE_COVER="y" WHAT=./pkg/kubelet/kuberuntime
main module (k8s.io/kubernetes) does not contain package k8s.io/kubernetes/hack/tools/ncpu
!!! [0414 17:10:00] Call tree:
!!! [0414 17:10:00]  1: hack/make-rules/test.sh:24 kube::golang::setup_env(...)
make: *** [Makefile:184: test] Error

What did you expect to happen?

Run unit tests for pkg/kubelet/kuberuntime.

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

❯ pwd
/Users/thomasmilox/perso/kubernetes

❯ go version
go version go1.20.3 darwin/amd64

❯ make test GOFLAGS="-v -failfast -count=1" KUBE_COVER="y" WHAT=./pkg/kubelet/kuberuntime
main module (k8s.io/kubernetes) does not contain package k8s.io/kubernetes/hack/tools/ncpu
!!! [0414 17:10:00] Call tree:
!!! [0414 17:10:00]  1: hack/make-rules/test.sh:24 kube::golang::setup_env(...)
make: *** [Makefile:184: test] Error

Anything else we need to know?

To solve the issue I had to:

❯ go get k8s.io/kubernetes/hack/tools/ncpu

❯ cd `find $GOPATH -type d -name "ncpu"`

❯ go install .

https://github.com/kubernetes/kubernetes/blob/master/hack/lib/golang.sh#L561-L567

It seems to happen on my setup because of my fork not being located under $GOPATH/src/k8s.io.

Is this worth opening a PR to document it (in development guide for example) ? or we want to enforce people working under $GOPATH/src/k8s.io ?

Kubernetes version

Screenshot 2023-04-15 at 16 00 17

Cloud provider

NONE

OS version

❯ uname -a
Darwin Thomass-MBP 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64 x86_64 i386 Darwin

Install tools

NONE

Container runtime (CRI) and version (if applicable)

NONE

Related plugins (CNI, CSI, …) and versions (if applicable)

NONE

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

I was thinking to provide a solution for people not working under GOPATH then I thought GOPATH could be an heavy suggestion to avoid any other issues.

It is a heavy suggestion, my point is just that it has been developed in gopath for so long and many things still have GOPATH dependencies that I’d recommend that you still clone it under GOPATH, aside from this particular bug needing fixing.

You don’t need to install this ncpu tool system wide, the fix will be enabling these scripts to setup fake GOPATH properly, which we do in other scripts to enable working without a real GOPATH.