From a4f71407c42f0f1ad8e35820ba1986dbcdb842d7 Mon Sep 17 00:00:00 2001 From: jianrongzhang89 Date: Wed, 2 Oct 2024 12:12:06 -0400 Subject: [PATCH] issue-541 Knative should not be required to install and run the SonataFlow Operator to deploy workflows --- internal/controller/sonataflow_controller.go | 23 +++++++++++++------ .../sonataflowplatform_controller.go | 19 ++++++++++----- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/internal/controller/sonataflow_controller.go b/internal/controller/sonataflow_controller.go index 404e3ccf8..a7734becd 100644 --- a/internal/controller/sonataflow_controller.go +++ b/internal/controller/sonataflow_controller.go @@ -218,14 +218,11 @@ func buildEnqueueRequestsFromMapFunc(c client.Client, b *operatorapi.SonataFlowB // SetupWithManager sets up the controller with the Manager. func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error { - return ctrl.NewControllerManagedBy(mgr). + builder := ctrl.NewControllerManagedBy(mgr). For(&operatorapi.SonataFlow{}). Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). Owns(&corev1.ConfigMap{}). - Owns(&servingv1.Service{}). - Owns(&eventingv1.Trigger{}). - Owns(&sourcesv1.SinkBinding{}). Owns(&operatorapi.SonataFlowBuild{}). Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(func(c context.Context, a client.Object) []reconcile.Request { plat, ok := a.(*operatorapi.SonataFlowPlatform) @@ -242,7 +239,19 @@ func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error { return []reconcile.Request{} } return buildEnqueueRequestsFromMapFunc(mgr.GetClient(), build) - })). - Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)). - Complete(r) + })) + + knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig()) + if err != nil { + return err + } + if knativeAvail.Serving { + builder = builder.Owns(&servingv1.Service{}) + } + if knativeAvail.Eventing { + builder = builder.Owns(&eventingv1.Trigger{}). + Owns(&sourcesv1.SinkBinding{}). + Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)) + } + return builder.Complete(r) } diff --git a/internal/controller/sonataflowplatform_controller.go b/internal/controller/sonataflowplatform_controller.go index b5fbbe269..75f3d1c5e 100644 --- a/internal/controller/sonataflowplatform_controller.go +++ b/internal/controller/sonataflowplatform_controller.go @@ -251,17 +251,24 @@ func (r *SonataFlowPlatformReconciler) updateIfActiveClusterPlatformExists(ctx c // SetupWithManager sets up the controller with the Manager. func (r *SonataFlowPlatformReconciler) SetupWithManager(mgr ctrlrun.Manager) error { - return ctrlrun.NewControllerManagedBy(mgr). + builder := ctrlrun.NewControllerManagedBy(mgr). For(&operatorapi.SonataFlowPlatform{}). Owns(&appsv1.Deployment{}). Owns(&corev1.Service{}). Owns(&corev1.ConfigMap{}). - Owns(&eventingv1.Trigger{}). - Owns(&sourcesv1.SinkBinding{}). Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapPlatformToPlatformRequests)). - Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests)). - Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)). - Complete(r) + Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests)) + + knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig()) + if err != nil { + return err + } + if knativeAvail.Eventing { + builder = builder.Owns(&eventingv1.Trigger{}). + Owns(&sourcesv1.SinkBinding{}). + Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)) + } + return builder.Complete(r) } // if active clusterplatform object is changed, reconcile all SonataFlowPlatforms in the cluster.