vladimirvivien / k8s-client-examples

Building stuff with the Kubernetes API
MIT License
118 stars 62 forks source link

Unable to build a binary or compile the example files #3

Open sanjiths opened 3 years ago

sanjiths commented 3 years ago

I am trying to build a binary for https://github.com/vladimirvivien/k8s-client-examples/blob/master/go/podlist/maing.go I have imported the required packages and facing the below issue:

[sansampa@localhost podlist]$ go build maing.go 
import cycle not allowed
package main
    imports k8s.io/apimachinery/pkg/apis/meta/v1
    imports k8s.io/apimachinery/pkg/labels
    imports k8s.io/apimachinery/pkg/util/validation
    imports net
    imports internal/nettrace
    imports net/http/httptrace
    imports crypto/tls
    imports crypto/tls
import cycle not allowed
package main
    imports k8s.io/apimachinery/pkg/apis/meta/v1
    imports k8s.io/apimachinery/pkg/labels
    imports k8s.io/apimachinery/pkg/util/validation
    imports net
    imports internal/nettrace
    imports net/http/httptrace
    imports internal/nettrace
/usr/local/go/src/net/dnsclient.go:12:8: non-standard import "golang.org/x/net/dns/dnsmessage" in standard package "net"
/usr/local/go/src/net/http/h2_bundle.go:47:9: non-standard import "golang.org/x/net/http/httpguts" in standard package "net/http"

Could you pls tell me how to proceed?

vladimirvivien commented 3 years ago

@sanjiths I updated the Go example with support for Go modules. Take a look to see if that helps.

sanjiths commented 3 years ago

Hi @vladimirvivien! It really helped :) thank you so much (y) Now, I have one more problem! How can i use this binary from inside a container or a pod?

I am facing below issue:


./podlist tree
2021/01/26 10:42:39 stat /home/vault/.kube/config: no such file or directory
[vault@vaultagent-0 tmp]$ vi /home/vault/.kube/config:

Thanks, Sanjith S

vladimirvivien commented 3 years ago

@sanjiths the code in this example is written to be used outside of a cluster.
But it's easy to change your code to make it work from within a cluster. Checkout the link below (from the client-go project), it shows what to change to fix your issue:

https://github.com/kubernetes/client-go/blob/b72204b2445de5ac815ae2bb993f6182d271fdb4/examples/in-cluster-client-configuration/main.go#L42