-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathkube.go
49 lines (38 loc) · 936 Bytes
/
kube.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
41
42
43
44
45
46
47
48
49
package main
import (
"os"
"path/filepath"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
// ConfigK8s K8s client
func ConfigK8s() (*kubernetes.Clientset, error) {
incluster := os.Getenv("INCLUSTER")
var config *rest.Config
var err error
if incluster == "" {
config, err = rest.InClusterConfig()
if err != nil {
log.Panic(err)
}
}
if incluster == "FALSE" {
config, err = clientcmd.BuildConfigFromFlags("", filepath.Join(os.Getenv("HOME"), ".kube", "config"))
if err != nil {
log.Panic(err)
}
}
// create the clientset
clientset, err := kubernetes.NewForConfig(config)
return clientset, err
}
//GetNamespace returns the value of the environment variable NAMESPACE or if not set the default the namespace
func GetNamespace() string {
ns := os.Getenv("NAMESPACE")
if ns == "" {
ns = "kube-system"
}
return ns
}