ricardozanini commented on code in PR #2911: URL: https://github.com/apache/incubator-kie-tools/pull/2911#discussion_r2003964559
########## packages/sonataflow-operator/internal/controller/common/worker.go: ########## @@ -0,0 +1,77 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package common Review Comment: Can you move this to a new `internal/manager` package instead? ########## packages/sonataflow-operator/internal/controller/profiles/preview/deployment_handler.go: ########## @@ -189,3 +209,69 @@ func (d *DeploymentReconciler) deploymentModelMutateVisitors( common.RestoreDeploymentVolumeAndVolumeMountMutateVisitor(), common.RolloutDeploymentIfCMChangedMutateVisitor(workflow, userPropsCM, managedPropsCM)} } + +func (d *DeploymentReconciler) updateLastTimeStatusNotified(workflow *operatorapi.SonataFlow, previousStatus operatorapi.SonataFlowStatus) { + previousRunningCondition := previousStatus.GetCondition(api.RunningConditionType) + currentRunningCondition := workflow.Status.GetCondition(api.RunningConditionType) + + if previousRunningCondition == nil { + previousRunningCondition = currentRunningCondition + } + if previousRunningCondition.Status != currentRunningCondition.Status || workflow.Status.LastTimeStatusNotified != nil && workflow.Status.LastTimeStatusNotified.Time.Before(controllercommon.GetOperatorStartTime()) { + workflow.Status.LastTimeStatusNotified = nil + } +} + +func (d *DeploymentReconciler) scheduleWorkflowStatusChangeNotification(ctx context.Context, workflow *operatorapi.SonataFlow) { + if workflow.Status.LastTimeStatusNotified == nil { + controllercommon.GetSFCWorker().RunAsync(func() { + notifyWorkflowStatusChange(d.C, workflow.Name, workflow.Namespace) + }) + } +} + +func notifyWorkflowStatusChange(cli client.Client, wfName, wfNamespace string) error { + var err error + var uri string + retryErr := retry.RetryOnConflict(retry.DefaultBackoff, func() error { + workflow := &operatorapi.SonataFlow{} + if err = cli.Get(context.Background(), types.NamespacedName{Name: wfName, Namespace: wfNamespace}, workflow); err != nil { + if errors.IsNotFound(err) { + klog.V(log.I).Infof("Workflow: %s, namespace: %s, was not found to send the workflow definition status update event.", wfName, wfNamespace) + return nil + } else { + klog.V(log.E).ErrorS(err, constants.SendWorkflowDefinitionsStatusUpdateEventError+" It was not possible to read the workflow.", "workflow", "namespace", wfName, wfNamespace) + return err + } + } + workflow = workflow.DeepCopy() + available := workflow.Status.GetCondition(api.RunningConditionType).IsTrue() + if uri, err = common.GetWorkflowDefinitionEventsTargetURL(cli, workflow); err != nil { + klog.V(log.E).ErrorS(err, constants.SendWorkflowDefinitionsStatusUpdateEventError+" Workflow definition events target url calculation failed.", "workflow", "namespace", workflow.Name, workflow.Namespace) + return err + } + if len(uri) == 0 { + klog.V(log.E).Infof("No enabled DataIndex, nor Broker, nor Sink configuration was found to send the workflow definition status update event for workflow: %s, namespace: %s", workflow.Name, workflow.Namespace) Review Comment: I don't think this log should be an error, we may change to DEBUG. Otherwise, simple deployments (without DI) would spawn errors in the logs all the time. ########## packages/sonataflow-operator/internal/controller/profiles/common/workflowdef_events.go: ########## @@ -0,0 +1,74 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package common + +import ( + "context" + + duckv1 "knative.dev/pkg/apis/duck/v1" + + "k8s.io/klog/v2" + "sigs.k8s.io/controller-runtime/pkg/client" + + operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08" + "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/knative" + "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform" + "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services" + "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/profiles/common/constants" Review Comment: Usually, a `common` package file won't import other internal packages. Can we move this to `internal/controller/eventing` instead? I'd avoid adding these types of functions to a common package. ########## packages/sonataflow-operator/internal/controller/platform/services/services.go: ########## @@ -690,7 +693,7 @@ func (d *DataIndexHandler) GenerateKnativeResources(platform *operatorapi.Sonata d.newTrigger(lbl, annotations, brokerName, namespace, serviceName, "process-node", "ProcessInstanceNodeDataEvent", constants.KogitoProcessInstancesEventsPath, platform), d.newTrigger(lbl, annotations, brokerName, namespace, serviceName, "process-state", "ProcessInstanceStateDataEvent", constants.KogitoProcessInstancesEventsPath, platform), d.newTrigger(lbl, annotations, brokerName, namespace, serviceName, "process-variable", "ProcessInstanceVariableDataEvent", constants.KogitoProcessInstancesEventsPath, platform), - d.newTrigger(lbl, annotations, brokerName, namespace, serviceName, "process-definition", "ProcessDefinitionEvent", constants.KogitoProcessDefinitionsEventsPath, platform), + d.newTrigger(lbl, managedAnnotations, brokerName, namespace, serviceName, "process-definition", "ProcessDefinitionEvent", constants.KogitoProcessDefinitionsEventsPath, platform), Review Comment: Was it a bug? -- 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]
