// SetupWithManager sets up the controller with the Manager.
SetupWithManager sets up the controller with the Manager.
// SetupWithManager sets up the controller with the Manager .
func (r *EventSourceReconciler) SetupWithManager(mgr ctrl.Manager) error {
	return ctrl.NewControllerManagedBy(mgr).
		For(&ofevent.EventSource{}, builder.WithPredicates(predicate.GenerationChangedPredicate{})).
		Watches(&source.Kind{Type: &ofevent.EventBus{}}, handler.EnqueueRequestsFromMapFunc(func(object client.Object) []reconcile.Request {
			eventSourceList := &ofevent.EventSourceList{}
			c := mgr.GetClient()
			err := c.List(context.TODO(), eventSourceList, &client.ListOptions{Namespace: object.GetNamespace()})
			if err != nil {
				return []reconcile.Request{}
			}
			reconcileRequests := make([]reconcile.Request, len(eventSourceList.Items))
			for _, eventSource := range eventSourceList.Items {
				if &eventSource != nil {
					if eventSource.Spec.EventBus != "" && eventSource.Spec.EventBus == object.GetName() {
						reconcileRequests = append(reconcileRequests, reconcile.Request{
							NamespacedName: types.NamespacedName{
								Namespace: eventSource.Namespace,
								Name:      eventSource.Name,
							},
						})
					}
				}
			}
			return reconcileRequests
		})).
		Watches(&source.Kind{Type: &ofevent.ClusterEventBus{}}, handler.EnqueueRequestsFromMapFunc(func(object client.Object) []reconcile.Request {
			eventSourceList := &ofevent.EventSourceList{}
			c := mgr.GetClient()
			selector := labels.SelectorFromSet(labels.Set(map[string]string{EventBusNameLabel: object.GetName()}))
			err := c.List(context.TODO(), eventSourceList, &client.ListOptions{LabelSelector: selector})
			if err != nil {
				return []reconcile.Request{}
			}
			reconcileRequests := make([]reconcile.Request, len(eventSourceList.Items))
			for _, eventSource := range eventSourceList.Items {
				if &eventSource != nil {
					var eventBus ofevent.EventBus
					if err := c.Get(context.TODO(), client.ObjectKey{Namespace: eventSource.Namespace, Name: eventSource.Spec.EventBus}, &eventBus); err == nil {
						continue
					}
					reconcileRequests = append(reconcileRequests, reconcile.Request{
						NamespacedName: types.NamespacedName{
							Namespace: eventSource.Namespace,
							Name:      eventSource.Name,
						},
					})
				}
			}
			return reconcileRequests
		})).
		Complete(r)
}
func ( r * EventSourceReconciler ) SetupWithManager ( mgr ctrl . Manager ) error { return ctrl . NewControllerManagedBy ( mgr ) . For ( & ofevent . EventSource { } , builder . WithPredicates ( predicate . GenerationChangedPredicate { } ) ) . Watches ( & source . Kind { Type : & ofevent . EventBus { } } , handler . EnqueueRequestsFromMapFunc ( func ( object client . Object ) [ ] reconcile . Request { eventSourceList := & ofevent . EventSourceList { } c := mgr . GetClient ( ) err := c . List ( context . TODO ( ) , eventSourceList , & client . ListOptions { Namespace : object . GetNamespace ( ) } ) if err != nil { return [ ] reconcile . Request { } } reconcileRequests := make ( [ ] reconcile . Request , len ( eventSourceList . Items ) ) for _ , eventSource := range eventSourceList . Items { if & eventSource != nil { if eventSource . Spec . EventBus != " " && eventSource . Spec . EventBus == object . GetName ( ) { reconcileRequests = append ( reconcileRequests , reconcile . Request { NamespacedName : types . NamespacedName { Namespace : eventSource . Namespace , Name : eventSource . Name , } , } ) } } } return reconcileRequests } ) ) . Watches ( & source . Kind { Type : & ofevent . ClusterEventBus { } } , handler . EnqueueRequestsFromMapFunc ( func ( object client . Object ) [ ] reconcile . Request { eventSourceList := & ofevent . EventSourceList { } c := mgr . GetClient ( ) selector := labels . SelectorFromSet ( labels . Set ( map [ string ] string { EventBusNameLabel : object . GetName ( ) } ) ) err := c . List ( context . TODO ( ) , eventSourceList , & client . ListOptions { LabelSelector : selector } ) if err != nil { return [ ] reconcile . Request { } } reconcileRequests := make ( [ ] reconcile . Request , len ( eventSourceList . Items ) ) for _ , eventSource := range eventSourceList . Items { if & eventSource != nil { var eventBus ofevent . EventBus if err := c . Get ( context . TODO ( ) , client . ObjectKey { Namespace : eventSource . Namespace , Name : eventSource . Spec . EventBus } , & eventBus ) ; err == nil { continue } reconcileRequests = append ( reconcileRequests , reconcile . Request { NamespacedName : types . NamespacedName { Namespace : eventSource . Namespace , Name : eventSource . Name , } , } ) } } return reconcileRequests } ) ) . Complete ( r ) }
SetupWithManager sets up the controller with the Manager.
SetupWithManager sets up the controller with the Manager .