-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
40 lines (35 loc) · 906 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
36
37
38
39
40
package netkat
import (
"github.com/go-kit/kit/log/level"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"os"
)
type (
Client struct {
*kubernetes.Clientset
Config *rest.Config
}
)
func InitClient(context string, kubeConfig string) (k8sClient Client) {
config, err := buildConfigFromFlags(context, kubeConfig)
if err != nil {
_ = level.Error(Logger).Log("msg", err)
os.Exit(1)
}
clientSet, err := kubernetes.NewForConfig(config)
if err != nil {
_ = level.Error(Logger).Log("msg", err)
os.Exit(1)
}
k8sClient = Client{clientSet, config}
return
}
func buildConfigFromFlags(context, kubeConfig string) (*rest.Config, error) {
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
&clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeConfig},
&clientcmd.ConfigOverrides{
CurrentContext: context,
}).ClientConfig()
}