Skip to content

Commit

Permalink
issue-541 Knative should not be required to install and run the Sonat…
Browse files Browse the repository at this point in the history
…aFlow Operator to deploy workflows
  • Loading branch information
jianrongzhang89 committed Oct 2, 2024
1 parent 645b09f commit a4f7140
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
23 changes: 16 additions & 7 deletions internal/controller/sonataflow_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
19 changes: 13 additions & 6 deletions internal/controller/sonataflowplatform_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a4f7140

Please sign in to comment.