wtfutil / wtf

The personal information dashboard for your terminal
http://wtfutil.com
Mozilla Public License 2.0
15.71k stars 799 forks source link

Feat Request: Use current-context in Kubernetes module when default context doesn't exist. #1265

Open webdog opened 2 years ago

webdog commented 2 years ago

What should it do?

In the Kubernetes module, if a context isn't specified, the behavior is to revert to the default context. If this doesn't exist, the application panics, and returns an invalid memory address.

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x1e0 pc=0x4fd5d7c]
goroutine 38 [running]:
k8s.io/client-go/tools/clientcmd.(*DeferredLoadingClientConfig).createClientConfig(0xc000432050)
k8s.io/client-go@v10.0.0+incompatible/tools/clientcmd/merged_client_builder.go:77 +0x2bc
k8s.io/client-go/tools/clientcmd.(*DeferredLoadingClientConfig).ClientConfig(0xc000432050)
                                                                                                                                                                                                    k8s.io/client-go@v10.0.0+incompatible/tools/clientcmd/merged_client_builder.go:98 +0x25
github.com/wtfutil/wtf/modules/kubernetes.(*Widget).getKubeClient(0xc0000da640)
github.com/wtfutil/wtf/modules/kubernetes/client.go:37 +0x16a
                                                                                                                                                                                     github.com/wtfutil/wtf/modules/kubernetes.(*Widget).getInstance.func1()
                                                                                                                                                                                                                                                            github.com/wtfutil/wtf/modules/kubernetes/client.go:20 +0x65
sync.(*Once).doSlow(0x57597d6, 0x53db640)
sync/once.go:68 +0xd2
 sync.(*Once).Do(...)
sync/once.go:59
                                                                                                                                                                       github.com/wtfutil/wtf/modules/kubernetes.(*Widget).getInstance(0xc0000da640)
                                                                                                                                                                                                                                                        github.com/wtfutil/wtf/modules/kubernetes/client.go:18 +0x65
github.com/wtfutil/wtf/modules/kubernetes.(*Widget).Refresh(0xc0000da640)                                                                                                                               github.com/wtfutil/wtf/modules/kubernetes/widget.go:50 +0x4a                                                                                                                                        github.com/wtfutil/wtf/app.Schedule({0x5e2d7f8, 0xc0000da640})
github.com/wtfutil/wtf/app/scheduler.go:12 +0x31
created by github.com/wtfutil/wtf/app.(*WtfApp).scheduleWidgets
github.com/wtfutil/wtf/app/wtf_app.go:167 +0xb0

A current-context exists, but I do not use a default context. I programatically generate my kubeconfigs with the aws CLI, and then remove the kubeconfig after the cluster is removed. When aws CLI regenerates the config, it isn't expected to create a default context based on the parameters sent to the aws cli.

To reproduce:

❯ ~ kubectl get pods --all-namespaces
NAMESPACE     NAME                       READY   STATUS    RESTARTS   AGE
kube-system   aws-node-hwc8r             1/1     Running   0          48m
kube-system   aws-node-jb4gd             1/1     Running   0          49m
kube-system   aws-node-jhhvj             1/1     Running   0          48m
kube-system   coredns-657694c6f4-4w6gx   1/1     Running   0          56m
kube-system   coredns-657694c6f4-lndn5   1/1     Running   0          56m
kube-system   kube-proxy-2qdwc           1/1     Running   0          50m
kube-system   kube-proxy-82w46           1/1     Running   0          50m
kube-system   kube-proxy-vvnh4           1/1     Running   0          50m

It seems reasonable (to me 😄 ) that a current-context can exist when a default doesn't, as this setup isn't necessarily breaking the kubeconfig. wtfutil seems to be state-dependent on the kubeconfig, adding support for the current would/could mitigate this somewhat.

Thank you!

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

webdog commented 1 year ago

@senorprogrammer Any chance the wontfix label could be removed?

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.