-
Notifications
You must be signed in to change notification settings - Fork 64
/
main.go
72 lines (60 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
68
69
70
71
72
package main
import (
"context"
"os"
"strings"
"time"
"github.com/getsentry/sentry-go"
"github.com/rs/zerolog"
globalLogger "github.com/rs/zerolog/log"
v1 "k8s.io/api/core/v1"
)
func configureLogging() {
levelMap := map[string]zerolog.Level{
"trace": zerolog.TraceLevel,
"debug": zerolog.DebugLevel,
"info": zerolog.InfoLevel,
"warn": zerolog.WarnLevel,
"error": zerolog.ErrorLevel,
"fatal": zerolog.FatalLevel,
"panic": zerolog.PanicLevel,
"disabled": zerolog.Disabled,
}
logLevelRaw := strings.ToLower(os.Getenv("SENTRY_K8S_LOG_LEVEL"))
var logLevel zerolog.Level
logLevel, ok := levelMap[logLevelRaw]
if !ok {
logLevel = zerolog.InfoLevel
}
zerolog.SetGlobalLevel(logLevel)
globalLogger.Logger = globalLogger.Output(zerolog.ConsoleWriter{Out: os.Stdout})
}
func main() {
configureLogging()
initSentrySDK()
defer sentry.Flush(time.Second)
checkCommonEnhancerPatterns()
prepareEventFilters()
config, err := getClusterConfig()
if err != nil {
globalLogger.Fatal().Msgf("Config init error: %s", err)
}
setKubernetesSentryContext(config)
setGlobalSentryTags()
err = runIntegrations()
if err != nil {
globalLogger.Fatal().Msgf("Integration error: %s", err)
}
watchAllNamespaces, namespaces, err := getNamespacesToWatch()
if err != nil {
globalLogger.Fatal().Msgf("Cannot parse namespaces to watch: %s", err)
}
if watchAllNamespaces {
namespaces = []string{v1.NamespaceAll}
}
ctx := globalLogger.Logger.WithContext(context.Background())
startEventWatchers(ctx, config, namespaces)
startPodWatchers(ctx, config, namespaces)
// Sleep forever
select {}
}