-
Notifications
You must be signed in to change notification settings - Fork 3
/
client.go
39 lines (32 loc) · 944 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
package kubernetes
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// RestConfig returns the canonical kubernetes REST config.
//
// Out-of-cluster loading is attempted first, followed by in-cluster when that fails.
func RestConfig() (*rest.Config, error) {
kubeconfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(
clientcmd.NewDefaultClientConfigLoadingRules(),
&clientcmd.ConfigOverrides{},
)
if cfg, err := kubeconfig.ClientConfig(); err == nil {
return cfg, nil
}
return rest.InClusterConfig()
}
// Clientset creates and returns the canonical kubernetes clientset.
//
// If conf is nil, then RestConfig() is used to generate the config object.
func Clientset(conf *rest.Config) (kubernetes.Interface, error) {
var err error
if conf == nil {
conf, err = RestConfig()
if err != nil {
return nil, err
}
}
return kubernetes.NewForConfig(conf)
}