omrikiei / ktunnel

A cli that exposes your local resources to kubernetes
GNU General Public License v3.0
958 stars 75 forks source link

Ktunnel crashes if we try to use the kube config from env variable #57

Closed Mariappan closed 3 years ago

Mariappan commented 3 years ago

Hello, Thanks for this nice k8s plugin.

Most dev use this idea of running a proxy container to forward the k8s traffic to local dev environment manually. But this plugin really makes that process smoother, with a single command.

I am trying to use this plugin for my dev environment and I am facing a minor issue with my setup.

I have multiple clusters configured though env variable KUBECONFIG https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/#the-kubeconfig-environment-variable

When trying to start ktunnel using this config, ktunnel crashes with following trace:

ERRO[0000] Failed getting kubernetes config: stat /home/maari/.kube/config:/home/maari/.kube/first.yaml:/home/maari/.kube/second.yaml: no such file or directory
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1323f7a]

goroutine 1 [running]:
k8s.io/client-go/kubernetes.NewForConfig(0x0, 0xc0003f126f, 0xff9ff3fe7fc, 0x37)
    /home/maari/go/pkg/mod/k8s.io/client-go@v0.20.0/kubernetes/clientset.go:395 +0x3a
github.com/omrikiei/ktunnel/pkg/k8s.getClients.func1()
    /home/maari/documents/github/ktunnel/pkg/k8s/common.go:75 +0x34
sync.(*Once).doSlow(0x2170878, 0xc0004239b8)
    /usr/lib/go/src/sync/once.go:68 +0xec
sync.(*Once).Do(...)
    /usr/lib/go/src/sync/once.go:59
github.com/omrikiei/ktunnel/pkg/k8s.getClients(0x2136a40)
    /home/maari/documents/github/ktunnel/pkg/k8s/common.go:74 +0x69
github.com/omrikiei/ktunnel/pkg/k8s.ExposeAsService(0x2136a40, 0xc000446320, 0x7010, 0x164d91e, 0x3, 0xc0003d35d0, 0x1, 0x1, 0xc00043c1a0, 0x1f, ...)
    /home/maari/documents/github/ktunnel/pkg/k8s/exposer.go:20 +0x45
github.com/omrikiei/ktunnel/cmd.glob..func2(0x212bee0, 0xc0003d35c0, 0x2, 0x2)
    /home/maari/documents/github/ktunnel/cmd/expose.go:42 +0x1e5
github.com/spf13/cobra.(*Command).execute(0x212bee0, 0xc0003d3580, 0x2, 0x2, 0x212bee0, 0xc0003d3580)
    /home/maari/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:856 +0x2c2
github.com/spf13/cobra.(*Command).ExecuteC(0x212b9e0, 0x7, 0x0, 0x0)
    /home/maari/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:960 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
    /home/maari/go/pkg/mod/github.com/spf13/cobra@v1.1.3/command.go:897
github.com/omrikiei/ktunnel/cmd.Execute()
    /home/maari/documents/github/ktunnel/cmd/root.go:45 +0x65
main.main()
    /home/maari/documents/github/ktunnel/main.go:8 +0x25
omrikiei commented 3 years ago

Hi @Mariappan , thank you for submitting the issue - I'll take a look and update the ticket soon