jianrongzhang89 commented on code in PR #467:
URL:
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/467#discussion_r1607442085
##########
controllers/knative/knative.go:
##########
@@ -84,3 +102,100 @@ func GetKnativeAvailability(cfg *rest.Config)
(*Availability, error) {
return result, nil
}
}
+
+func GetWorkflowSink(ctx context.Context, c client.Client, workflow
*operatorapi.SonataFlow, pl *operatorapi.SonataFlowPlatform)
(*duckv1.Destination, error) {
+ if workflow == nil {
+ return nil, nil
+ }
+ if workflow.Spec.Sink != nil {
+ return workflow.Spec.Sink, nil
+ }
+ if pl != nil {
+ if pl.Spec.Eventing != nil {
+ // no sink defined in the workflow, use the platform
broker
+ return pl.Spec.Eventing.Broker, nil
+ } else if pl.Status.ClusterPlatformRef != nil {
+ // Find the platform referred by the cluster platform
+ platform := &operatorapi.SonataFlowPlatform{}
+ if err := c.Get(ctx, types.NamespacedName{Namespace:
pl.Status.ClusterPlatformRef.PlatformRef.Namespace, Name:
pl.Status.ClusterPlatformRef.PlatformRef.Name}, platform); err != nil {
+ return nil, fmt.Errorf("error reading the
platform referred by the cluster platform")
+ }
+ if platform.Spec.Eventing != nil {
+ return platform.Spec.Eventing.Broker, nil
+ }
+ }
+ }
+ return nil, nil
+}
+
+const knativeBrokerAnnotation = "eventing.knative.dev/broker.class"
+
+func GetKnativeResource(ctx context.Context, cfg *rest.Config, kRef
*duckv1.KReference) (*unstructured.Unstructured, error) {
+ dynamicClient, err := dynamic.NewForConfig(cfg)
+ if err != nil {
+ return nil, err
+ }
+ gv, err := schema.ParseGroupVersion(kRef.APIVersion)
+ if err != nil {
+ return nil, err
+ }
+ resourceId := schema.GroupVersionResource{
+ Group: gv.Group,
+ Version: gv.Version,
+ Resource: kRef.Kind,
+ }
+ if len(kRef.Namespace) == 0 {
+ return nil, fmt.Errorf("namespace for knative resource %s is
missing", kRef.Name)
+ }
+ list, err :=
dynamicClient.Resource(resourceId).Namespace(kRef.Namespace).List(ctx,
metav1.ListOptions{})
+ fmt.Printf("list:%v", list)
+ return
dynamicClient.Resource(resourceId).Namespace(kRef.Namespace).Get(ctx,
kRef.Name, metav1.GetOptions{})
+}
+
+func IsKnativeBroker(kRef *duckv1.KReference) bool {
+ return kRef.APIVersion == "eventing.knative.dev/v1" && kRef.Kind ==
"Broker"
+}
+
+func IsKnativeEnvInjected(ctx context.Context, c client.Client,
deploymentName, namespace string) (bool, error) {
+ deployment := &appsv1.Deployment{}
+ if err := c.Get(ctx, types.NamespacedName{Name: deploymentName,
Namespace: namespace}, deployment); err != nil {
+ if errors.IsNotFound(err) {
+ return false, nil //deployment not found
+ }
+ return false, err
+ }
+ for _, env := range deployment.Spec.Template.Spec.Containers[0].Env {
+ if env.Name == KSink {
+ return true, nil
+ }
+ }
+ return false, nil
+}
+
+func IsDataIndexEnabled(plf *operatorapi.SonataFlowPlatform) bool {
+ if plf.Spec.Services != nil {
+ if plf.Spec.Services.DataIndex != nil {
+ return
pointer.BoolDeref(plf.Spec.Services.DataIndex.Enabled, false)
+ }
+ return false
+ }
+ // Check if DataIndex is enabled in the platform status
+ if plf.Status.ClusterPlatformRef != nil &&
plf.Status.ClusterPlatformRef.Services != nil &&
plf.Status.ClusterPlatformRef.Services.DataIndexRef != nil &&
len(plf.Status.ClusterPlatformRef.Services.DataIndexRef.Url) > 0 {
+ return true
+ }
+ return false
+}
+
+func IsJobServiceEnabled(plf *operatorapi.SonataFlowPlatform) bool {
+ if plf.Spec.Services != nil {
+ if plf.Spec.Services.JobService != nil {
+ return
pointer.BoolDeref(plf.Spec.Services.JobService.Enabled, false)
+ }
+ return false
+ }
+ // Check if JobService is enabled in the platform status
+ if plf.Status.ClusterPlatformRef != nil &&
plf.Status.ClusterPlatformRef.Services != nil &&
plf.Status.ClusterPlatformRef.Services.JobServiceRef != nil &&
len(plf.Status.ClusterPlatformRef.Services.JobServiceRef.Url) > 0 {
+ return true
+ }
+ return false
Review Comment:
Sounds good. Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]