jordigilh commented on code in PR #372:
URL: 
https://github.com/apache/incubator-kie-kogito-serverless-operator/pull/372#discussion_r1471302526


##########
api/v1alpha08/sonataflowplatform_types.go:
##########
@@ -46,6 +46,57 @@ type SonataFlowPlatformSpec struct {
        // `sonataflow.org/profile: prod`
        // +optional
        Services ServicesPlatformSpec `json:"services,omitempty"`
+       // Persistence defines the platform persistence configuration. When 
this field is set,
+       // the configuration is used as the persistence for platform services 
and sonataflow instances
+       // that don't provide one of their own.
+       // +optional
+       Persistence *PlatformPersistenceSpec `json:"persistence,omitempty"`
+}
+
+// PlatformPersistenceSpec configures the DataBase support for both platform 
services and workflows. For services, it allows
+// configuring a generic database connectivity if the service does not come 
with its own configured. In case of the workflow
+// the configuration is defined by the image name of the supported database. 
When the workflow is configured to require
+// a database backend type supported by the platform (that is, the platform CR 
contains an image name for that database type)
+// , the workflow pod is configured to contain a sidecar container running the 
database image defined here, and the workflow
+// JDBC connectivity is setup to point to the DB container.

Review Comment:
   Done



##########
api/v1alpha08/sonataflowplatform_types.go:
##########
@@ -46,6 +46,57 @@ type SonataFlowPlatformSpec struct {
        // `sonataflow.org/profile: prod`
        // +optional
        Services ServicesPlatformSpec `json:"services,omitempty"`
+       // Persistence defines the platform persistence configuration. When 
this field is set,
+       // the configuration is used as the persistence for platform services 
and sonataflow instances
+       // that don't provide one of their own.
+       // +optional
+       Persistence *PlatformPersistenceSpec `json:"persistence,omitempty"`
+}
+
+// PlatformPersistenceSpec configures the DataBase support for both platform 
services and workflows. For services, it allows
+// configuring a generic database connectivity if the service does not come 
with its own configured. In case of the workflow
+// the configuration is defined by the image name of the supported database. 
When the workflow is configured to require
+// a database backend type supported by the platform (that is, the platform CR 
contains an image name for that database type)
+// , the workflow pod is configured to contain a sidecar container running the 
database image defined here, and the workflow
+// JDBC connectivity is setup to point to the DB container.
+// +optional
+type PlatformPersistenceSpec struct {
+       // Connect configured services to a postgresql database.
+       // +optional
+       PostgreSQL *PostgreSQLPlatformSpec `json:"postgresql,omitempty"`
+}
+
+// PostgreSQLPlatformSpec provides the generic configuration details to 
configure the JDBC URL and establish a connection for each managed services 
when they don't provide their own configuration.
+type PostgreSQLPlatformSpec struct {
+       // SecretRef contains the database user credentials
+       SecretRef SecretReference `json:"secretRef"`
+       // ServiceRef contains the K8s service name and namespace location of 
the PostgreSQL service.
+       ServiceRef ServiceReference `json:"serviceRef,omitempty"`
+       // Name of postgresql database to be used. Defaults to "sonataflow"
+       // +kubebuilder:default:=sonataflow
+       DatabaseName string `json:"databaseName,omitempty"`
+}
+
+type ServiceReference struct {
+       // Name contains the name of the kubernetes service. This field is 
mandatory.
+       // +required
+       Name string `json:"name"`
+       // Namespace contains the name of the namespace where the kubernetes 
service resides. This field is optional.
+       // +optional
+       Namespace string `json:"namespace"`
+       // Port contains the port number associated to the kubernetes service. 
This field is mandatory.
+       // +required
+       Port int `json:"port,omitempty"`
+}
+
+// SecretReference use of a secret to store the credentials to authenticate in 
the JDBC connection.
+type SecretReference struct {
+       // Name of the postgresql credentials secret. This field is mandatory.
+       Name string `json:"name"`
+       // +optional
+       UserKey string `json:"userKey,omitempty"`
+       // +optional
+       PasswordKey string `json:"passwordKey,omitempty"`
 }

Review Comment:
   Done



##########
controllers/platform/services/services.go:
##########
@@ -138,13 +138,25 @@ func (d DataIndexHandler) MergePodSpec(podSpec 
corev1.PodSpec) (corev1.PodSpec,
        return *c, err
 }
 
+// hasPostgreSQLConfigured returns true when either the SonataFlow Platform 
PostgreSQL CR's structure or the one in the Data Index service specification is 
not nil
+func (d DataIndexHandler) hasPostgreSQLConfigured() bool {
+       return (d.platform.Spec.Services.DataIndex.Persistence != nil && 
d.platform.Spec.Services.DataIndex.Persistence.PostgreSql != nil) ||
+               (d.platform.Spec.Persistence != nil && 
d.platform.Spec.Persistence.PostgreSQL != nil)
+}
+
 func (d DataIndexHandler) ConfigurePersistence(containerSpec 
*corev1.Container) *corev1.Container {
-       if d.platform.Spec.Services.DataIndex.Persistence != nil && 
d.platform.Spec.Services.DataIndex.Persistence.PostgreSql != nil {
+
+       if d.hasPostgreSQLConfigured() {
+               p := d.platform.Spec.Services.DataIndex.Persistence
                c := containerSpec.DeepCopy()
                c.Image = 
d.GetServiceImageName(constants.PersistenceTypePostgreSQL)
-               c.Env = append(c.Env, 
persistence.ConfigurePostgreSqlEnv(d.platform.Spec.Services.DataIndex.Persistence.PostgreSql,
 d.GetServiceName(), d.platform.Namespace)...)
+               if d.platform.Spec.Services.DataIndex.Persistence != nil && 
d.platform.Spec.Services.DataIndex.Persistence.PostgreSql != nil {
+                       c.Env = append(c.Env, 
persistence.ConfigurePostgreSQLEnv(p.PostgreSql, d.GetServiceName(), 
d.platform.Namespace)...)
+               } else {
+                       c.Env = append(c.Env, 
persistence.ConfigurePostgreSQLEnvFromPlatformSpec(d.platform.Spec.Persistence.PostgreSQL,
 d.GetServiceName())...)
+               }
                // specific to DataIndex
-               c.Env = append(c.Env, corev1.EnvVar{Name: 
quarkusHibernateORMDatabaseGeneration, Value: "update"}, corev1.EnvVar{Name: 
quarkusFlywayMigrateAtStart, Value: "true"})
+               c.Env = append(c.Env, corev1.EnvVar{Name: 
"QUARKUS_HIBERNATE_ORM_DATABASE_GENERATION", Value: "update"}, 
corev1.EnvVar{Name: "QUARKUS_FLYWAY_MIGRATE_AT_START", Value: "true"})

Review Comment:
   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]

Reply via email to