ricardozanini commented on code in PR #287:
URL: 
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/287#discussion_r1376654661


##########
api/v1alpha08/sonataflowplatform_services_types.go:
##########
@@ -0,0 +1,89 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 v1alpha08
+
+// ServicesPlatformSpec describes the desired service configuration for "prod" 
workflows.
+type ServicesPlatformSpec struct {
+       // Deploys the Data Index service for use by "prod" profile workflows.
+       // +optional
+       DataIndex *ServicesPodTemplateSpec `json:"dataIndex,omitempty"`
+       // Persists service(s) to a datasource of choice. Ephemeral by default.
+       // +optional
+       Persistence *PersistenceOptions `json:"persistence,omitempty"`
+}
+
+// ServicesPodTemplateSpec describes the desired custom Kubernetes PodTemplate 
definition for the deployed flow.
+//
+// The FlowContainer describes the container where the actual service is 
running. It will override any default definitions.
+// For example, to override the image one can use 
`.spec.services.dataIndex.container.image = my/image:tag`.
+type ServicesPodTemplateSpec struct {
+       // Container is the Kubernetes container where the service should run.
+       // One can change this attribute in order to override the defaults 
provided by the operator.
+       // +optional
+       Container *FlowContainer `json:"container,omitempty"`

Review Comment:
   Can we rename this struct to something else since the container is not 
exclusively for the flow use cases? Maybe `ContainerSpec`? I wanna avoid 
`Container` to not conflict with the k8s API. WDYT?



##########
api/v1alpha08/sonataflowplatform_services_types.go:
##########
@@ -0,0 +1,89 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 v1alpha08
+
+// ServicesPlatformSpec describes the desired service configuration for "prod" 
workflows.
+type ServicesPlatformSpec struct {
+       // Deploys the Data Index service for use by "prod" profile workflows.
+       // +optional
+       DataIndex *ServicesPodTemplateSpec `json:"dataIndex,omitempty"`
+       // Persists service(s) to a datasource of choice. Ephemeral by default.
+       // +optional
+       Persistence *PersistenceOptions `json:"persistence,omitempty"`
+}
+
+// ServicesPodTemplateSpec describes the desired custom Kubernetes PodTemplate 
definition for the deployed flow.
+//
+// The FlowContainer describes the container where the actual service is 
running. It will override any default definitions.
+// For example, to override the image one can use 
`.spec.services.dataIndex.container.image = my/image:tag`.
+type ServicesPodTemplateSpec struct {
+       // Container is the Kubernetes container where the service should run.
+       // One can change this attribute in order to override the defaults 
provided by the operator.
+       // +optional
+       Container *FlowContainer `json:"container,omitempty"`
+       // Describes the PodSpec for the internal service deployment based on 
the default Kubernetes PodSpec API
+       // +optional
+       FlowPodSpec `json:",inline"`

Review Comment:
   Same thing here. I guess `PodSpec` is already taken by the k8s API. Let's 
keep `PodSpec` since it's in another module, so we keep the differentiation 
under the namespace level then.



##########
api/v1alpha08/sonataflowplatform_services_types.go:
##########
@@ -0,0 +1,89 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 v1alpha08
+
+// ServicesPlatformSpec describes the desired service configuration for "prod" 
workflows.
+type ServicesPlatformSpec struct {
+       // Deploys the Data Index service for use by "prod" profile workflows.
+       // +optional
+       DataIndex *ServicesPodTemplateSpec `json:"dataIndex,omitempty"`
+       // Persists service(s) to a datasource of choice. Ephemeral by default.
+       // +optional
+       Persistence *PersistenceOptions `json:"persistence,omitempty"`
+}
+
+// ServicesPodTemplateSpec describes the desired custom Kubernetes PodTemplate 
definition for the deployed flow.
+//
+// The FlowContainer describes the container where the actual service is 
running. It will override any default definitions.
+// For example, to override the image one can use 
`.spec.services.dataIndex.container.image = my/image:tag`.
+type ServicesPodTemplateSpec struct {
+       // Container is the Kubernetes container where the service should run.
+       // One can change this attribute in order to override the defaults 
provided by the operator.
+       // +optional
+       Container *FlowContainer `json:"container,omitempty"`
+       // Describes the PodSpec for the internal service deployment based on 
the default Kubernetes PodSpec API
+       // +optional
+       FlowPodSpec `json:",inline"`
+       // +optional
+       Replicas *int32 `json:"replicas,omitempty"`
+       // Determines whether "prod" profile workflows should be configured to 
use this service
+       // +optional
+       Enabled *bool `json:"enabled,omitempty"`
+}
+
+// PersistenceOptions configure the services to persist to a datasource of 
choice
+// +kubebuilder:validation:MaxProperties=1
+type PersistenceOptions struct {
+       // Connect configured services to a postgresql database.
+       // +optional
+       PostgreSql *PersistencePostgreSql `json:"postgresql,omitempty"`
+       // +optional
+       // Infinispan *PersistenceInfinispan `json:"infinispan,omitempty"`

Review Comment:
   We can remove this comment to avoid misunderstandings.



##########
controllers/platform/services.go:
##########
@@ -0,0 +1,360 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 platform
+
+import (
+       "context"
+       "strconv"
+       "strings"
+
+       appsv1 "k8s.io/api/apps/v1"
+       corev1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/api/resource"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/klog/v2"
+       "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
+
+       operatorapi 
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/client"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
+       "github.com/apache/incubator-kie-kogito-serverless-operator/log"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
+       "github.com/imdario/mergo"
+)
+
+var httpPort = strings.ToLower(string(corev1.URISchemeHTTP))

Review Comment:
   @wmedvede I guess we can make this global to `utils` and use it in the 
properties service too.



##########
controllers/platform/services.go:
##########
@@ -0,0 +1,360 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 platform
+
+import (
+       "context"
+       "strconv"
+       "strings"
+
+       appsv1 "k8s.io/api/apps/v1"
+       corev1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/api/resource"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/klog/v2"
+       "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
+
+       operatorapi 
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/client"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
+       "github.com/apache/incubator-kie-kogito-serverless-operator/log"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
+       "github.com/imdario/mergo"
+)
+
+var httpPort = strings.ToLower(string(corev1.URISchemeHTTP))
+
+// NewServiceAction returns an action that deploys the services.
+func NewServiceAction() Action {
+       return &serviceAction{}
+}
+
+type serviceAction struct {
+       baseAction
+}
+
+func (action *serviceAction) Name() string {
+       return "service"
+}
+
+func (action *serviceAction) CanHandle(platform 
*operatorapi.SonataFlowPlatform) bool {
+       return platform.Status.IsReady()
+}
+
+func (action *serviceAction) Handle(ctx context.Context, platform 
*operatorapi.SonataFlowPlatform) (*operatorapi.SonataFlowPlatform, error) {
+       // Refresh applied configuration
+       if err := ConfigureDefaults(ctx, action.client, platform, false); err 
!= nil {
+               return nil, err
+       }
+
+       if err := createDataIndexComponents(ctx, action.client, platform); err 
!= nil {
+               return nil, err
+       }
+
+       return platform, nil
+}
+
+func createDataIndexComponents(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       if platform.Spec.Services.DataIndex != nil {
+               if err := createDataIndexConfigMap(ctx, client, platform); err 
!= nil {
+                       return err
+               }
+               if err := createDataIndexDeployment(ctx, client, platform); err 
!= nil {
+                       return err
+               }
+               if err := createDataIndexService(ctx, client, platform); err != 
nil {
+                       return err
+               }
+       }
+
+       return nil
+}
+
+func createDataIndexDeployment(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       probe := &corev1.Probe{
+               ProbeHandler: corev1.ProbeHandler{
+                       HTTPGet: &corev1.HTTPGetAction{
+                               Path:   "/q/health/ready",
+                               Port:   common.DefaultHTTPWorkflowPortIntStr,
+                               Scheme: corev1.URISchemeHTTP,
+                       },
+               },
+               InitialDelaySeconds: int32(15),
+               TimeoutSeconds:      int32(10),
+               PeriodSeconds:       int32(30),
+               SuccessThreshold:    int32(1),
+               FailureThreshold:    int32(3),
+       }
+       dataDeployContainer := &corev1.Container{
+               Name:  common.DataIndexName,
+               Image: common.DataIndexImageBase + 
common.PersistenceTypeEphemeral,
+               Env: []corev1.EnvVar{
+                       {
+                               Name:  "KOGITO_DATA_INDEX_QUARKUS_PROFILE",
+                               Value: "http-events-support",
+                       },
+                       {
+                               Name:  "QUARKUS_HTTP_PORT",
+                               Value: "8080",
+                       },
+                       {
+                               Name:  "QUARKUS_HTTP_CORS",
+                               Value: "true",
+                       },
+                       {
+                               Name:  "QUARKUS_HTTP_CORS_ORIGINS",
+                               Value: "/.*/",
+                       },
+                       {
+                               Name:  "QUARKUS_KAFKA_HEALTH_ENABLE",
+                               Value: "false",
+                       },
+               },
+               Resources: corev1.ResourceRequirements{
+                       Limits: corev1.ResourceList{
+                               corev1.ResourceCPU:    
resource.MustParse("100m"),
+                               corev1.ResourceMemory: 
resource.MustParse("256Mi"),
+                       },
+               },
+               ReadinessProbe: probe,
+               LivenessProbe:  probe,
+               Ports: []corev1.ContainerPort{
+                       {
+                               Name:          httpPort,
+                               ContainerPort: 
int32(common.DefaultHTTPWorkflowPortInt),
+                               Protocol:      corev1.ProtocolTCP,
+                       },
+               },
+               ImagePullPolicy: corev1.PullAlways,
+               VolumeMounts: []corev1.VolumeMount{
+                       {
+                               Name:      "application-config",
+                               MountPath: "/home/kogito/config",
+                       },
+               },
+       }
+       configurePersistence(ctx, client, dataDeployContainer, platform)
+       if platform.Spec.Services.DataIndex.Container != nil {
+               if err := mergo.Merge(dataDeployContainer, 
platform.Spec.Services.DataIndex.Container.ToContainer(), mergo.WithOverride); 
err != nil {
+                       return err
+               }
+       }
+
+       var replicas int32 = 1
+       if platform.Spec.Services.DataIndex.Replicas != nil {
+               replicas = *platform.Spec.Services.DataIndex.Replicas
+       }
+       lbl := map[string]string{
+               workflowproj.LabelApp: platform.Name,
+       }
+       dataDeploySpec := appsv1.DeploymentSpec{
+               Selector: &metav1.LabelSelector{
+                       MatchLabels: lbl,
+               },
+               Replicas: &replicas,
+               Template: corev1.PodTemplateSpec{
+                       ObjectMeta: metav1.ObjectMeta{
+                               Labels: lbl,
+                       },
+                       Spec: corev1.PodSpec{
+                               Containers: 
[]corev1.Container{*dataDeployContainer},
+                               Volumes: []corev1.Volume{
+                                       {
+                                               Name: "application-config",
+                                               VolumeSource: 
corev1.VolumeSource{
+                                                       ConfigMap: 
&corev1.ConfigMapVolumeSource{
+                                                               
LocalObjectReference: corev1.LocalObjectReference{
+                                                                       Name: 
platform.Name + "-" + common.DataIndexName,
+                                                               },
+                                                       },
+                                               },
+                                       },
+                               },
+                       },
+               },
+       }
+       if err := mergo.Merge(&dataDeploySpec.Template.Spec, 
platform.Spec.Services.DataIndex.FlowPodSpec.ToPodSpec(), mergo.WithOverride); 
err != nil {
+               return err
+       }
+
+       dataDeploy := &appsv1.Deployment{
+               ObjectMeta: metav1.ObjectMeta{
+                       Namespace: platform.Namespace,
+                       Name:      platform.Name + "-" + common.DataIndexName,
+                       Labels:    lbl,
+               }}
+       if err := controllerutil.SetControllerReference(platform, dataDeploy, 
client.Scheme()); err != nil {
+               return err
+       }
+
+       // Create or Update the deployment
+       if op, err := controllerutil.CreateOrUpdate(ctx, client, dataDeploy, 
func() error {
+               dataDeploy.Spec = dataDeploySpec
+
+               return nil
+       }); err != nil {
+               return err
+       } else {
+               klog.V(log.I).InfoS("Deployment successfully reconciled", 
"operation", op)
+       }
+
+       return nil
+}
+
+func configurePersistence(ctx context.Context, client client.Client, 
dataDeployContainer *corev1.Container, platform 
*operatorapi.SonataFlowPlatform) {
+       if platform.Spec.Services.Persistence != nil {
+               if platform.Spec.Services.Persistence.PostgreSql != nil {
+                       configurePostgreSql(ctx, client, dataDeployContainer, 
platform)
+               }
+       }
+}
+
+func configurePostgreSql(ctx context.Context, client client.Client, 
dataDeployContainer *corev1.Container, platform 
*operatorapi.SonataFlowPlatform) {
+       persistenceType := common.PersistenceTypePostgressql
+       dataDeployContainer.Image = common.DataIndexImageBase + persistenceType
+
+       databaseNamespace := platform.Namespace
+       if 
len(platform.Spec.Services.Persistence.PostgreSql.ServiceRef.Namespace) > 0 {
+               databaseNamespace = 
platform.Spec.Services.Persistence.PostgreSql.ServiceRef.Namespace
+       }
+       dataSourcePort := 5432
+       if platform.Spec.Services.Persistence.PostgreSql.ServiceRef.Port != nil 
{
+               dataSourcePort = 
*platform.Spec.Services.Persistence.PostgreSql.ServiceRef.Port
+       }
+       databaseName := "sonataflow"
+       if len(platform.Spec.Services.Persistence.PostgreSql.DatabaseName) > 0 {
+               databaseName = 
platform.Spec.Services.Persistence.PostgreSql.DatabaseName
+       }
+       dataSourceUrl := "jdbc:" + persistenceType + "://" + 
platform.Spec.Services.Persistence.PostgreSql.ServiceRef.Name + "." + 
databaseNamespace + ":" + strconv.Itoa(dataSourcePort) + "/" + databaseName + 
"?currentSchema=data-index-service"
+
+       secretRef := corev1.LocalObjectReference{
+               Name: 
platform.Spec.Services.Persistence.PostgreSql.SecretRef.Name,
+       }
+       quarkusDatasourceUsername := "POSTGRESQL_USER"
+       if len(platform.Spec.Services.Persistence.PostgreSql.SecretRef.UserKey) 
> 0 {
+               quarkusDatasourceUsername = 
platform.Spec.Services.Persistence.PostgreSql.SecretRef.UserKey
+       }
+       quarkusDatasourcePassword := "POSTGRESQL_PASSWORD"
+       if 
len(platform.Spec.Services.Persistence.PostgreSql.SecretRef.PasswordKey) > 0 {
+               quarkusDatasourcePassword = 
platform.Spec.Services.Persistence.PostgreSql.SecretRef.PasswordKey
+       }
+       persistEnvVars := []corev1.EnvVar{
+               {
+                       Name: "QUARKUS_DATASOURCE_USERNAME",
+                       ValueFrom: &corev1.EnvVarSource{
+                               SecretKeyRef: &corev1.SecretKeySelector{
+                                       Key:                  
quarkusDatasourceUsername,
+                                       LocalObjectReference: secretRef,
+                               },
+                       },
+               },
+               {
+                       Name: "QUARKUS_DATASOURCE_PASSWORD",
+                       ValueFrom: &corev1.EnvVarSource{
+                               SecretKeyRef: &corev1.SecretKeySelector{
+                                       Key:                  
quarkusDatasourcePassword,
+                                       LocalObjectReference: secretRef,
+                               },
+                       },
+               },
+               {
+                       Name:  "QUARKUS_DATASOURCE_DB_KIND",
+                       Value: persistenceType,
+               },
+               {
+                       Name:  "QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION",
+                       Value: "update",
+               },
+               {
+                       Name:  "QUARKUS_FLYWAY_MIGRATE_AT_START",
+                       Value: "true",
+               },
+               {
+                       Name:  "QUARKUS_DATASOURCE_JDBC_URL",
+                       Value: dataSourceUrl,
+               },
+       }
+       dataDeployContainer.Env = append(dataDeployContainer.Env, 
persistEnvVars...)
+}
+
+func createDataIndexService(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       lbl := map[string]string{
+               workflowproj.LabelApp: platform.Name,
+       }
+       dataSvcSpec := corev1.ServiceSpec{
+               Ports: []corev1.ServicePort{
+                       {
+                               Name:       httpPort,
+                               Protocol:   corev1.ProtocolTCP,
+                               Port:       80,
+                               TargetPort: 
common.DefaultHTTPWorkflowPortIntStr,
+                       },
+               },
+               Selector: lbl,
+       }
+       dataSvc := &corev1.Service{
+               ObjectMeta: metav1.ObjectMeta{
+                       Namespace: platform.Namespace,
+                       Name:      platform.Name + "-" + common.DataIndexName,
+                       Labels:    lbl,
+               }}
+       if err := controllerutil.SetControllerReference(platform, dataSvc, 
client.Scheme()); err != nil {
+               return err
+       }
+
+       // Create or Update the service
+       if op, err := controllerutil.CreateOrUpdate(ctx, client, dataSvc, 
func() error {
+               dataSvc.Spec = dataSvcSpec
+
+               return nil
+       }); err != nil {
+               return err
+       } else {
+               klog.V(log.I).InfoS("Service successfully reconciled", 
"operation", op)
+       }
+
+       return nil
+}
+
+// createDataIndexConfigMap ...
+func createDataIndexConfigMap(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       configMap := &corev1.ConfigMap{
+               ObjectMeta: metav1.ObjectMeta{
+                       Name:      platform.Name + "-" + common.DataIndexName,
+                       Namespace: platform.Namespace,
+                       Labels: map[string]string{
+                               workflowproj.LabelApp: platform.Name,
+                       },
+               },
+       }
+       if err := controllerutil.SetControllerReference(platform, configMap, 
client.Scheme()); err != nil {
+               return err
+       }
+
+       // Create or Update the service
+       if op, err := controllerutil.CreateOrUpdate(ctx, client, configMap, 
func() error {
+               configMap.Data = map[string]string{
+                       "application.properties": 
"quarkus.smallrye-health.check.\"io.quarkus.kafka.client.health.KafkaHealthCheck\".enabled=false\n",

Review Comment:
   Maybe we should use 
https://github.com/apache/incubator-kie-kogito-serverless-operator/blob/main/controllers/profiles/common/app_properties.go#L43
 to control this. Users might require changes to this CM. wdyt? We can open a 
follow up issue and do it in a different PR if you prefer, thou.



##########
controllers/platform/services.go:
##########
@@ -0,0 +1,360 @@
+// Copyright 2023 Red Hat, Inc. and/or its affiliates
+//
+// Licensed 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 platform
+
+import (
+       "context"
+       "strconv"
+       "strings"
+
+       appsv1 "k8s.io/api/apps/v1"
+       corev1 "k8s.io/api/core/v1"
+       "k8s.io/apimachinery/pkg/api/resource"
+       metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+       "k8s.io/klog/v2"
+       "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
+
+       operatorapi 
"github.com/apache/incubator-kie-kogito-serverless-operator/api/v1alpha08"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/container-builder/client"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/controllers/profiles/common"
+       "github.com/apache/incubator-kie-kogito-serverless-operator/log"
+       
"github.com/apache/incubator-kie-kogito-serverless-operator/workflowproj"
+       "github.com/imdario/mergo"
+)
+
+var httpPort = strings.ToLower(string(corev1.URISchemeHTTP))
+
+// NewServiceAction returns an action that deploys the services.
+func NewServiceAction() Action {
+       return &serviceAction{}
+}
+
+type serviceAction struct {
+       baseAction
+}
+
+func (action *serviceAction) Name() string {
+       return "service"
+}
+
+func (action *serviceAction) CanHandle(platform 
*operatorapi.SonataFlowPlatform) bool {
+       return platform.Status.IsReady()
+}
+
+func (action *serviceAction) Handle(ctx context.Context, platform 
*operatorapi.SonataFlowPlatform) (*operatorapi.SonataFlowPlatform, error) {
+       // Refresh applied configuration
+       if err := ConfigureDefaults(ctx, action.client, platform, false); err 
!= nil {
+               return nil, err
+       }
+
+       if err := createDataIndexComponents(ctx, action.client, platform); err 
!= nil {
+               return nil, err
+       }
+
+       return platform, nil
+}
+
+func createDataIndexComponents(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       if platform.Spec.Services.DataIndex != nil {
+               if err := createDataIndexConfigMap(ctx, client, platform); err 
!= nil {
+                       return err
+               }
+               if err := createDataIndexDeployment(ctx, client, platform); err 
!= nil {
+                       return err
+               }
+               if err := createDataIndexService(ctx, client, platform); err != 
nil {
+                       return err
+               }
+       }
+
+       return nil
+}
+
+func createDataIndexDeployment(ctx context.Context, client client.Client, 
platform *operatorapi.SonataFlowPlatform) error {
+       probe := &corev1.Probe{
+               ProbeHandler: corev1.ProbeHandler{
+                       HTTPGet: &corev1.HTTPGetAction{
+                               Path:   "/q/health/ready",

Review Comment:
   Can we move these strings to constants? There are more here that I believe 
we can keep them on `const`s. wdyt?



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