-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
35 lines (29 loc) · 814 Bytes
/
client.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
package client
import (
"fmt"
"os"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
// gcp fails hard without this
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
func ClientConfig() clientcmd.ClientConfig {
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{})
}
// get the kube client config to call kube API
func InitClient() *kubernetes.Clientset {
clientConfig := ClientConfig()
config, err := clientConfig.ClientConfig()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: getting configurations is hard\n")
os.Exit(1)
}
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: creating clients is hard\n")
os.Exit(1)
}
return clientset
}