-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathclient.go
More file actions
29 lines (25 loc) · 748 Bytes
/
client.go
File metadata and controls
29 lines (25 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package kubernetes
import (
"os"
"path/filepath"
"github.com/pkg/errors"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
)
func GetClient() (*kubernetes.Clientset, error) {
config, err := rest.InClusterConfig()
if err != nil {
if os.Getenv("PORTAINER_UPDATER_DEBUG") != "1" {
return nil, errors.WithMessage(err, "failed to get kubernetes config")
}
// Fallback to local kubeconfig
kubeconfig := filepath.Join(homedir.HomeDir(), ".kube", "config")
config, err = clientcmd.BuildConfigFromFlags("", kubeconfig)
if err != nil {
return nil, errors.WithMessage(err, "failed to get kubernetes config")
}
}
return kubernetes.NewForConfig(config)
}