...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package config
15
16 import (
17 "time"
18
19 "github.com/kelseyhightower/envconfig"
20
21 "github.com/chaos-mesh/chaos-mesh/pkg/ttlcontroller"
22 )
23
24
25 type ChaosDashboardConfig struct {
26 ListenHost string `envconfig:"LISTEN_HOST" default:"0.0.0.0" json:"listen_host"`
27 ListenPort int `envconfig:"LISTEN_PORT" default:"2333" json:"listen_port"`
28 MetricAddress string `envconfig:"METRIC_ADDRESS" json:"-"`
29 EnableLeaderElection bool `envconfig:"ENABLE_LEADER_ELECTION" json:"-"`
30 Database *DatabaseConfig `json:"-"`
31 PersistTTL *PersistTTLConfig `json:"-"`
32
33 ClusterScoped bool `envconfig:"CLUSTER_SCOPED" default:"true" json:"cluster_mode"`
34
35
36 TargetNamespace string `envconfig:"TARGET_NAMESPACE" default:"" json:"target_namespace"`
37
38
39 EnableFilterNamespace bool `envconfig:"ENABLE_FILTER_NAMESPACE" default:"false"`
40
41
42 SecurityMode bool `envconfig:"SECURITY_MODE" default:"true" json:"security_mode"`
43 DNSServerCreate bool `envconfig:"DNS_SERVER_CREATE" default:"false" json:"dns_server_create"`
44 Version string `json:"version"`
45 }
46
47
48 type PersistTTLConfig struct {
49 SyncPeriod string `envconfig:"CLEAN_SYNC_PERIOD" default:"12h"`
50 Event string `envconfig:"TTL_EVENT" default:"168h"`
51 Experiment string `envconfig:"TTL_EXPERIMENT" default:"336h"`
52 }
53
54
55 type DatabaseConfig struct {
56
57 Archive bool
58 Driver string `envconfig:"DATABASE_DRIVER" default:"sqlite3"`
59 Datasource string `envconfig:"DATABASE_DATASOURCE" default:"core.sqlite"`
60 Secret string `envconfig:"DATABASE_SECRET"`
61 }
62
63
64 func EnvironChaosDashboard() (*ChaosDashboardConfig, error) {
65 cfg := ChaosDashboardConfig{}
66 err := envconfig.Process("", &cfg)
67 return &cfg, err
68 }
69
70
71 func ParsePersistTTLConfig(config *PersistTTLConfig) (*ttlcontroller.TTLconfig, error) {
72 SyncPeriod, err := time.ParseDuration(config.SyncPeriod)
73 if err != nil {
74 return nil, err
75 }
76
77 Event, err := time.ParseDuration(config.Event)
78 if err != nil {
79 return nil, err
80 }
81
82 Experiment, err := time.ParseDuration(config.Experiment)
83 if err != nil {
84 return nil, err
85 }
86
87 return &ttlcontroller.TTLconfig{
88 DatabaseTTLResyncPeriod: SyncPeriod,
89 EventTTL: Event,
90 ArchiveExperimentTTL: Experiment,
91 }, nil
92 }
93