...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package podnetworkchaos
17
18 import (
19 "reflect"
20
21 "github.com/go-logr/logr"
22 ctrl "sigs.k8s.io/controller-runtime"
23 "sigs.k8s.io/controller-runtime/pkg/client"
24 "sigs.k8s.io/controller-runtime/pkg/event"
25 "sigs.k8s.io/controller-runtime/pkg/predicate"
26
27 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
28 "github.com/chaos-mesh/chaos-mesh/controllers/config"
29 "github.com/chaos-mesh/chaos-mesh/controllers/utils/builder"
30 "github.com/chaos-mesh/chaos-mesh/controllers/utils/chaosdaemon"
31 "github.com/chaos-mesh/chaos-mesh/controllers/utils/recorder"
32 )
33
34 func Bootstrap(mgr ctrl.Manager, client client.Client, logger logr.Logger, b *chaosdaemon.ChaosDaemonClientBuilder, recorderBuilder *recorder.RecorderBuilder) error {
35 if !config.ShouldSpawnController("podnetworkchaos") {
36 return nil
37 }
38
39 return builder.Default(mgr).
40 For(&v1alpha1.PodNetworkChaos{}).
41 Named("podnetworkchaos").
42 WithEventFilter(predicate.Funcs{
43 UpdateFunc: func(e event.UpdateEvent) bool {
44 oldObj := e.ObjectOld.(*v1alpha1.PodNetworkChaos)
45 newObj := e.ObjectNew.(*v1alpha1.PodNetworkChaos)
46
47 return !reflect.DeepEqual(oldObj.Spec, newObj.Spec)
48 },
49 }).
50 Complete(&Reconciler{
51 Client: client,
52 Log: logger.WithName("podnetworkchaos"),
53 Recorder: recorderBuilder.Build("podnetworkchaos"),
54
55
56 AllowHostNetworkTesting: config.ControllerCfg.AllowHostNetworkTesting,
57 ChaosDaemonClientBuilder: b,
58 })
59 }
60