I'm trying your code to remove the plumbing for in- and out of cluster K8s access. I started with this small example:
package k8s
import (
"fmt"
discovery "github.com/gkarthiks/k8s-discovery"
)
var (
k8s *discovery.K8s
)
// GetKubernetesConnection tries to create a connection either from a local .kube/config file or from in-cluster service account
func GetKubernetesConnection() {
k8s, _ = discovery.NewK8s()
namespace, _ := k8s.GetNamespace()
fmt.Printf("Specified Namespace: %s\n", namespace)
version, _ := k8s.GetVersion()
fmt.Printf("Version of running Kubernetes: %s\n", version)
}
INFO[0000] Program running from outside of the cluster
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1d82986]
goroutine 1 [running]:
github.com/gkarthiks/k8s-discovery.(*K8s).GetVersion(0x0, 0x2185a60, 0xc00037e1f0, 0x10436e7, 0x2aa56c0)
/Users/ringods/Projects/golang/pkg/mod/github.com/gkarthiks/[email protected]/discovery.go:69 +0x26
github.com/cumundi/sqe-processing/pkg/k8s.GetKubernetesConnection()
/Users/ringods/Projects/cumundi/sqe-processing/pkg/k8s/runner.go:17 +0x43
main.main()
/Users/ringods/Projects/cumundi/sqe-processing/pkg/cmd/sqe-starter/main.go:19 +0x20
I am testing this now out of cluster, with a kubeconfig having the current context set to a GKE cluster. I am fully authenticated and any kubectl
command correctly communicates with the cluster.