@@ -11,69 +11,42 @@ import (
11
11
)
12
12
13
13
type (
14
- // GetFn is a function that can be used to intercept GET calls.
15
- GetFn func (ctx context.Context , client client.WithWatch , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) error
16
- // ListFn is a function that can be used to intercept LIST calls.
17
- ListFn func (ctx context.Context , client client.WithWatch , list client.ObjectList , opts ... client.ListOption ) error
18
- // CreateFn is a function that can be used to intercept CREATE calls.
19
- CreateFn func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.CreateOption ) error
20
- // DeleteFn is a function that can be used to intercept DELETE calls.
21
- DeleteFn func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteOption ) error
22
- // DeleteAllOfFn is a function that can be used to intercept Collection DELETE calls.
23
- DeleteAllOfFn func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteAllOfOption ) error
24
- // UpdateFn is a function that can be used to intercept UPDATE calls.
25
- UpdateFn func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.UpdateOption ) error
26
- // PatchFn is a function that can be used to intercept PATCH calls.
27
- PatchFn func (ctx context.Context , client client.WithWatch , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error
28
- // WatchFn is a function that can be used to intercept WATCH calls.
29
- WatchFn func (ctx context.Context , client client.WithWatch , obj client.ObjectList , opts ... client.ListOption ) (watch.Interface , error )
30
- // SubResourceFn is a function that can be used to intercept SubResource calls.
31
- SubResourceFn func (client client.WithWatch , subResource string ) client.SubResourceClient
32
-
33
- // SubResourceGetFn is a function that can be used to intercept SubResource GET calls.
34
- SubResourceGetFn func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceGetOption ) error
35
- // SubResourceCreateFn is a function that can be used to intercept SubResource CREATE calls.
36
- SubResourceCreateFn func (ctx context.Context , client client.SubResourceClient , obj client.Object , subResource client.Object , opts ... client.SubResourceCreateOption ) error
37
- // SubResourceUpdateFn is a function that can be used to intercept SubResource UPDATE calls.
38
- SubResourceUpdateFn func (ctx context.Context , client client.SubResourceClient , obj client.Object , opts ... client.SubResourceUpdateOption ) error
39
- // SubResourcePatchFn is a function that can be used to intercept SubResource PATCH calls.
40
- SubResourcePatchFn func (ctx context.Context , client client.SubResourceClient , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error
41
-
42
- // Fns contains functions that are called instead of the underlying client's methods.
43
- Fns struct {
44
- Get GetFn
45
- List ListFn
46
- Create CreateFn
47
- Delete DeleteFn
48
- DeleteAllOf DeleteAllOfFn
49
- Update UpdateFn
50
- Patch PatchFn
51
- Watch WatchFn
52
- SubResource SubResourceFn
14
+
15
+ // Funcs contains functions that are called instead of the underlying client's methods.
16
+ Funcs struct {
17
+ Get func (ctx context.Context , client client.WithWatch , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) error
18
+ List func (ctx context.Context , client client.WithWatch , list client.ObjectList , opts ... client.ListOption ) error
19
+ Create func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.CreateOption ) error
20
+ Delete func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteOption ) error
21
+ DeleteAllOf func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.DeleteAllOfOption ) error
22
+ Update func (ctx context.Context , client client.WithWatch , obj client.Object , opts ... client.UpdateOption ) error
23
+ Patch func (ctx context.Context , client client.WithWatch , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error
24
+ Watch func (ctx context.Context , client client.WithWatch , obj client.ObjectList , opts ... client.ListOption ) (watch.Interface , error )
25
+ SubResource func (client client.WithWatch , subResource string ) client.SubResourceClient
53
26
}
54
27
55
- // SubResourceFns is a set of functions that can be used to intercept calls to a SubResourceClient.
56
- SubResourceFns struct {
57
- Get SubResourceGetFn
58
- Create SubResourceCreateFn
59
- Update SubResourceUpdateFn
60
- Patch SubResourcePatchFn
28
+ // SubResourceFuncs is a set of functions that can be used to intercept calls to a SubResourceClient.
29
+ SubResourceFuncs struct {
30
+ Get func ( ctx context. Context , client client. SubResourceClient , obj client. Object , subResource client. Object , opts ... client. SubResourceGetOption ) error
31
+ Create func ( ctx context. Context , client client. SubResourceClient , obj client. Object , subResource client. Object , opts ... client. SubResourceCreateOption ) error
32
+ Update func ( ctx context. Context , client client. SubResourceClient , obj client. Object , opts ... client. SubResourceUpdateOption ) error
33
+ Patch func ( ctx context. Context , client client. SubResourceClient , obj client. Object , patch client. Patch , opts ... client. SubResourcePatchOption ) error
61
34
}
62
35
)
63
36
64
- // NewClient returns a new interceptor client that calls the functions in fns instead of the underlying client's methods, if they are not nil.
65
- func NewClient (interceptedClient client.WithWatch , fns Fns ) client.WithWatch {
66
- return interceptor {client : interceptedClient , fns : fns }
37
+ // NewClient returns a new interceptor client that calls the functions in funcs instead of the underlying client's methods, if they are not nil.
38
+ func NewClient (interceptedClient client.WithWatch , funcs Funcs ) client.WithWatch {
39
+ return interceptor {client : interceptedClient , funcs : funcs }
67
40
}
68
41
69
42
// NewSubResourceClient returns a SubResourceClient that intercepts calls to the provided client with the provided functions.
70
- func NewSubResourceClient (interceptedClient client.SubResourceClient , fns SubResourceFns ) client.SubResourceClient {
71
- return subResourceInterceptor {client : interceptedClient , fns : fns }
43
+ func NewSubResourceClient (interceptedClient client.SubResourceClient , funcs SubResourceFuncs ) client.SubResourceClient {
44
+ return subResourceInterceptor {client : interceptedClient , funcs : funcs }
72
45
}
73
46
74
47
type interceptor struct {
75
48
client client.WithWatch
76
- fns Fns
49
+ funcs Funcs
77
50
}
78
51
79
52
var _ client.WithWatch = & interceptor {}
@@ -87,50 +60,50 @@ func (c interceptor) IsObjectNamespaced(obj runtime.Object) (bool, error) {
87
60
}
88
61
89
62
func (c interceptor ) Get (ctx context.Context , key client.ObjectKey , obj client.Object , opts ... client.GetOption ) error {
90
- if c .fns .Get != nil {
91
- return c .fns .Get (ctx , c .client , key , obj , opts ... )
63
+ if c .funcs .Get != nil {
64
+ return c .funcs .Get (ctx , c .client , key , obj , opts ... )
92
65
}
93
66
return c .client .Get (ctx , key , obj , opts ... )
94
67
}
95
68
96
69
func (c interceptor ) List (ctx context.Context , list client.ObjectList , opts ... client.ListOption ) error {
97
- if c .fns .List != nil {
98
- return c .fns .List (ctx , c .client , list , opts ... )
70
+ if c .funcs .List != nil {
71
+ return c .funcs .List (ctx , c .client , list , opts ... )
99
72
}
100
73
return c .client .List (ctx , list , opts ... )
101
74
}
102
75
103
76
func (c interceptor ) Create (ctx context.Context , obj client.Object , opts ... client.CreateOption ) error {
104
- if c .fns .Create != nil {
105
- return c .fns .Create (ctx , c .client , obj , opts ... )
77
+ if c .funcs .Create != nil {
78
+ return c .funcs .Create (ctx , c .client , obj , opts ... )
106
79
}
107
80
return c .client .Create (ctx , obj , opts ... )
108
81
}
109
82
110
83
func (c interceptor ) Delete (ctx context.Context , obj client.Object , opts ... client.DeleteOption ) error {
111
- if c .fns .Delete != nil {
112
- return c .fns .Delete (ctx , c .client , obj , opts ... )
84
+ if c .funcs .Delete != nil {
85
+ return c .funcs .Delete (ctx , c .client , obj , opts ... )
113
86
}
114
87
return c .client .Delete (ctx , obj , opts ... )
115
88
}
116
89
117
90
func (c interceptor ) Update (ctx context.Context , obj client.Object , opts ... client.UpdateOption ) error {
118
- if c .fns .Update != nil {
119
- return c .fns .Update (ctx , c .client , obj , opts ... )
91
+ if c .funcs .Update != nil {
92
+ return c .funcs .Update (ctx , c .client , obj , opts ... )
120
93
}
121
94
return c .client .Update (ctx , obj , opts ... )
122
95
}
123
96
124
97
func (c interceptor ) Patch (ctx context.Context , obj client.Object , patch client.Patch , opts ... client.PatchOption ) error {
125
- if c .fns .Patch != nil {
126
- return c .fns .Patch (ctx , c .client , obj , patch , opts ... )
98
+ if c .funcs .Patch != nil {
99
+ return c .funcs .Patch (ctx , c .client , obj , patch , opts ... )
127
100
}
128
101
return c .client .Patch (ctx , obj , patch , opts ... )
129
102
}
130
103
131
104
func (c interceptor ) DeleteAllOf (ctx context.Context , obj client.Object , opts ... client.DeleteAllOfOption ) error {
132
- if c .fns .DeleteAllOf != nil {
133
- return c .fns .DeleteAllOf (ctx , c .client , obj , opts ... )
105
+ if c .funcs .DeleteAllOf != nil {
106
+ return c .funcs .DeleteAllOf (ctx , c .client , obj , opts ... )
134
107
}
135
108
return c .client .DeleteAllOf (ctx , obj , opts ... )
136
109
}
@@ -140,8 +113,8 @@ func (c interceptor) Status() client.SubResourceWriter {
140
113
}
141
114
142
115
func (c interceptor ) SubResource (subResource string ) client.SubResourceClient {
143
- if c .fns .SubResource != nil {
144
- return c .fns .SubResource (c .client , subResource )
116
+ if c .funcs .SubResource != nil {
117
+ return c .funcs .SubResource (c .client , subResource )
145
118
}
146
119
return c .client .SubResource (subResource )
147
120
}
@@ -155,43 +128,43 @@ func (c interceptor) RESTMapper() meta.RESTMapper {
155
128
}
156
129
157
130
func (c interceptor ) Watch (ctx context.Context , obj client.ObjectList , opts ... client.ListOption ) (watch.Interface , error ) {
158
- if c .fns .Watch != nil {
159
- return c .fns .Watch (ctx , c .client , obj , opts ... )
131
+ if c .funcs .Watch != nil {
132
+ return c .funcs .Watch (ctx , c .client , obj , opts ... )
160
133
}
161
134
return c .client .Watch (ctx , obj , opts ... )
162
135
}
163
136
164
137
type subResourceInterceptor struct {
165
138
client client.SubResourceClient
166
- fns SubResourceFns
139
+ funcs SubResourceFuncs
167
140
}
168
141
169
142
var _ client.SubResourceClient = & subResourceInterceptor {}
170
143
171
144
func (s subResourceInterceptor ) Get (ctx context.Context , obj client.Object , subResource client.Object , opts ... client.SubResourceGetOption ) error {
172
- if s .fns .Get != nil {
173
- return s .fns .Get (ctx , s .client , obj , subResource , opts ... )
145
+ if s .funcs .Get != nil {
146
+ return s .funcs .Get (ctx , s .client , obj , subResource , opts ... )
174
147
}
175
148
return s .client .Get (ctx , obj , subResource , opts ... )
176
149
}
177
150
178
151
func (s subResourceInterceptor ) Create (ctx context.Context , obj client.Object , subResource client.Object , opts ... client.SubResourceCreateOption ) error {
179
- if s .fns .Create != nil {
180
- return s .fns .Create (ctx , s .client , obj , subResource , opts ... )
152
+ if s .funcs .Create != nil {
153
+ return s .funcs .Create (ctx , s .client , obj , subResource , opts ... )
181
154
}
182
155
return s .client .Create (ctx , obj , subResource , opts ... )
183
156
}
184
157
185
158
func (s subResourceInterceptor ) Update (ctx context.Context , obj client.Object , opts ... client.SubResourceUpdateOption ) error {
186
- if s .fns .Update != nil {
187
- return s .fns .Update (ctx , s .client , obj , opts ... )
159
+ if s .funcs .Update != nil {
160
+ return s .funcs .Update (ctx , s .client , obj , opts ... )
188
161
}
189
162
return s .client .Update (ctx , obj , opts ... )
190
163
}
191
164
192
165
func (s subResourceInterceptor ) Patch (ctx context.Context , obj client.Object , patch client.Patch , opts ... client.SubResourcePatchOption ) error {
193
- if s .fns .Patch != nil {
194
- return s .fns .Patch (ctx , s .client , obj , patch , opts ... )
166
+ if s .funcs .Patch != nil {
167
+ return s .funcs .Patch (ctx , s .client , obj , patch , opts ... )
195
168
}
196
169
return s .client .Patch (ctx , obj , patch , opts ... )
197
170
}
0 commit comments