yunabe / lgo

Interactive Go programming with Jupyter
BSD 3-Clause "New" or "Revised" License
2.44k stars 122 forks source link

Trying to install Kubernetes client-go package fails #51

Closed radu-matei closed 6 years ago

radu-matei commented 6 years ago

Hi, and thanks for the awesome project!

I'm trying to install the Kubernetes client-go so I can use it in a notebook. This is what I'm trying to do in the Dockerfile:

RUN go get k8s.io/client-go/...

RUN go get github.com/tools/godep

RUN cd /go/src/k8s.io/client-go && godep restore
RUN lgo installpkg k8s.io/client-go/...

While most of the packages seem to be installed correctly, some of them fail in the following way:

 /tmp/go-build734525261/libk8s.io-client-go-tools-portforward.so
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: missing section for relocation target k8s.io/apimachinery/pkg/util/sets.String.PopAny
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: reloc 8 to non-elf symbol k8s.io/apimachinery/pkg/util/sets.String.PopAny (outer=k8s.io/apimachinery/pkg/util/sets.String.PopAny) 0
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: undefined: "k8s.io/apimachinery/pkg/util/sets.String.PopAny"
(336/348) failed to install "k8s.io/client-go/tools/portforward": exit status 2
# /tmp/go-build519294519/libk8s.io-apimachinery-pkg-util-remotecommand.so
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: missing section for relocation target k8s.io/apimachinery/pkg/util/sets.String.PopAny
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: reloc 8 to non-elf symbol k8s.io/apimachinery/pkg/util/sets.String.PopAny (outer=k8s.io/apimachinery/pkg/util/sets.String.PopAny) 0
k8s.io/apimachinery/pkg/apis/meta/v1.ParseToLabelSelector: undefined: "k8s.io/apimachinery/pkg/util/sets.String.PopAny"

Although it seems to be an issue with the package itself, I want to make sure that:

 reloc 8 to non-elf symbol 
 missing section for relocation target 

are not issues with the compatibility of this project.

Thanks!

radu-matei commented 6 years ago

And I just found your issue https://github.com/golang/go/issues/22998

yunabe commented 6 years ago

And I just found your issue golang/go#22998

Yes, that is the root cause of this. lgo relies on -buildmode=shared internally. There is a bug in go that buildmode=shared fails if the target packaeg (A) has an indirect dependency to another package (B) and the shared library of B (e.g. libB.so) is already installed. Supprisingly, packages with indirect dependencies are rare, but it still sometimes happens.

In this case, I think the easiest workaround is just adding k8s.io/apimachinery/pkg/util/sets to the blacklist lgo maintains because errors are caused by the indirect dependencies to k8s.io/apimachinery/pkg/util/sets by PopAny.

yunabe commented 6 years ago

I blacklisted k8s.io/apimachinery/pkg/util/sets and updated the docker image (yunabe/lgo:latest). Can you docker pull and try it again?

radu-matei commented 6 years ago

I successfully built the image and tried to run a basic example - this is the output:

# /tmp/go-build478673581/libgithub.com-yunabe-lgo-sess7b2274696d65223a313532343234363035373238363437363030307d-exec4.so
github.com/yunabe/lgo/sess7b2274696d65223a313532343234363035373238363437363030307d/exec4.LgoExport_main: missing section for relocation target k8s.io/client-go/kubernetes/typed/core/v1.(*CoreV1Client).Pods
github.com/yunabe/lgo/sess7b2274696d65223a313532343234363035373238363437363030307d/exec4.LgoExport_main: reloc 8 to non-elf symbol k8s.io/client-go/kubernetes/typed/core/v1.(*CoreV1Client).Pods (outer=k8s.io/client-go/kubernetes/typed/core/v1.(*CoreV1Client).Pods) 0
github.com/yunabe/lgo/sess7b2274696d65223a313532343234363035373238363437363030307d/exec4.LgoExport_main: undefined: "k8s.io/client-go/kubernetes/typed/core/v1.(*CoreV1Client).Pods"
Failed to build a shared library of github.com/yunabe/lgo/sess7b2274696d65223a313532343234363035373238363437363030307d/exec4: exit status 2
yunabe commented 6 years ago

Interesting. Can you share the code you executed in your basic example?

radu-matei commented 6 years ago

I tried to get started with the example in the client-go repo

yunabe commented 6 years ago

Thanks. It seems like the workaround I implemented to bypasss https://github.com/golang/go/issues/22998 to fix https://github.com/yunabe/lgo/issues/11 is not working in this case. Maybe because Pods is an interface method or Pods is defined via embedding.

yunabe commented 6 years ago

I'm investigating the condition to reproduce this issue. For the meanwhile, you can bypass the issue by adding import _ "k8s.io/client-go/kubernetes/typed/core/v1" to your code.

radu-matei commented 6 years ago

Now it works, thanks a lot!