-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.go
40 lines (32 loc) · 790 Bytes
/
util.go
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
30
31
32
33
34
35
36
37
38
39
40
package main
import (
"fmt"
"os"
"k8s.io/client-go/kubernetes"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
func getKubeHandle() *kubernetes.Clientset {
var conf *rest.Config
// In cluster config
/*
conf, err := rest.InClusterConfig()
if err != nil {
fmt.Println("err=", err)
}*/
// Outside of cluster config
conf, err := clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config")
if err != nil {
fatal(fmt.Sprintf("error in getting Kubeconfig: %v", err))
}
cs, err := kubernetes.NewForConfig(conf)
if err != nil {
fatal(fmt.Sprintf("error in getting clientset from Kubeconfig: %v", err))
}
return cs
}
func fatal(msg string) {
os.Stderr.WriteString(msg + "\n")
os.Exit(1)
}