Skip to content

Commit a32b81b

Browse files
author
Per Goncalves da Silva
committed
fix onDelete guard, subscription metrics, and some small things
Signed-off-by: Per Goncalves da Silva <[email protected]>
1 parent 18cc8e9 commit a32b81b

File tree

5 files changed

+27
-16
lines changed

5 files changed

+27
-16
lines changed

pkg/controller/operators/catalog/operator.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -877,18 +877,16 @@ func (o *Operator) handleDeletion(obj interface{}) {
877877
func (o *Operator) handleCatSrcDeletion(obj interface{}) {
878878
catsrc, ok := obj.(metav1.Object)
879879
if !ok {
880+
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
880881
if !ok {
881-
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
882-
if !ok {
883-
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", obj))
884-
return
885-
}
882+
utilruntime.HandleError(fmt.Errorf("couldn't get object from tombstone %#v", obj))
883+
return
884+
}
886885

887-
catsrc, ok = tombstone.Obj.(metav1.Object)
888-
if !ok {
889-
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a Namespace %#v", obj))
890-
return
891-
}
886+
catsrc, ok = tombstone.Obj.(metav1.Object)
887+
if !ok {
888+
utilruntime.HandleError(fmt.Errorf("tombstone contained object that is not a Namespace %#v", obj))
889+
return
892890
}
893891
}
894892
sourceKey := registry.CatalogKey{Name: catsrc.GetName(), Namespace: catsrc.GetNamespace()}

pkg/controller/operators/catalog/subscription/syncer.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ func (s *subscriptionSyncer) Sync(ctx context.Context, event kubestate.ResourceE
7171
initial = initial.Add()
7272
case kubestate.ResourceUpdated:
7373
initial = initial.Update()
74-
metrics.UpdateSubsSyncCounterStorage(res)
7574
}
7675

7776
reconciled, err := s.reconcilers.Reconcile(ctx, initial)
@@ -231,6 +230,23 @@ func newSyncerWithConfig(ctx context.Context, config *syncerConfig) (kubestate.S
231230
},
232231
}
233232

233+
// Add metrics handler to subscription informer
234+
// NOTE: This is different from how metrics are handled for other resources (install plan, catalog source, etc.)
235+
// which use metrics provider and through the QueueInformer
236+
config.subscriptionInformer.AddEventHandler(cache.ResourceEventHandlerFuncs{
237+
AddFunc: func(obj interface{}) {},
238+
UpdateFunc: func(oldObj, newObj interface{}) {
239+
if sub, ok := newObj.(*v1alpha1.Subscription); ok {
240+
metrics.UpdateSubsSyncCounterStorage(sub)
241+
}
242+
},
243+
DeleteFunc: func(obj interface{}) {
244+
if sub, ok := obj.(*v1alpha1.Subscription); ok {
245+
metrics.DeleteSubsMetric(sub)
246+
}
247+
},
248+
})
249+
234250
// Build a reconciler chain from the default and configured reconcilers
235251
// Default reconcilers should always come first in the chain
236252
defaultReconcilers := kubestate.ReconcilerChain{

pkg/lib/queueinformer/config.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ func (c *queueInformerConfig) complete() {
4141
// Extract indexer from informer if
4242
c.indexer = c.informer.GetIndexer()
4343
}
44-
if c.onDelete != nil {
45-
c.onDelete = func(obj interface{}) {}
46-
}
4744
}
4845

4946
// validate returns an error if the config isn't valid.
@@ -67,6 +64,7 @@ func (c *queueInformerConfig) validateQueueInformer() (err error) {
6764
func defaultConfig() *queueInformerConfig {
6865
return &queueInformerConfig{
6966
provider: metrics.NewMetricsNil(),
67+
onDelete: func(obj interface{}) {},
7068
queue: workqueue.NewTypedRateLimitingQueueWithConfig[types.NamespacedName](
7169
workqueue.DefaultTypedControllerRateLimiter[types.NamespacedName](),
7270
workqueue.TypedRateLimitingQueueConfig[types.NamespacedName]{

pkg/lib/queueinformer/queueinformer.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ func (q *QueueInformer) Sync(ctx context.Context, event kubestate.ResourceEvent)
3636

3737
// Enqueue adds a key to the queue. If obj is a key already it gets added directly.
3838
func (q *QueueInformer) Enqueue(item types.NamespacedName) {
39-
// Create new resource event and add to queue
4039
q.logger.WithField("item", item).Trace("enqueuing item")
4140
q.queue.Add(item)
4241
}

pkg/lib/queueinformer/queueinformer_operator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ func (o *operator) processNextWorkItem(ctx context.Context, loop *QueueInformer)
300300
}
301301
event := kubestate.NewResourceEvent(kubestate.ResourceUpdated, resource)
302302

303-
// Sync and requeue on error (throw out failed deletion syncs)
303+
// Sync and requeue on error
304304
err = loop.Sync(ctx, event)
305305
if requeues := queue.NumRequeues(item); err != nil && requeues < 8 {
306306
logger.WithField("requeues", requeues).Trace("requeuing with rate limiting")

0 commit comments

Comments
 (0)