forked from chaos-mesh/chaos-mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
101 lines (83 loc) · 2.77 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// Copyright 2020 Chaos Mesh Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"flag"
"os"
"go.uber.org/fx"
_ "github.com/jinzhu/gorm/dialects/mssql"
_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"github.com/chaos-mesh/chaos-mesh/pkg/apiserver"
"github.com/chaos-mesh/chaos-mesh/pkg/collector"
config "github.com/chaos-mesh/chaos-mesh/pkg/config/dashboard"
"github.com/chaos-mesh/chaos-mesh/pkg/store"
"github.com/chaos-mesh/chaos-mesh/pkg/store/dbstore"
"github.com/chaos-mesh/chaos-mesh/pkg/ttlcontroller"
"github.com/chaos-mesh/chaos-mesh/pkg/version"
)
var (
log = ctrl.Log.WithName("dashboard")
)
var (
printVersion bool
)
// @title Chaos Mesh Dashboard API
// @version 2.0
// @description Swagger docs for Chaos Mesh Dashboard. If you encounter any problems with API, please click on the issues link below to report bugs or questions.
// @contact.name Issues
// @contact.url https://github.com/chaos-mesh/chaos-mesh/issues
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @BasePath /api
func main() {
flag.BoolVar(&printVersion, "version", false, "print version information and exit")
flag.Parse()
version.PrintVersionInfo("Chaos Dashboard")
if printVersion {
os.Exit(0)
}
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
mainLog := log.WithName("main")
dashboardConfig, err := config.GetChaosDashboardEnv()
if err != nil {
mainLog.Error(err, "invalid ChaosDashboardConfig")
os.Exit(1)
}
dashboardConfig.Version = version.Get().GitVersion
persistTTLConfigParsed, err := config.ParsePersistTTLConfig(dashboardConfig.PersistTTL)
if err != nil {
mainLog.Error(err, "invalid PersistTTLConfig")
os.Exit(1)
}
ctrlRuntimeStopCh := ctrl.SetupSignalHandler()
app := fx.New(
fx.Provide(
func() (<-chan struct{}, *config.ChaosDashboardConfig, *ttlcontroller.TTLconfig) {
return ctrlRuntimeStopCh, dashboardConfig, persistTTLConfigParsed
},
dbstore.NewDBStore,
collector.NewServer,
ttlcontroller.NewController,
),
store.Module,
apiserver.Module,
fx.Invoke(collector.Register),
fx.Invoke(ttlcontroller.Register),
)
app.Run()
}