Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kubernetes] use k8s client per widget #1141

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 7 additions & 17 deletions modules/kubernetes/client.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions modules/kubernetes/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package kubernetes

import (
"fmt"
"sync"

"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
Expand All @@ -14,6 +15,9 @@ import (
type Widget struct {
view.TextWidget

client *clientInstance
clientOnce sync.Once

objects []string
title string
kubeconfig string
Expand Down