forked from abahmed/kwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.63 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
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/abahmed/kwatch/constant"
"github.com/abahmed/kwatch/controller"
"github.com/abahmed/kwatch/upgrader"
"github.com/abahmed/kwatch/util"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func main() {
logrus.Infof(fmt.Sprintf(constant.WelcomeMsg, constant.Version))
// initialize configuration
configFile := os.Getenv("CONFIG_FILE")
if len(configFile) == 0 {
configFile = filepath.Join("config.yaml")
}
viper.SetConfigFile(configFile)
viper.AutomaticEnv()
// if a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
logrus.Infof("using config file: %s", viper.ConfigFileUsed())
} else {
logrus.Warnf("unable to load config file: %s", err.Error())
}
// get providers
providers := util.GetProviders()
// check and notify if newer versions are available
if !viper.GetBool("disableUpdateCheck") {
go upgrader.CheckUpdates(providers)
}
// Parse namespace allow/forbid lists
namespaceAllowList := make([]string, 0)
namespaceForbidList := make([]string, 0)
for _, namespace := range viper.GetStringSlice("namespaces") {
if clean := strings.TrimPrefix(namespace, "!"); namespace != clean {
namespaceForbidList = append(namespaceForbidList, clean)
continue
}
namespaceAllowList = append(namespaceAllowList, namespace)
}
if len(namespaceAllowList) > 0 && len(namespaceForbidList) > 0 {
logrus.Fatal("Either allowed or forbidden namespaces must be set. Can't set both")
}
// start controller
controller.Start(providers, viper.GetBool("ignoreFailedGracefulShutdown"), namespaceAllowList, namespaceForbidList)
}