/
queues.go
534 lines (480 loc) · 20.7 KB
/
queues.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
package operator
import (
"reflect"
"time"
_ "github.com/prestodb/presto-go-client/presto"
log "github.com/sirupsen/logrus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
_ "k8s.io/client-go/plugin/pkg/client/auth/oidc"
"k8s.io/client-go/tools/cache"
"k8s.io/client-go/util/workqueue"
metering "github.com/operator-framework/operator-metering/pkg/apis/metering/v1"
_ "github.com/operator-framework/operator-metering/pkg/util/reflector/prometheus" // for prometheus metric registration
_ "github.com/operator-framework/operator-metering/pkg/util/workqueue/prometheus" // for prometheus metric registration
)
func (op *Reporting) shutdownQueues() {
for _, queue := range op.queueList {
queue.ShutDown()
}
}
func (op *Reporting) addReport(obj interface{}) {
report := obj.(*metering.Report)
if report.DeletionTimestamp != nil {
op.deleteReport(report)
return
}
op.logger.Infof("adding Report %s/%s", report.Namespace, report.Name)
op.enqueueReport(report)
}
func (op *Reporting) updateReport(prev, cur interface{}) {
prevReport := prev.(*metering.Report)
curReport := cur.(*metering.Report)
if curReport.DeletionTimestamp != nil {
op.deleteReport(curReport)
return
}
if curReport.ResourceVersion == prevReport.ResourceVersion {
// Periodic resyncs will send update events for all known Reports.
// Two different versions of the same report will always have
// different ResourceVersions.
op.logger.Debugf("Report %s/%s resourceVersion is unchanged, skipping update", curReport.Namespace, curReport.Name)
return
}
if reflect.DeepEqual(prevReport.Spec, curReport.Spec) {
op.logger.Debugf("Report %s/%s spec is unchanged, skipping update", curReport.Namespace, curReport.Name)
return
}
op.logger.Infof("updating Report %s/%s", curReport.Namespace, curReport.Name)
op.enqueueReport(curReport)
}
func (op *Reporting) deleteReport(obj interface{}) {
report, ok := obj.(*metering.Report)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
op.logger.WithFields(log.Fields{"report": report.Name, "namespace": report.Namespace}).Errorf("Couldn't get object from tombstone %#v", obj)
return
}
report, ok = tombstone.Obj.(*metering.Report)
if !ok {
op.logger.WithFields(log.Fields{"report": report.Name, "namespace": report.Namespace}).Errorf("Tombstone contained object that is not a Report %#v", obj)
return
}
}
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(report)
if err != nil {
op.logger.WithFields(log.Fields{"report": report.Name, "namespace": report.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", report)
return
}
op.reportQueue.Add(key)
}
func (op *Reporting) enqueueReport(report *metering.Report) {
key, err := cache.MetaNamespaceKeyFunc(report)
if err != nil {
op.logger.WithError(err).Errorf("Couldn't get key for object %#v: %v", report, err)
return
}
op.reportQueue.Add(key)
}
func (op *Reporting) enqueueReportAfter(report *metering.Report, duration time.Duration) {
key, err := cache.MetaNamespaceKeyFunc(report)
if err != nil {
op.logger.WithError(err).Errorf("Couldn't get key for object %#v: %v", report, err)
return
}
op.reportQueue.AddAfter(key, duration)
}
func (op *Reporting) addReportDataSource(obj interface{}) {
ds := obj.(*metering.ReportDataSource)
if ds.DeletionTimestamp != nil {
op.deleteReportDataSource(ds)
return
}
op.logger.Infof("adding ReportDataSource %s/%s", ds.Namespace, ds.Name)
op.enqueueReportDataSource(ds)
}
func (op *Reporting) updateReportDataSource(prev, cur interface{}) {
curReportDataSource := cur.(*metering.ReportDataSource)
prevReportDataSource := prev.(*metering.ReportDataSource)
if curReportDataSource.DeletionTimestamp != nil {
op.deleteReportDataSource(curReportDataSource)
return
}
// we allow periodic resyncs to trigger ReportDataSources even
// if they're not changed to ensure failed ones eventually get re-tried.
// however, if we know that it's a Prometheus ReportDataSource where the
// MetricImportStatus is all that changed, we can safely assume that this
// update came from the operator updating that field and we can ignore this
// update.
isProm := curReportDataSource.Spec.PrometheusMetricsImporter != nil
if isProm {
sameSpec := reflect.DeepEqual(curReportDataSource.Spec, prevReportDataSource.Spec)
importStatusChanged := !reflect.DeepEqual(curReportDataSource.Status.PrometheusMetricsImportStatus, prevReportDataSource.Status.PrometheusMetricsImportStatus)
if sameSpec && importStatusChanged {
return
}
}
op.logger.Infof("updating ReportDataSource %s/%s", curReportDataSource.Namespace, curReportDataSource.Name)
op.enqueueReportDataSource(curReportDataSource)
}
func (op *Reporting) deleteReportDataSource(obj interface{}) {
dataSource, ok := obj.(*metering.ReportDataSource)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
op.logger.WithFields(log.Fields{"reportDataSsource": dataSource.Name, "namespace": dataSource.Namespace}).Errorf("Couldn't get object from tombstone %#v", obj)
return
}
dataSource, ok = tombstone.Obj.(*metering.ReportDataSource)
if !ok {
op.logger.WithFields(log.Fields{"reportDataSsource": dataSource.Name, "namespace": dataSource.Namespace}).Errorf("Tombstone contained object that is not a ReportDataSource %#v", obj)
return
}
}
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(dataSource)
if err != nil {
op.logger.WithFields(log.Fields{"reportDataSsource": dataSource.Name, "namespace": dataSource.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", dataSource)
return
}
op.reportDataSourceQueue.Add(key)
}
func (op *Reporting) enqueueReportDataSource(ds *metering.ReportDataSource) {
key, err := cache.MetaNamespaceKeyFunc(ds)
if err != nil {
op.logger.WithFields(log.Fields{"reportDataSource": ds.Name, "namespace": ds.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", ds)
return
}
op.reportDataSourceQueue.Add(key)
}
func (op *Reporting) enqueueReportDataSourceAfter(ds *metering.ReportDataSource, duration time.Duration) {
key, err := cache.MetaNamespaceKeyFunc(ds)
if err != nil {
op.logger.WithFields(log.Fields{"reportDataSource": ds.Name, "namespace": ds.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", ds)
return
}
op.reportDataSourceQueue.AddAfter(key, duration)
}
func (op *Reporting) addReportQuery(obj interface{}) {
query := obj.(*metering.ReportQuery)
op.logger.Infof("adding ReportQuery %s/%s", query.Namespace, query.Name)
op.enqueueReportQuery(query)
}
func (op *Reporting) updateReportQuery(prev, cur interface{}) {
curReportQuery := cur.(*metering.ReportQuery)
prevReportQuery := prev.(*metering.ReportQuery)
logger := op.logger.WithFields(log.Fields{"reportQuery": curReportQuery.Name, "namespace": curReportQuery.Namespace})
// Only skip queuing if we're not missing a view
if curReportQuery.ResourceVersion == prevReportQuery.ResourceVersion {
// Periodic resyncs will send update events for all known ReportQuerys.
// Two different versions of the same reportQuery will always have
// different ResourceVersions.
logger.Debugf("ReportQuery %s/%s resourceVersion is unchanged, skipping update", curReportQuery.Namespace, curReportQuery.Name)
return
}
if reflect.DeepEqual(prevReportQuery.Spec, curReportQuery.Spec) {
logger.Debugf("ReportQuery %s/%s spec is unchanged, skipping update", curReportQuery.Namespace, curReportQuery.Name)
return
}
logger.Infof("updating ReportQuery %s/%s", curReportQuery.Namespace, curReportQuery.Name)
op.enqueueReportQuery(curReportQuery)
}
func (op *Reporting) enqueueReportQuery(query *metering.ReportQuery) {
key, err := cache.MetaNamespaceKeyFunc(query)
if err != nil {
op.logger.WithFields(log.Fields{"reportQuery": query.Name, "namespace": query.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", query)
return
}
op.reportQueryQueue.Add(key)
}
func (op *Reporting) addPrestoTable(obj interface{}) {
table := obj.(*metering.PrestoTable)
if table.DeletionTimestamp != nil {
op.deletePrestoTable(table)
return
}
logger := op.logger.WithFields(log.Fields{"prestoTable": table.Name, "namespace": table.Namespace})
logger.Infof("adding PrestoTable %s/%s", table.Namespace, table.Name)
op.enqueuePrestoTable(table)
}
func (op *Reporting) updatePrestoTable(_, cur interface{}) {
curPrestoTable := cur.(*metering.PrestoTable)
if curPrestoTable.DeletionTimestamp != nil {
op.deletePrestoTable(curPrestoTable)
return
}
logger := op.logger.WithFields(log.Fields{"prestoTable": curPrestoTable.Name, "namespace": curPrestoTable.Namespace})
logger.Infof("updating PrestoTable %s/%s", curPrestoTable.Namespace, curPrestoTable.Name)
op.enqueuePrestoTable(curPrestoTable)
}
func (op *Reporting) deletePrestoTable(obj interface{}) {
prestoTable, ok := obj.(*metering.PrestoTable)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
op.logger.WithFields(log.Fields{"prestoTable": prestoTable.Name, "namespace": prestoTable.Namespace}).Errorf("Couldn't get object from tombstone %#v", obj)
return
}
prestoTable, ok = tombstone.Obj.(*metering.PrestoTable)
if !ok {
op.logger.WithFields(log.Fields{"prestoTable": prestoTable.Name, "namespace": prestoTable.Namespace}).Errorf("Tombstone contained object that is not a PrestoTable %#v", obj)
return
}
}
// when finalizers aren't enabled, it's pretty likely by the time our
// worker get the event from the queue that the resource will no longer
// exist in our store, so we eagerly drop the table upon seeing the delete
// event when finalizers are disabled
if !op.cfg.EnableFinalizers && prestoTable != nil {
err := op.dropPrestoTable(prestoTable)
if err != nil {
op.logger.WithFields(log.Fields{"prestoTable": prestoTable.Name, "namespace": prestoTable.Namespace}).WithError(err).Errorf("couldn't drop PrestoTable: %#v", prestoTable)
return
}
_, err = op.removePrestoTableFinalizer(prestoTable)
if err != nil {
op.logger.WithFields(log.Fields{"prestoTable": prestoTable.Name, "namespace": prestoTable.Namespace}).WithError(err).Errorf("unable to remove finalizers from PrestoTable: %#v", prestoTable)
return
}
}
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(prestoTable)
if err != nil {
op.logger.WithFields(log.Fields{"prestoTable": prestoTable.Name, "namespace": prestoTable.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", prestoTable)
return
}
op.prestoTableQueue.Add(key)
}
func (op *Reporting) enqueuePrestoTable(table *metering.PrestoTable) {
key, err := cache.MetaNamespaceKeyFunc(table)
if err != nil {
op.logger.WithFields(log.Fields{"prestoTable": table.Name, "namespace": table.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", table)
return
}
op.prestoTableQueue.Add(key)
}
func (op *Reporting) addHiveTable(obj interface{}) {
table := obj.(*metering.HiveTable)
if table.DeletionTimestamp != nil {
op.deleteHiveTable(table)
return
}
logger := op.logger.WithFields(log.Fields{"hiveTable": table.Name, "namespace": table.Namespace})
logger.Infof("adding HiveTable %s/%s", table.Namespace, table.Name)
op.enqueueHiveTable(table)
}
func (op *Reporting) updateHiveTable(_, cur interface{}) {
curHiveTable := cur.(*metering.HiveTable)
if curHiveTable.DeletionTimestamp != nil {
op.deleteHiveTable(curHiveTable)
return
}
logger := op.logger.WithFields(log.Fields{"hiveTable": curHiveTable.Name, "namespace": curHiveTable.Namespace})
logger.Infof("updating HiveTable %s/%s", curHiveTable.Namespace, curHiveTable.Name)
op.enqueueHiveTable(curHiveTable)
}
func (op *Reporting) deleteHiveTable(obj interface{}) {
hiveTable, ok := obj.(*metering.HiveTable)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
op.logger.WithFields(log.Fields{"hiveTable": hiveTable.Name, "namespace": hiveTable.Namespace}).Errorf("Couldn't get object from tombstone %#v", obj)
return
}
hiveTable, ok = tombstone.Obj.(*metering.HiveTable)
if !ok {
op.logger.WithFields(log.Fields{"hiveTable": hiveTable.Name, "namespace": hiveTable.Namespace}).Errorf("Tombstone contained object that is not a HiveTable %#v", obj)
return
}
}
// when finalizers aren't enabled, it's pretty likely by the time our
// worker get the event from the queue that the resource will no longer
// exist in our store, so we eagerly drop the table upon seeing the delete
// event when finalizers are disabled
if !op.cfg.EnableFinalizers && hiveTable != nil {
err := op.dropHiveTable(hiveTable)
if err != nil {
op.logger.WithFields(log.Fields{"hiveTable": hiveTable.Name, "namespace": hiveTable.Namespace}).WithError(err).Errorf("couldn't drop HiveTable: %#v", hiveTable)
return
}
_, err = op.removeHiveTableFinalizer(hiveTable)
if err != nil {
op.logger.WithFields(log.Fields{"hiveTable": hiveTable.Name, "namespace": hiveTable.Namespace}).WithError(err).Errorf("unable to remove finalizers from HiveTable: %#v", hiveTable)
return
}
}
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(hiveTable)
if err != nil {
op.logger.WithFields(log.Fields{"hiveTable": hiveTable.Name, "namespace": hiveTable.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", hiveTable)
return
}
op.hiveTableQueue.Add(key)
}
func (op *Reporting) enqueueHiveTable(table *metering.HiveTable) {
key, err := cache.MetaNamespaceKeyFunc(table)
if err != nil {
op.logger.WithFields(log.Fields{"hiveTable": table.Name, "namespace": table.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", table)
return
}
op.hiveTableQueue.Add(key)
}
func (op *Reporting) addStorageLocation(obj interface{}) {
storageLocation := obj.(*metering.StorageLocation)
if storageLocation.DeletionTimestamp != nil {
op.deleteStorageLocation(storageLocation)
return
}
logger := op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace})
logger.Infof("adding StorageLocation %s/%s", storageLocation.Namespace, storageLocation.Name)
op.enqueueStorageLocation(storageLocation)
}
func (op *Reporting) updateStorageLocation(_, cur interface{}) {
curStorageLocation := cur.(*metering.StorageLocation)
if curStorageLocation.DeletionTimestamp != nil {
op.deleteStorageLocation(curStorageLocation)
return
}
logger := op.logger.WithFields(log.Fields{"storageLocation": curStorageLocation.Name, "namespace": curStorageLocation.Namespace})
logger.Infof("updating StorageLocation %s/%s", curStorageLocation.Namespace, curStorageLocation.Name)
op.enqueueStorageLocation(curStorageLocation)
}
func (op *Reporting) deleteStorageLocation(obj interface{}) {
storageLocation, ok := obj.(*metering.StorageLocation)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
if !ok {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).Errorf("Couldn't get object from tombstone %#v", obj)
return
}
storageLocation, ok = tombstone.Obj.(*metering.StorageLocation)
if !ok {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).Errorf("Tombstone contained object that is not a StorageLocation %#v", obj)
return
}
}
// when finalizers aren't enabled, it's pretty likely by the time our
// worker get the event from the queue that the resource will no longer
// exist in our store, so we eagerly drop the storageLocation upon seeing the delete
// event when finalizers are disabled
if !op.cfg.EnableFinalizers && storageLocation != nil {
err := op.deleteStorage(storageLocation)
if err != nil {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).WithError(err).Errorf("couldn't delete storage for storageLocation: %#v", storageLocation)
return
}
_, err = op.removeStorageLocationFinalizer(storageLocation)
if err != nil {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).WithError(err).Errorf("unable to remove finalizers for storageLocation: %#v", storageLocation)
return
}
}
key, err := cache.DeletionHandlingMetaNamespaceKeyFunc(storageLocation)
if err != nil {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", storageLocation)
return
}
op.storageLocationQueue.Add(key)
}
func (op *Reporting) enqueueStorageLocation(storageLocation *metering.StorageLocation) {
key, err := cache.MetaNamespaceKeyFunc(storageLocation)
if err != nil {
op.logger.WithFields(log.Fields{"storageLocation": storageLocation.Name, "namespace": storageLocation.Namespace}).WithError(err).Errorf("couldn't get key for object: %#v", storageLocation)
return
}
op.storageLocationQueue.Add(key)
}
type workerProcessFunc func(logger log.FieldLogger) bool
func (op *Reporting) processResource(logger log.FieldLogger, handlerFunc syncHandler, objType string, queue workqueue.RateLimitingInterface, maxRequeues int) bool {
obj, quit := queue.Get()
if quit {
logger.Infof("queue is shutting down, exiting %s worker", objType)
return false
}
defer queue.Done(obj)
op.runHandler(logger, handlerFunc, objType, obj, queue, maxRequeues)
return true
}
type syncHandler func(logger log.FieldLogger, key string) error
func (op *Reporting) runHandler(logger log.FieldLogger, handlerFunc syncHandler, objType string, obj interface{}, queue workqueue.RateLimitingInterface, maxRequeues int) {
logger = logger.WithFields(newLogIdentifier(op.rand))
if key, ok := op.getKeyFromQueueObj(logger, objType, obj, queue); ok {
logger.Infof("syncing %s %s", objType, key)
err := handlerFunc(logger, key)
op.handleErr(logger, err, objType, key, queue, maxRequeues)
}
}
// getKeyFromQueueObj tries to convert the object from the queue into a string,
// and if it isn't, it forgets the key from the queue, and logs an error.
//
// We expect strings to come off the workqueue. These are of the
// form namespace/name. We do this as the delayed nature of the
// workqueue means the items in the informer cache may actually be
// more up to date that when the item was initially put onto the
// workqueue.
func (op *Reporting) getKeyFromQueueObj(logger log.FieldLogger, objType string, obj interface{}, queue workqueue.RateLimitingInterface) (string, bool) {
if key, ok := obj.(string); ok {
return key, ok
}
queue.Forget(obj)
logger.WithField(objType, obj).Errorf("expected string in work queue but got %#v", obj)
return "", false
}
// handleErr checks if an error happened and makes sure we will retry later.
func (op *Reporting) handleErr(logger log.FieldLogger, err error, objType string, obj interface{}, queue workqueue.RateLimitingInterface, maxRequeues int) {
logger = logger.WithField(objType, obj)
if err == nil {
logger.Infof("successfully synced %s %q", objType, obj)
queue.Forget(obj)
return
}
// This controller retries up to maxRequeues times if something goes wrong.
// After that, it stops trying.
if maxRequeues == -1 || queue.NumRequeues(obj) < maxRequeues {
logger.WithError(err).Errorf("error syncing %s %q, adding back to queue", objType, obj)
queue.AddRateLimited(obj)
return
}
queue.Forget(obj)
logger.WithError(err).Infof("error syncing %s %q, dropping out of the queue", objType, obj)
}
// inTargetNamespaceEventHandlerFunc wraps a cache.ResourceEventHandler and
// only runs the wrapped handler if the resource is listed in targetNamespaces.
type inTargetNamespaceResourceEventHandler struct {
handler cache.ResourceEventHandler
targetNamespaces []string
}
func (handler *inTargetNamespaceResourceEventHandler) inTargetNamespace(obj interface{}) bool {
metav1Obj, ok := obj.(metav1.Object)
if !ok {
return false
}
for _, targetNS := range handler.targetNamespaces {
if metav1Obj.GetNamespace() == targetNS {
return true
}
}
return false
}
func (handler *inTargetNamespaceResourceEventHandler) OnAdd(obj interface{}) {
if handler.inTargetNamespace(obj) {
handler.handler.OnAdd(obj)
}
}
func (handler *inTargetNamespaceResourceEventHandler) OnUpdate(oldObj, newObj interface{}) {
if handler.inTargetNamespace(oldObj) && handler.inTargetNamespace(newObj) {
handler.handler.OnUpdate(oldObj, newObj)
}
}
func (handler *inTargetNamespaceResourceEventHandler) OnDelete(obj interface{}) {
if handler.inTargetNamespace(obj) {
handler.handler.OnDelete(obj)
}
}
// newInTargetNamespaceEventHandler returns an
// inTargetNamespaceResourceEventHandler to wrap the given handler. If
// targetNamespaces is empty, then it returns the original eventHandler
// unmodified.
func newInTargetNamespaceEventHandler(handler cache.ResourceEventHandler, targetNamespaces []string) cache.ResourceEventHandler {
if len(targetNamespaces) == 0 {
return handler
}
return &inTargetNamespaceResourceEventHandler{handler: handler, targetNamespaces: targetNamespaces}
}