-
Notifications
You must be signed in to change notification settings - Fork 251
/
main.go
59 lines (48 loc) · 1.54 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 (
"flag"
"fmt"
"os"
"github.com/golang/glog"
"kube-monkey/internal/pkg/config"
"kube-monkey/internal/pkg/kubemonkey"
)
func glogUsage() {
fmt.Fprintf(os.Stderr, "usage: example -stderrthreshold=[INFO|WARN|FATAL] -log_dir=[string]\n")
flag.PrintDefaults()
os.Exit(2)
}
func initLogging() {
// Check commandline options or "flags" for glog parameters
// to be picked up by the glog module
flag.Usage = glogUsage
flag.Parse()
if _, err := os.Stat(flag.Lookup("log_dir").Value.String()); os.IsNotExist(err) {
err = os.MkdirAll(flag.Lookup("log_dir").Value.String(), os.ModePerm)
if err != nil {
glog.Errorf("Failed to open custom log directory at %s; defaulting to /tmp! Error: %v", flag.Lookup("log_dir").Value, err)
} else {
glog.V(5).Infof("Created custom logging %s directory!", flag.Lookup("log_dir").Value)
}
}
// Since km runs as a k8 pod, log everything to stderr (stdout not supported)
// this takes advantage of k8's logging driver allowing kubectl logs kube-monkey
if err := flag.Lookup("alsologtostderr").Value.Set("true"); err != nil {
glog.Errorf("Failed to set alsologtostderr. Error: %v", err)
}
}
func initConfig() {
if err := config.Init(); err != nil {
glog.Fatal(err.Error())
}
}
func main() {
// Initialize logging
initLogging()
// Initialize configs
initConfig()
glog.V(1).Infof("Starting kube-monkey with v logging level %v and local log directory %s", flag.Lookup("v").Value, flag.Lookup("log_dir").Value)
if err := kubemonkey.Run(); err != nil {
glog.Fatal(err.Error())
}
}