@@ -19,6 +19,7 @@ package multicluster
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "strings"
22
23
"sync"
23
24
24
25
"github.com/go-logr/logr"
@@ -142,6 +143,7 @@ func (mcc *multiClusterClient) Create(ctx context.Context, obj client.Object, op
142
143
// Get cluster info from context or labels, and delete it from labels because we should not write it into apiserver
143
144
cluster , err = getThenDeleteCluster (ctx , obj .GetLabels ())
144
145
if err != nil {
146
+ metrics .NewInvalidClusterCounterMetrics ("Create" , cluster )
145
147
mcc .log .Error (err , "failed to get cluster" )
146
148
return err
147
149
}
@@ -155,6 +157,7 @@ func (mcc *multiClusterClient) Create(ctx context.Context, obj client.Object, op
155
157
156
158
clusterClient , ok := mcc .clusterToClient [cluster ]
157
159
if ! ok {
160
+ metrics .NewInvalidClusterCounterMetrics ("Create" , cluster )
158
161
return fmt .Errorf ("unable to create: %v because of unknown cluster: %s for the client" , obj , cluster )
159
162
}
160
163
return clusterClient .Create (ctx , obj , opts ... )
@@ -169,6 +172,7 @@ func (mcc *multiClusterClient) Delete(ctx context.Context, obj client.Object, op
169
172
170
173
cluster , err = getCluster (ctx , obj .GetLabels ())
171
174
if err != nil {
175
+ metrics .NewInvalidClusterCounterMetrics ("Delete" , cluster )
172
176
mcc .log .Error (err , "failed to get cluster" )
173
177
return err
174
178
}
@@ -182,6 +186,7 @@ func (mcc *multiClusterClient) Delete(ctx context.Context, obj client.Object, op
182
186
183
187
clusterClient , ok := mcc .clusterToClient [cluster ]
184
188
if ! ok {
189
+ metrics .NewInvalidClusterCounterMetrics ("Delete" , cluster )
185
190
return fmt .Errorf ("unable to delete: %v because of unknown cluster: %s for the client" , obj , cluster )
186
191
}
187
192
return clusterClient .Delete (ctx , obj , opts ... )
@@ -195,6 +200,7 @@ func (mcc *multiClusterClient) DeleteAllOf(ctx context.Context, obj client.Objec
195
200
196
201
cluster , err = getCluster (ctx , obj .GetLabels ())
197
202
if err != nil {
203
+ metrics .NewInvalidClusterCounterMetrics ("DeleteAllOf" , cluster )
198
204
mcc .log .Error (err , "failed to get cluster" )
199
205
return err
200
206
}
@@ -208,6 +214,7 @@ func (mcc *multiClusterClient) DeleteAllOf(ctx context.Context, obj client.Objec
208
214
209
215
clusterClient , ok := mcc .clusterToClient [cluster ]
210
216
if ! ok {
217
+ metrics .NewInvalidClusterCounterMetrics ("DeleteAllOf" , cluster )
211
218
err = fmt .Errorf ("unable to deleteAllOf: %v because of unknown cluster: %s for the client" , obj , cluster )
212
219
return
213
220
}
@@ -226,6 +233,7 @@ func (mcc *multiClusterClient) Get(ctx context.Context, key types.NamespacedName
226
233
227
234
cluster , err = getCluster (ctx , obj .GetLabels ())
228
235
if err != nil {
236
+ metrics .NewInvalidClusterCounterMetrics ("Get" , cluster )
229
237
mcc .log .Error (err , "failed to get cluster" )
230
238
return err
231
239
}
@@ -239,6 +247,7 @@ func (mcc *multiClusterClient) Get(ctx context.Context, key types.NamespacedName
239
247
240
248
clusterClient , ok := mcc .clusterToClient [cluster ]
241
249
if ! ok {
250
+ metrics .NewInvalidClusterCounterMetrics ("Get" , cluster )
242
251
return fmt .Errorf ("unable to get: %v because of unknown cluster: %s for the client" , obj , cluster )
243
252
}
244
253
return clusterClient .Get (ctx , key , obj )
@@ -251,6 +260,7 @@ func (mcc *multiClusterClient) List(ctx context.Context, list client.ObjectList,
251
260
252
261
clusters , err := mcc .getClusterNames (ctx )
253
262
if err != nil {
263
+ metrics .NewInvalidClusterCounterMetrics ("List" , strings .Join (clusters , "," ))
254
264
mcc .log .Error (err , "failed to get clusters" )
255
265
return err
256
266
}
@@ -273,6 +283,7 @@ func (mcc *multiClusterClient) List(ctx context.Context, list client.ObjectList,
273
283
var ok bool
274
284
c , ok = mcc .clusterToClient [cluster ]
275
285
if ! ok {
286
+ metrics .NewInvalidClusterCounterMetrics ("List" , cluster )
276
287
return fmt .Errorf ("unable to list because of unknown cluster: %s for the client" , cluster )
277
288
}
278
289
}
@@ -314,6 +325,7 @@ func (mcc *multiClusterClient) Patch(ctx context.Context, obj client.Object, pat
314
325
// Get cluster info from context or labels, and delete it from labels because we should not write it into apiserver
315
326
cluster , err = getThenDeleteCluster (ctx , obj .GetLabels ())
316
327
if err != nil {
328
+ metrics .NewInvalidClusterCounterMetrics ("Patch" , cluster )
317
329
mcc .log .Error (err , "failed to get cluster" )
318
330
return err
319
331
}
@@ -327,6 +339,7 @@ func (mcc *multiClusterClient) Patch(ctx context.Context, obj client.Object, pat
327
339
328
340
clusterClient , ok := mcc .clusterToClient [cluster ]
329
341
if ! ok {
342
+ metrics .NewInvalidClusterCounterMetrics ("Patch" , cluster )
330
343
return fmt .Errorf ("unable to patch: %v because of unknown cluster: %v for the client" , obj , cluster )
331
344
}
332
345
return clusterClient .Patch (ctx , obj , patch , opts ... )
@@ -342,6 +355,7 @@ func (mcc *multiClusterClient) Update(ctx context.Context, obj client.Object, op
342
355
// Get cluster info from context or labels, and delete it from labels because we should not write it into apiserver
343
356
cluster , err = getThenDeleteCluster (ctx , obj .GetLabels ())
344
357
if err != nil {
358
+ metrics .NewInvalidClusterCounterMetrics ("Update" , cluster )
345
359
mcc .log .Error (err , "failed to get cluster" )
346
360
return err
347
361
}
@@ -355,6 +369,7 @@ func (mcc *multiClusterClient) Update(ctx context.Context, obj client.Object, op
355
369
356
370
clusterClient , ok := mcc .clusterToClient [cluster ]
357
371
if ! ok {
372
+ metrics .NewInvalidClusterCounterMetrics ("Update" , cluster )
358
373
err = fmt .Errorf ("unable to update: %v because of unknown cluster: %s for the client" , obj , cluster )
359
374
return
360
375
}
@@ -393,6 +408,7 @@ func (sw *statusWriter) Update(ctx context.Context, obj client.Object, opts ...c
393
408
// Get cluster info from context or labels, and delete it from labels because we should not write it into apiserver
394
409
cluster , err = getThenDeleteCluster (ctx , obj .GetLabels ())
395
410
if err != nil {
411
+ metrics .NewInvalidClusterCounterMetrics ("StatusUpdate" , cluster )
396
412
sw .log .Error (err , "failed to get cluster" )
397
413
return err
398
414
}
@@ -403,6 +419,7 @@ func (sw *statusWriter) Update(ctx context.Context, obj client.Object, opts ...c
403
419
404
420
clusterClient , ok := sw .clusterToClient [cluster ]
405
421
if ! ok {
422
+ metrics .NewInvalidClusterCounterMetrics ("StatusUpdate" , cluster )
406
423
return fmt .Errorf ("unable to update: %v because of unknown cluster: %s for the client" , obj , cluster )
407
424
}
408
425
return clusterClient .Status ().Update (ctx , obj , opts ... )
@@ -418,6 +435,7 @@ func (sw *statusWriter) Patch(ctx context.Context, obj client.Object, patch clie
418
435
// Get cluster info from context or labels, and delete it from labels because we should not write it into apiserver
419
436
cluster , err = getThenDeleteCluster (ctx , obj .GetLabels ())
420
437
if err != nil {
438
+ metrics .NewInvalidClusterCounterMetrics ("StatusPatch" , cluster )
421
439
sw .log .Error (err , "failed to get cluster" )
422
440
return err
423
441
}
@@ -428,6 +446,7 @@ func (sw *statusWriter) Patch(ctx context.Context, obj client.Object, patch clie
428
446
429
447
clusterClient , ok := sw .clusterToClient [cluster ]
430
448
if ! ok {
449
+ metrics .NewInvalidClusterCounterMetrics ("StatusPatch" , cluster )
431
450
return fmt .Errorf ("unable to update: %v because of unknown cluster: %s for the client" , obj , cluster )
432
451
}
433
452
return clusterClient .Status ().Patch (ctx , obj , patch , opts ... )
0 commit comments