/
clientset.go
28 lines (24 loc) · 704 Bytes
/
clientset.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
package k8s
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
// Load all the auth plugins for the cloud providers.
_ "k8s.io/client-go/plugin/pkg/client/auth"
)
func NewClientSet(kubeConfig string) (*kubernetes.Clientset, error) {
var config *rest.Config
var err error
if kubeConfig == "" {
// configure client while running inside the k8s cluster
// uses Service Acct token mounted in the Pod
config, err = rest.InClusterConfig()
} else {
// configure access to the cluster from outside
config, err = clientcmd.BuildConfigFromFlags("", kubeConfig)
}
if err != nil {
return nil, err
}
return kubernetes.NewForConfig(config)
}