...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package podnetworkchaosmanager
17
18 import (
19 "github.com/go-logr/logr"
20 "go.uber.org/fx"
21 "k8s.io/apimachinery/pkg/runtime"
22 "k8s.io/apimachinery/pkg/types"
23 "sigs.k8s.io/controller-runtime/pkg/client"
24 )
25
26 type Builder struct {
27 Log logr.Logger
28 client.Client
29 client.Reader
30 scheme *runtime.Scheme
31 }
32
33 type Params struct {
34 fx.In
35
36 Logger logr.Logger
37 Client client.Client
38 Reader client.Reader `name:"no-cache"`
39 Scheme *runtime.Scheme
40 }
41
42 func NewBuilder(params Params) *Builder {
43 return &Builder{
44 Log: params.Logger,
45 Client: params.Client,
46 Reader: params.Reader,
47 scheme: params.Scheme,
48 }
49 }
50
51 func (b *Builder) Build(source string, key types.NamespacedName) *PodNetworkManager {
52 t := &PodNetworkTransaction{}
53
54 return &PodNetworkManager{
55 Source: source,
56 Log: b.Log,
57 Client: b.Client,
58 Reader: b.Reader,
59 scheme: b.scheme,
60
61 Key: key,
62 T: t,
63 }
64 }
65
66 func (b *Builder) WithInit(source string, key types.NamespacedName) *PodNetworkManager {
67 t := &PodNetworkTransaction{}
68 t.Clear(source)
69
70 return &PodNetworkManager{
71 Source: source,
72 Log: b.Log,
73 Client: b.Client,
74 Reader: b.Reader,
75 scheme: b.scheme,
76
77 Key: key,
78 T: t,
79 }
80 }
81