diff --git a/modules/kubernetes/client.go b/modules/kubernetes/client.go index 5fe370732..2b0101abe 100644 --- a/modules/kubernetes/client.go +++ b/modules/kubernetes/client.go @@ -1,36 +1,26 @@ package kubernetes import ( - "sync" - "k8s.io/client-go/kubernetes" // Includes authentication modules for various Kubernetes providers _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/client-go/tools/clientcmd" ) -var kubeClient *clientInstance -var kubeError error -var clientOnce sync.Once - type clientInstance struct { Client kubernetes.Interface } // getInstance returns a Kubernetes interface for a clientset func (widget *Widget) getInstance() (*clientInstance, error) { - clientOnce.Do(func() { - if kubeClient == nil { - client, err := widget.getKubeClient() - if err != nil { - kubeError = err - } - kubeClient = &clientInstance{ - Client: client, - } - } + var err error + + widget.clientOnce.Do(func() { + widget.client = &clientInstance{} + widget.client.Client, err = widget.getKubeClient() }) - return kubeClient, kubeError + + return widget.client, err } // getKubeClient returns a kubernetes clientset for the kubeconfig provided diff --git a/modules/kubernetes/widget.go b/modules/kubernetes/widget.go index ea88d369d..40b577c30 100644 --- a/modules/kubernetes/widget.go +++ b/modules/kubernetes/widget.go @@ -2,6 +2,7 @@ package kubernetes import ( "fmt" + "sync" "github.com/rivo/tview" "github.com/wtfutil/wtf/utils" @@ -14,6 +15,9 @@ import ( type Widget struct { view.TextWidget + client *clientInstance + clientOnce sync.Once + objects []string title string kubeconfig string