tchughesiv commented on code in PR #345:
URL: 
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/345#discussion_r1465006202


##########
controllers/sonataflowplatform_controller.go:
##########
@@ -166,12 +170,106 @@ func (r *SonataFlowPlatformReconciler) Reconcile(ctx 
context.Context, req reconc
 
 }
 
+// If an active cluster platform exists, update platform.Status accordingly
+func (r *SonataFlowPlatformReconciler) SonataFlowPlatformUpdateStatus(ctx 
context.Context, req reconcile.Request, target *operatorapi.SonataFlowPlatform) 
error {
+       // Fetch the active SonataFlowClusterPlatform instance
+       sfcPlatform, err := clusterplatform.GetActiveClusterPlatform(ctx, 
r.Client)
+       if err != nil && !errors.IsNotFound(err) {
+               klog.V(log.E).ErrorS(err, "Failed to get active 
SonataFlowClusterPlatform")
+               return err
+       }
+
+       if sfcPlatform != nil {
+               sfPlatform := &operatorapi.SonataFlowPlatform{}
+
+               platformRef := sfcPlatform.Spec.PlatformRef
+               namespacedName := types.NamespacedName{Namespace: 
platformRef.Namespace, Name: platformRef.Name}
+               if req.NamespacedName == namespacedName {
+                       sfPlatform = target.DeepCopy()
+               } else {
+                       // retrieve referenced platform object
+                       err := r.Reader.Get(ctx, namespacedName, sfPlatform)
+                       if err != nil && !errors.IsNotFound(err) {
+                               klog.V(log.E).ErrorS(err, "Failed to get 
referenced SonataFlowPlatform", namespacedName)
+                               return err
+                       }
+               }
+
+               target.Status.ClusterPlatformRef = 
&operatorapi.SonataFlowClusterPlatformRefStatus{
+                       Name: sfcPlatform.Name,
+                       PlatformRef: operatorapi.SonataFlowPlatformRef{
+                               Name:      platformRef.Name,
+                               Namespace: platformRef.Namespace,
+                       },
+               }
+
+               tpsDI := services.NewDataIndexHandler(target)
+               tpsDI.SetServiceUrlInStatus(sfPlatform)

Review Comment:
   Point 3 is not correct. If i understand your scenario correctly, then in the 
code above we can assume the following:
   target = my-own-data-index
   sfPlatform = my-previous-sonataflow-platform
   
   In this case, reconciliation of the "my-own-data-index" (`target`) platform 
CR is occuring. The `SetServiceUrlInStatus` function would set the status of 
the "my-own-data-index" (`target`) platform CR so that it used its own 
"http://my-own-data-index"; service. It will do so by leaving its 
`status.ClusterPlatformRef.Services = nil`. Nothing in `sfPlatform` is 
affected. `sfPlatform` represents the platform object referenced in 
`SonataFlowClusterPlatform.spec.platformRef` and it is not affected.
   
https://github.com/apache/incubator-kie-kogito-serverless-operator/blob/81e1e83002b8fa92a6bdf2e96ed040b7080ed8db/controllers/platform/services/services.go#L116-L128



-- 
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]

Reply via email to