Sitemap

Straighten out Your Kubernetes client-go Dependencies — #HeptioProTip

--

Recently I’ve seen some people having trouble getting the Kubernetes client-go package to compile. Within the Kubernetes API Machinery SIG, we’ve been reorganizing client-go and its dependencies so they’re actually easier to use, but in the interim, you may notice the occasional compilation failure due to mismatching dependencies in your GOPATH. If you find yourself scratching your head trying to make things work, then this post is for you!

Zoom image will be displayed
Thanks to Ashley McNamara for the gophers

Client-go currently uses the godep dependency management tool to vendor its dependencies. Below, we’ll also use godep to ensure the proper revisions are checked out for all of client-go’s dependencies.

Make sure you’re using a tag for client-go instead of the master branch; our recommendation is v4.0.0-beta.0, which is compatible with Kubernetes versions up through v1.7.x.

NOTE: This approach checks out the specific revisions of packages that client-go needs in your GOPATH. If you want to avoid changing anything in your normal GOPATH, we recommend that you create a clean new directory and set your GOPATH environment variable to point to the new directory.

Install godep if you don’t already have it:

$ go get github.com/tools/godep

Download client-go if you don’t already have it, and check out the appropriate tag:

$ go get k8s.io/client-go
$ cd $GOPATH/src/k8s.io/client-go
$ git checkout v4.0.0-beta.0

Restore client-go’s dependencies to their appropriate versions in your GOPATH.

$ cd $GOPATH/src/k8s.io/client-go
$ godep restore

Write some code that uses client-go. For example, in $GOPATH/src/github.com/ncdc/client-go-example/main.go

Optionally, vendor these dependencies in your project

$ godep save ./…

Try it out! Here’s what I see against my hack/local-up-cluster.sh cluster.

$ export KUBECONFIG=<path to your kubeconfig file>
$ go run ./main.go
Node: 127.0.0.1

Finally, if you’re also planning on using code from the Kubernetes repository, we recommend you check out the latest v1.7.x tag, which corresponds to the v4.0.0-beta.0 client-go tag.

Hope you enjoyed this #HeptioProTip! Follow @heptio for more tips and tricks.

--

--

Andy Goldstein
Andy Goldstein

Written by Andy Goldstein

Husband, father, engineer @ Red Hat, Kubernetes contributor

Responses (2)