k8s-controller-core-resource icon indicating copy to clipboard operation
k8s-controller-core-resource copied to clipboard

Not able to run after cloning

Open swapanshridhar opened this issue 5 years ago • 5 comments

Reached here from your MEDIUM article : https://medium.com/@trstringer/create-kubernetes-controllers-for-core-and-custom-resources-62fc35ad64a3

Started following README instructions, but 'go run *.go' gives me dependencies error.

MacBook$ pwd /Users/xxx/testing_operators
MacBook$ git clone https://github.com/trstringer/k8s-controller-core-resource
MacBook$ cd k8s-controller-core-resource
MacBook$ ls
Gopkg.lock    Gopkg.toml    README.md     controller.go handler.go    main.go


MacBook$ go run *.go

controller.go:7:2: cannot find package "github.com/Sirupsen/logrus" in any of:
	/usr/local/opt/go/libexec/src/github.com/Sirupsen/logrus (from $GOROOT)
	/Users/xxx/go_space/src/github.com/Sirupsen/logrus (from $GOPATH)
handler.go:5:2: cannot find package "k8s.io/api/core/v1" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/api/core/v1 (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/api/core/v1 (from $GOPATH)
main.go:10:2: cannot find package "k8s.io/apimachinery/pkg/apis/meta/v1" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/apimachinery/pkg/apis/meta/v1 (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/apimachinery/pkg/apis/meta/v1 (from $GOPATH)
main.go:11:2: cannot find package "k8s.io/apimachinery/pkg/runtime" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/apimachinery/pkg/runtime (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/apimachinery/pkg/runtime (from $GOPATH)
controller.go:8:2: cannot find package "k8s.io/apimachinery/pkg/util/runtime" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/apimachinery/pkg/util/runtime (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/apimachinery/pkg/util/runtime (from $GOPATH)
controller.go:9:2: cannot find package "k8s.io/apimachinery/pkg/util/wait" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/apimachinery/pkg/util/wait (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/apimachinery/pkg/util/wait (from $GOPATH)
main.go:12:2: cannot find package "k8s.io/apimachinery/pkg/watch" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/apimachinery/pkg/watch (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/apimachinery/pkg/watch (from $GOPATH)
controller.go:10:2: cannot find package "k8s.io/client-go/kubernetes" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/client-go/kubernetes (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/client-go/kubernetes (from $GOPATH)
controller.go:11:2: cannot find package "k8s.io/client-go/tools/cache" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/client-go/tools/cache (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/client-go/tools/cache (from $GOPATH)
main.go:15:2: cannot find package "k8s.io/client-go/tools/clientcmd" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/client-go/tools/clientcmd (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/client-go/tools/clientcmd (from $GOPATH)
controller.go:12:2: cannot find package "k8s.io/client-go/util/workqueue" in any of:
	/usr/local/opt/go/libexec/src/k8s.io/client-go/util/workqueue (from $GOROOT)
	/Users/xxx/go_space/src/k8s.io/client-go/util/workqueue (from $GOPATH)

I am new to GO and k8s.

I have installed GO :

MacBook$ echo $GOPATH
/Users/xxx/go_space
MacBook$ echo $GOROOT
/usr/local/opt/go/libexec
MacBook$ GOBIN
/Users/xxx/go_space/bin

Setup:

Running a 3 node Vagrant Ubuntu cluster, and using Macbook CLI to issue commands to my vagrant cluster, and communication is wired up from ~/.kube/config

MacBook$ kubectl get nodes
NAME         STATUS   ROLES    AGE     VERSION
k8s-head     Ready    master   2d14h   v1.13.3
k8s-node-1   Ready    <none>   2d14h   v1.13.3
k8s-node-2   Ready    <none>   2d14h   v1.13.3

@trstringer Any inputs on it ? Do we need some dependency file for it, which can install things ? Or I need to run the code from head Node ?

swapanshridhar avatar Feb 08 '19 00:02 swapanshridhar

As suspected, it was dependencies not present after having bare GO compiler there< I did the following to resolve it before running > 'go run *.go' :

$ go get github.com/Sirupsen/logrus
$ go get k8s.io/apimachinery/pkg/apis/meta/v1
$ go get github.com/trstringer/k8s-controller-custom-resource/pkg/client/clientset/versioned
$ go get k8s.io/client-go/kubernetes
$ go get k8s.io/client-go/tools/clientcmd
$ go get k8s.io/client-go/tools/cache
$ go get k8s.io/client-go/util/workqueue

swapanshridhar avatar Feb 08 '19 03:02 swapanshridhar

Thanks, @swapanshridhar info. I also tried to succeed.

yylin1 avatar Feb 08 '19 16:02 yylin1

$ sudo apt-get install go-dep $ sudo dep ensure

warmchang avatar Dec 30 '19 03:12 warmchang

Anyone can you help me, I'm facing a similar error but I have no Idea how to resolve this Screenshot (576) Screenshot (577)

Vi1234sh12 avatar Mar 02 '21 10:03 Vi1234sh12

go dep is now deprecated. the correct way to resolve is by running:

go mod init
go mod tidy

prashant2402 avatar Nov 16 '21 22:11 prashant2402