Skip to content

Commit fda9903

Browse files
jianrongzhang89rgdoliveira
authored andcommitted
issue-541 Knative should not be required to install and run the SonataFlow Operator to deploy workflows (apache#545)
1 parent bab8c7c commit fda9903

File tree

2 files changed

+29
-13
lines changed

2 files changed

+29
-13
lines changed

internal/controller/sonataflow_controller.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,11 @@ func buildEnqueueRequestsFromMapFunc(c client.Client, b *operatorapi.SonataFlowB
218218

219219
// SetupWithManager sets up the controller with the Manager.
220220
func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
221-
return ctrl.NewControllerManagedBy(mgr).
221+
builder := ctrl.NewControllerManagedBy(mgr).
222222
For(&operatorapi.SonataFlow{}).
223223
Owns(&appsv1.Deployment{}).
224224
Owns(&corev1.Service{}).
225225
Owns(&corev1.ConfigMap{}).
226-
Owns(&servingv1.Service{}).
227-
Owns(&eventingv1.Trigger{}).
228-
Owns(&sourcesv1.SinkBinding{}).
229226
Owns(&operatorapi.SonataFlowBuild{}).
230227
Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(func(c context.Context, a client.Object) []reconcile.Request {
231228
plat, ok := a.(*operatorapi.SonataFlowPlatform)
@@ -242,7 +239,19 @@ func (r *SonataFlowReconciler) SetupWithManager(mgr ctrl.Manager) error {
242239
return []reconcile.Request{}
243240
}
244241
return buildEnqueueRequestsFromMapFunc(mgr.GetClient(), build)
245-
})).
246-
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)).
247-
Complete(r)
242+
}))
243+
244+
knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig())
245+
if err != nil {
246+
return err
247+
}
248+
if knativeAvail.Serving {
249+
builder = builder.Owns(&servingv1.Service{})
250+
}
251+
if knativeAvail.Eventing {
252+
builder = builder.Owns(&eventingv1.Trigger{}).
253+
Owns(&sourcesv1.SinkBinding{}).
254+
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests))
255+
}
256+
return builder.Complete(r)
248257
}

internal/controller/sonataflowplatform_controller.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,24 @@ func (r *SonataFlowPlatformReconciler) updateIfActiveClusterPlatformExists(ctx c
251251

252252
// SetupWithManager sets up the controller with the Manager.
253253
func (r *SonataFlowPlatformReconciler) SetupWithManager(mgr ctrlrun.Manager) error {
254-
return ctrlrun.NewControllerManagedBy(mgr).
254+
builder := ctrlrun.NewControllerManagedBy(mgr).
255255
For(&operatorapi.SonataFlowPlatform{}).
256256
Owns(&appsv1.Deployment{}).
257257
Owns(&corev1.Service{}).
258258
Owns(&corev1.ConfigMap{}).
259-
Owns(&eventingv1.Trigger{}).
260-
Owns(&sourcesv1.SinkBinding{}).
261259
Watches(&operatorapi.SonataFlowPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapPlatformToPlatformRequests)).
262-
Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests)).
263-
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests)).
264-
Complete(r)
260+
Watches(&operatorapi.SonataFlowClusterPlatform{}, handler.EnqueueRequestsFromMapFunc(r.mapClusterPlatformToPlatformRequests))
261+
262+
knativeAvail, err := knative.GetKnativeAvailability(mgr.GetConfig())
263+
if err != nil {
264+
return err
265+
}
266+
if knativeAvail.Eventing {
267+
builder = builder.Owns(&eventingv1.Trigger{}).
268+
Owns(&sourcesv1.SinkBinding{}).
269+
Watches(&eventingv1.Trigger{}, handler.EnqueueRequestsFromMapFunc(knative.MapTriggerToPlatformRequests))
270+
}
271+
return builder.Complete(r)
265272
}
266273

267274
// if active clusterplatform object is changed, reconcile all SonataFlowPlatforms in the cluster.

0 commit comments

Comments
 (0)