-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
79 lines (65 loc) · 1.76 KB
/
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"os"
"os/signal"
graph "github.com/SunSince90/ASTRID-kube/graph"
"github.com/SunSince90/ASTRID-kube/informers"
"github.com/SunSince90/ASTRID-kube/settings"
types "github.com/SunSince90/ASTRID-kube/types"
"github.com/kardianos/osext"
log "github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/tools/clientcmd"
)
var (
signalChan chan os.Signal
stop chan struct{}
cleanupDone chan struct{}
)
func main() {
log.Infoln("Starting...")
// Get the current path
folderPath, err := osext.ExecutableFolder()
if err != nil {
log.Fatal(err)
}
settings.Load(folderPath + "/settings/conf.yaml")
log.Infoln("Configuration file loaded successfully")
//----------------------------------------
// Start
//----------------------------------------
clientset := getClientSet()
settings.Clientset = clientset
// Set up the node informer
informers.Nodes = informers.New(types.Nodes, "").(*informers.NodeInformer)
informers.Nodes.AddEventHandler(nil, nil, nil)
informers.Nodes.Start()
signalChan = make(chan os.Signal, 1)
stop = make(chan struct{})
graphManager := graph.InitManager(clientset, stop)
graphManager.Start()
cleanupDone = make(chan struct{})
signal.Notify(signalChan, os.Interrupt)
go cleanUp()
<-cleanupDone
}
func getClientSet() kubernetes.Interface {
// Use the current context in kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", settings.Settings.Paths.Kubeconfig)
if err != nil {
panic(err.Error())
}
// Get the clientset
clientset, err := kubernetes.NewForConfig(config)
if err != nil {
panic(err.Error())
}
return clientset
}
func cleanUp() {
<-signalChan
close(stop)
log.Infoln("Received an interrupt, stopping everything")
//cleanup(services, c)
close(cleanupDone)
}