Skip to content

Commit

Permalink
fix: Fix watch handlers for TextTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Jan 11, 2023
1 parent 221af30 commit 79285c9
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions controllers/comments/base_comment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,36 +201,36 @@ func (r *BaseCommentReconciler) baseSetupWithManager(mgr ctrl.Manager, r2 reconc
return fmt.Errorf("failed setting index fields: %w", err)
}

watchHandler := handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
list := buildList()

var ref templatesv1alpha1.ObjectRef
ref.Name = obj.GetName()
switch obj.(type) {
case *corev1.ConfigMap:
ref.Kind = "ConfigMap"
case *templatesv1alpha1.TextTemplate:
ref.Kind = "TextTemplate"
default:
return nil
}
if err := r.List(context.Background(), list, client.MatchingFields{
indexKey: ref.String(),
}); err != nil {
return nil
}
var ret []reconcile.Request
for _, o := range list.GetItems() {
ret = append(ret, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(o)})
}
return ret
})

return ctrl.NewControllerManagedBy(mgr).
For(obj, builder.WithPredicates(
predicate.GenerationChangedPredicate{},
)).
Watches(
&source.Kind{Type: &corev1.ConfigMap{}},
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
list := buildList()

var ref templatesv1alpha1.ObjectRef
ref.Name = obj.GetName()
switch obj.(type) {
case *corev1.ConfigMap:
ref.Kind = "ConfigMap"
case *templatesv1alpha1.TextTemplate:
ref.Kind = "TextTemplate"
default:
return nil
}
if err := r.List(context.Background(), list, client.MatchingFields{
indexKey: ref.String(),
}); err != nil {
return nil
}
var ret []reconcile.Request
for _, o := range list.GetItems() {
ret = append(ret, reconcile.Request{NamespacedName: client.ObjectKeyFromObject(o)})
}
return ret
}),
).
Watches(&source.Kind{Type: &corev1.ConfigMap{}}, watchHandler).
Watches(&source.Kind{Type: &templatesv1alpha1.TextTemplate{}}, watchHandler).
Complete(r2)
}

0 comments on commit 79285c9

Please sign in to comment.