-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (49 loc) · 1.4 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
package main
import (
"log"
"os"
"os/signal"
"syscall"
)
func main() {
// Load initial configuration
configuration := parseFlags()
logger, err := getLogger(configuration)
if err != nil {
log.Fatalf("[FATAL] Failed to instantiate logger: %s", err)
}
// Validate the configuration
if errs := configuration.Validate(); len(errs) != 0 {
logger.Fatalw("Invalid configuration values", "errors", errs)
}
logger.Infow("Using configuration", "configuration", configuration)
// Initialize application state
state, err := NewState(configuration, logger)
if err != nil {
logger.Fatalw("Failed to initialize application", "err", err)
}
defer state.Store.CleanUp()
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
// TODO: maybe regularly sync with docker
if err := syncDNSWithDocker(state); err != nil {
logger.Fatalw("Failed to get initial docker state", "err", err)
}
eventChan, errorChan := makeDockerChannels(state.DockerClient, state.Config)
main:
for {
select {
case event := <-eventChan:
err := processDockerEvent(event, state)
if err != nil {
state.Logger.Errorw("Failed to process docker event", "err", err)
}
case err := <-errorChan:
state.Logger.Fatalw("Received a docker error", "err", err)
break main
case sig := <-signalChan:
state.Logger.Infow("Received signal to terminate", "sig", sig)
break main
}
}
}