-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
65 lines (54 loc) · 1.71 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
package main
import (
"context"
"github.com/taboola/consul2calico/pkg/calico"
"github.com/taboola/consul2calico/pkg/consul"
"github.com/taboola/consul2calico/pkg/controller"
"github.com/taboola/consul2calico/pkg/log"
"github.com/taboola/consul2calico/pkg/setting"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
var (
logger = log.LoggerFunction()
servicesConfigFile = os.Getenv("SVC_CONFIG_FILE")
)
func init() {
log.SeValues("all", "", "")
}
func main() {
// Create application context withCancel
ctx, cancel := context.WithCancel(context.Background())
stop := make(chan os.Signal, 1) // Create channel to receive OS signals
signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) // Register the signals channel to receive SIGTERM
mutexCache := &sync.RWMutex{}
setting.UpdateGlobalParams(servicesConfigFile)
var consulChange = make(map[string]int)
var serviceMap = setting.ServiceMap
var consulCalicoMap = setting.ConsulCalicoMap
var mapAction = setting.MapAction
//Init Consul client
consulClient, err := consul.GetConsulClient()
if err != nil {
logger.Errorf("Failed to initialize consul client ERROR: %v", err)
os.Exit(2)
}
//Init Calico client
calicoClient, err := calico.GetCalicoClient()
if err != nil {
logger.Errorf("Failed to initialize calico client ERROR: %v", err)
os.Exit(2)
}
SyncController := controller.New(calico.New(calicoClient), consul.New(consulClient), logger, consulChange, serviceMap,
consulCalicoMap, mapAction, mutexCache)
SyncController.Run(ctx, stop)
<-stop
// Shutdown. Cancel application context will kill all attached tasks.
cancel()
//Wait for goroutines to die
time.Sleep(3 * time.Second)
os.Exit(2)
}