-
Notifications
You must be signed in to change notification settings - Fork 76
/
main.go
67 lines (55 loc) · 1.61 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
package main
import (
"fmt"
"github.com/abahmed/kwatch/alertmanager"
"github.com/abahmed/kwatch/client"
"github.com/abahmed/kwatch/config"
"github.com/abahmed/kwatch/constant"
"github.com/abahmed/kwatch/handler"
"github.com/abahmed/kwatch/pvcmonitor"
"github.com/abahmed/kwatch/storage/memory"
"github.com/abahmed/kwatch/upgrader"
"github.com/abahmed/kwatch/version"
"github.com/abahmed/kwatch/watcher"
"github.com/sirupsen/logrus"
)
func main() {
config, err := config.LoadConfig()
if err != nil {
logrus.Fatalf("failed to load config: %s", err.Error())
}
setLogFormatter(config.App.LogFormatter)
logrus.Infof(fmt.Sprintf(constant.WelcomeMsg, version.Short()))
// create kubernetes client
client := client.Create(&config.App)
alertManager := alertmanager.AlertManager{}
alertManager.Init(config.Alert, &config.App)
if !config.App.DisableStartupMessage {
// send notification to providers
alertManager.Notify(fmt.Sprintf(constant.WelcomeMsg, version.Short()))
}
// check and notify if newer versions are available
upgrader := upgrader.NewUpgrader(&config.Upgrader, &alertManager)
go upgrader.CheckUpdates()
// start monitoring Persistent Volume Claims
pvcMonitor :=
pvcmonitor.NewPvcMonitor(client, &config.PvcMonitor, &alertManager)
go pvcMonitor.Start()
// Create handler
h := handler.NewHandler(
client,
config,
memory.NewMemory(),
&alertManager,
)
// start watcher
watcher.Start(client, config, h)
}
func setLogFormatter(formatter string) {
switch formatter {
case "json":
logrus.SetFormatter(&logrus.JSONFormatter{})
default:
logrus.SetFormatter(&logrus.TextFormatter{})
}
}