-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
59 lines (42 loc) · 976 Bytes
/
main.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
50
51
52
53
54
55
56
57
58
59
package main
import (
"log"
"os"
"os/signal"
"sync"
"syscall"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
const (
defaultClusterRoleName = "edit"
)
func main() {
log.SetOutput(os.Stdout)
sigs := make(chan os.Signal, 1)
stop := make(chan struct{})
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
wg := &sync.WaitGroup{}
k8sClient, err := newK8sClient()
if err != nil {
panic(err.Error())
}
// Set cluster role name
clusterRoleName := os.Getenv("CLUSTER_ROLE_NAME")
if clusterRoleName == "" {
clusterRoleName = defaultClusterRoleName
}
go nsControllerExec(k8sClient, clusterRoleName, stop, wg)
<-sigs
log.Println("Shutting down...")
close(stop)
wg.Wait()
}
func newK8sClient() (*kubernetes.Clientset, error) {
k8sConfig := os.Getenv("KUBECONFIG")
config, err := clientcmd.BuildConfigFromFlags("", k8sConfig)
if err != nil {
return nil, err
}
return kubernetes.NewForConfig(config)
}