...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package remotechaosmonitor
17
18 import (
19 "github.com/go-logr/logr"
20 "go.uber.org/fx"
21 ctrl "sigs.k8s.io/controller-runtime"
22 "sigs.k8s.io/controller-runtime/pkg/client"
23
24 "github.com/chaos-mesh/chaos-mesh/controllers/config"
25 "github.com/chaos-mesh/chaos-mesh/controllers/types"
26 "github.com/chaos-mesh/chaos-mesh/controllers/utils/builder"
27 )
28
29 type Params struct {
30 fx.In
31
32 Mgr ctrl.Manager
33 ManageClient client.Client `name:"manage-client"`
34 LocalClient client.Client
35 ClusterName string `name:"cluster-name"`
36 Logger logr.Logger
37 Objs []types.Object `group:"objs"`
38 }
39
40 func Bootstrap(params Params) error {
41 logger := params.Logger
42 mgr := params.Mgr
43 objs := params.Objs
44 setupLog := logger.WithName("setup-remotechaosmonitor")
45
46 for _, obj := range objs {
47 name := obj.Name + "-remotechaos-monitor"
48
49 if !config.ShouldSpawnController(name) {
50 return nil
51 }
52
53 setupLog.Info("setting up controller", "resource-name", obj.Name)
54
55
56 builder := builder.Default(mgr).
57 For(obj.Object).
58 Named(obj.Name + "-remotechaos-monitor")
59
60 err := builder.Complete(New(obj.Object, params.ManageClient, params.ClusterName, params.LocalClient, params.Logger))
61
62 if err != nil {
63 return err
64 }
65
66 }
67 return nil
68 }
69
70 var Module = fx.Options(
71 fx.Invoke(Bootstrap),
72 )
73