K8s Go client library fails to find package on go get

9/7/2016

We wrote some Go code to talk to our Kubernetes cluster and fetch the IP of a Service exposed. We do it like so:

(import "gopkg.in/kubernetes/kubernetes.v1/pkg/client/restclient")
(import kubectl "gopkg.in/kubernetes/kubernetes.v1/pkg/client/unversioned")

 svc, err := c.Services(k8sNS).Get(svcName)
 if err != nil {
   panic(l.Errorf("Could not retrieve svc details. %s", err.Error()))
 }
 svcIP := svc.Status.LoadBalancer.Ingress[0].IP

go get works fine, and our script executes when we do go run ... and everybody is happy. Now, as of yesterday (from the time this question is posted) on the same script - go get fails. The error is like so:

[09.07.2016 10:56 AM]$ go get
package k8s.io/kubernetes/pkg/apis/authentication.k8s.io/install: cannot find package "k8s.io/kubernetes/pkg/apis/authentication.k8s.io/install" in any of:
        /usr/local/go/src/k8s.io/kubernetes/pkg/apis/authentication.k8s.io/install (from $GOROOT)
        /home/ckotha/godir/src/k8s.io/kubernetes/pkg/apis/authentication.k8s.io/install (from $GOPATH)

We have not specifically used authentication package in our code. Are we importing kubernetes libraries correctly? is there another way to do this ?

ls on $GOPATH/k8s.io/kubernetes/pkg/apis/ and found this:

:~/godir/src/k8s.io/kubernetes/pkg/apis
[09.07.2016 10:53 AM]$ ls
abac  apps  authentication  authorization  autoscaling  batch  certificates  componentconfig  extensions  imagepolicy  OWNERS  policy  rbac  storage
-- chetan
go
kubernetes

1 Answer

9/7/2016

It looks like a package you imported has changed.

You can update existing repositories:

go get -u

The -u flag instructs get to use the network to update the named packages and their dependencies. By default, get uses the network to check out missing packages but does not use it to look for updates to existing packages.

You do use gopkg.io to pin the version to v1, but I think you want to be more specific, eg, v1.3.6 (EDIT: this won't work because gopkg.in doesn't permit package selectors more specific than the major version.).

Alternatively, a good way to ensure code stays the same is to compile your binary and execute that, instead of using go run.

-- Mark
Source: StackOverflow