...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package main
15
16 import (
17 "flag"
18 "os"
19
20 "go.uber.org/fx"
21
22 _ "github.com/jinzhu/gorm/dialects/mssql"
23 _ "github.com/jinzhu/gorm/dialects/mysql"
24 _ "github.com/jinzhu/gorm/dialects/postgres"
25 _ "github.com/jinzhu/gorm/dialects/sqlite"
26
27 _ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
28 ctrl "sigs.k8s.io/controller-runtime"
29 "sigs.k8s.io/controller-runtime/pkg/log/zap"
30
31 "github.com/chaos-mesh/chaos-mesh/pkg/apiserver"
32 "github.com/chaos-mesh/chaos-mesh/pkg/collector"
33 config "github.com/chaos-mesh/chaos-mesh/pkg/config/dashboard"
34 "github.com/chaos-mesh/chaos-mesh/pkg/store"
35 "github.com/chaos-mesh/chaos-mesh/pkg/store/dbstore"
36 "github.com/chaos-mesh/chaos-mesh/pkg/ttlcontroller"
37 "github.com/chaos-mesh/chaos-mesh/pkg/version"
38 )
39
40 var (
41 log = ctrl.Log.WithName("dashboard")
42 )
43
44 var (
45 printVersion bool
46 )
47
48
49
50
51
52
53
54
55
56
57
58
59 func main() {
60 flag.BoolVar(&printVersion, "version", false, "print version information and exit")
61 flag.Parse()
62
63 version.PrintVersionInfo("Chaos Dashboard")
64 if printVersion {
65 os.Exit(0)
66 }
67
68 ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
69 mainLog := log.WithName("main")
70
71 dashboardConfig, err := config.GetChaosDashboardEnv()
72 if err != nil {
73 mainLog.Error(err, "invalid ChaosDashboardConfig")
74 os.Exit(1)
75 }
76 dashboardConfig.Version = version.Get().GitVersion
77
78 persistTTLConfigParsed, err := config.ParsePersistTTLConfig(dashboardConfig.PersistTTL)
79 if err != nil {
80 mainLog.Error(err, "invalid PersistTTLConfig")
81 os.Exit(1)
82 }
83
84 ctrlRuntimeStopCh := ctrl.SetupSignalHandler()
85 app := fx.New(
86 fx.Provide(
87 func() (<-chan struct{}, *config.ChaosDashboardConfig, *ttlcontroller.TTLconfig) {
88 return ctrlRuntimeStopCh, dashboardConfig, persistTTLConfigParsed
89 },
90 dbstore.NewDBStore,
91 collector.NewServer,
92 ttlcontroller.NewController,
93 ),
94 store.Module,
95 apiserver.Module,
96 fx.Invoke(collector.Register),
97 fx.Invoke(ttlcontroller.Register),
98 )
99
100 app.Run()
101 }
102