Building go-lang project /Kubernetes Ingress/ from scratch with no go experience

in k8s •  6 years ago 


I have been working with Kubernetes and I wanted to build it's contrib yesterday. However, nginx implementation of Kubernetes' Ingress is written in go-lang. Even though I needed to change some const string, it required recompilation.

Go is not java, and go building system is not maven. Setting up the environment was not straightforward. I was facing couple troubles but I'm going to take it from the beginning. My laptop uses ubuntu 15.04 - well 15.10 since 9pm :-) - and I have never installed go lang yet.

Go lang installation on Ubuntu

First of all, you need to install go lang. You can use official repo, but it contains older version 1.3. However, do not install it using apt-get as kubernetes or it's dependencies require higher version of go-lang. Of course, I originally installed version 1.3  but some fatal error occurred later. It forced me do to the manual installation anyway.

Here is simple tutorial.

wget https://storage.googleapis.com/golang/go1.5.1.linux-amd64.tar.gz 
sudo tar -C /usr/local -xzf go1.5.1.linux-amd64.tar.gz
export GOROOT=/usr/local/go
export PATH=$PATH:$GOROOT/bin


Last two lines affect only the current terminal. You should update /etc/environment in the case you consider to use go-lang in the future.

Then, you can try to get version of go via:

$ go version
go version go1.5.1 linux/amd64

Go-lang compilation and building

Now, you can pull your git project, e.g.:

git clone https://github.com/kubernetes/contrib

There is a build command in go-lang. You can type it into you terminal:

$ go buildcontroller.go:26:2: cannot find package "k8s.io/kubernetes/pkg/api" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/api (from $GOROOT) ($GOPATH not set)controller.go:27:2: cannot find package "k8s.io/kubernetes/pkg/apis/extensions" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/apis/extensions (from $GOROOT) ($GOPATH not set)controller.go:28:2: cannot find package "k8s.io/kubernetes/pkg/client/unversioned" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/client/unversioned (from $GOROOT) ($GOPATH not set)controller.go:29:2: cannot find package "k8s.io/kubernetes/pkg/fields" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/fields (from $GOROOT) ($GOPATH not set)controller.go:30:2: cannot find package "k8s.io/kubernetes/pkg/labels" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/labels (from $GOROOT) ($GOPATH not set)controller.go:31:2: cannot find package "k8s.io/kubernetes/pkg/util" in any of: /usr/local/go/src/k8s.io/kubernetes/pkg/util (from $GOROOT) ($GOPATH not set)


What's wrong? We have not setup GOPATH yet. This directory is something like maven cache. It's pretty simple, you can just point the variable to your home, e.g.

export GOPATH=/home/martin/.go

Try to build it again. There are no errors, but nothing is happening. I found in some stackoverflow discussion that there is a get command as well. Unfortunately, buildis consist of get anyway. Then I found -v as verbose.

$ /usr/local/go/bin/go get -vFetching https://k8s.io/kubernetes/pkg/api?go-get=1Parsing meta tags from https://k8s.io/kubernetes/pkg/api?go-get=1 (status code 200)get "k8s.io/kubernetes/pkg/api": found meta tag main.metaImport{Prefix:"k8s.io/kubernetes", VCS:"git", RepoRoot:"https://github.com/kubernetes/kubernetes"} at https://k8s.io/kubernetes/pkg/api?go-get=1get "k8s.io/kubernetes/pkg/api": verifying non-authoritative meta tagFetching https://k8s.io/kubernetes?go-get=1Parsing meta tags from https://k8s.io/kubernetes?go-get=1 (status code 200)k8s.io/kubernetes (download)

That's all, now building should work:

$ go build -vgithub.com/davecgh/go-spew/spewgithub.com/ugorji/go/codecgolang.org/x/net/contextgithub.com/google/gofuzzk8s.io/kubernetes/pkg/api/unversionedk8s.io/kubernetes/third_party/forked/reflectk8s.io/kubernetes/pkg/util/setsgopkg.in/yaml.v2github.com/golang/glogk8s.io/kubernetes/pkg/types
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

Congratulations @martinpodval! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 1 year!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!