You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "rhkp (via GitHub)" <gi...@apache.org> on 2024/12/04 15:36:41 UTC
[PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
rhkp opened a new pull request, #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790
Closes #2789
Implement DB Migrator Changes into SonataFlow Operator.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2673032802
> @rhkp I'm not talking about changing the image name here, but in this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image
>
> Can you please double-check if all the naming there is correct and **have the expected** tag name?
>
> If there's a place in that package that the name is not `docker.io/apache/incubator-kie-kogito-db-migrator-tool`, we won't be able to run anything.
>
> And I have a ticket to create the Dockerhub namespace: https://issues.apache.org/jira/browse/INFRA-26557
>
> Once it's created we can run the Jenkins job to publish the first tag and you change it here if the PR is still opened.
Thanks @ricardozanini. This clarifies it and I will check it first thing start of the next week and submit change PR if needed.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "pkliczewski (via GitHub)" <gi...@apache.org>.
pkliczewski commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2678374298
@wmedvede any changes you would like to see being done as part of this PR?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894306059
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
@wmedvede I am not in favor of renaming this with `operator` as I think calling this `operator` causes confusing with a go operator, which is not the case?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1918867587
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
+
+ dbMigratorJob, err := action.createOrUpdateDBMigrationJob(ctx, action.client, platform, psDI, psJS)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJob != nil {
+ klog.V(log.E).InfoS("Created DB migration job")
+ dbMigratorJobStatus, err := dbMigratorJob.ReconcileDBMigrationJob(ctx, action.client, platform)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJobStatus.Failed == 1 {
+ return nil, errors.New("DB migration job failed")
+ } else if dbMigratorJobStatus.Succeeded == 1 {
+ return platform, nil
+ } else {
+ // DB migration is still running
+ return nil, nil
+ }
+ }
+
+ return platform, nil
+}
+
+func (action *serviceAction) isJobsBasedDBMigration(platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) bool {
Review Comment:
Moved to db_migrator_job.go and now won't belong to serviceAction.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "jakubschwan (via GitHub)" <gi...@apache.org>.
jakubschwan commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1923813149
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -54,10 +62,13 @@ type PersistenceOptionsSpec struct {
// +optional
PostgreSQL *PersistencePostgreSQL `json:"postgresql,omitempty"`
- // Whether to migrate database on service startup?
+ // DB Migration approach for service?
Review Comment:
Please update the description to better describe the configuration for DB migration. And remove the question mark from the description.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,428 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+ "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+type DBMigratorJobStatus struct {
+ Name string
+ BatchJobStatus *batchv1.JobStatus
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+// IsJobsBasedDBMigration returns whether job based db migration approach is needed?
+func IsJobsBasedDBMigration(platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) bool {
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ return (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration)
+}
+
+func createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ job := createJobDBMigration(platform, dbMigratorJob)
+ klog.V(log.I).InfoS("Starting DB Migration Job: ", "namespace", platform.Namespace, "job", job.Name)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op, "namespace", platform.Namespace, "job", job.Name)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+// HandleDBMigrationJob Creates db migration job and executes it on the cluster
+func HandleDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
+
+ dbMigratorJob, err := createOrUpdateDBMigrationJob(ctx, client, platform, psDI, psJS)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJob != nil {
+ klog.V(log.E).InfoS("Created DB migration job")
+ dbMigratorJobStatus, err := dbMigratorJob.ReconcileDBMigrationJob(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJobStatus.BatchJobStatus.Failed == 1 {
+ return nil, errors.New("DB migration job " + dbMigratorJobStatus.Name + " failed in namespace: " + platform.Namespace)
+ } else if dbMigratorJobStatus.BatchJobStatus.Succeeded == 1 {
Review Comment:
As there are functions for checking these statuses, can you replace these conditions by functions `hasFailed` and `hasSucceeded`?
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
do not forget to replace with apache image
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894144756
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
Review Comment:
default schema names for the services must be consistent with what we do for each service, "defaultDI" is not good.
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
@rhkp @ricardozanini wondering if we should call this strategy "operator" instead :thinking: , and we don't "expose" how it is performed.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
Review Comment:
I'd prefer to call this method simply newQuarkusDataSource
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
Review Comment:
same here, default schema name "defaultJs", not good.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
align with the new name apache/incubator-kie-kogito-db-migrator-tool and be sure that:
1. the tag is derived with a mechanism similar to what we have for the DataIndex and Jobs Serivce
2. we have a corresponding entry in the packages/sonataflow-operator/config/manager/controllers_cfg.yaml, and that we do an analogous processing to what we do for the DataIndex and Jobs Service images.
i.e., if we have an image configured in the controllers_cfg.yaml, then, this image wins. see also, packages/sonataflow-operator/internal/controller/cfg/controllers_cfg.go and the processing we do for DI and JS.
If not, we must still get the image name and mostly the tag from a common place, see: https://github.com/apache/incubator-kie-tools/blob/3933d90d67c8272813200b3c5615bf02a4ba49d0/packages/sonataflow-operator/internal/controller/platform/services/services.go#L141
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
Review Comment:
I think this method is not covering all cases well.
Follow the PersistencePostgreSQL struct, and see: PostgreSQLServiceOptions
type PostgreSQLServiceOptions struct {
*SQLServiceOptions `json:",inline"`
// Schema of postgresql database to be used. Defaults to "data-index-service"
// +optional
DatabaseSchema string `json:"databaseSchema,omitempty"`
}
Take a look at this also please: https://sonataflow.org/serverlessworkflow/main/cloud/operator/supporting-services.html#_configuring_the_supporting_services_persistence
The services persistence configurations supports various configuration alternatives.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+// CreateJobDBMigration Creates DB Migration Job and returns to the caller
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := getDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: "MIGRATE_DB_DATAINDEX",
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL",
+ Value: diQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_USERNAME",
+ Value: diQuarkusDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD",
+ Value: diQuarkusDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS",
+ Value: diQuarkusDataSource.Schema,
+ },
+ {
+ Name: "MIGRATE_DB_JOBSSERVICE",
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL",
+ Value: jsQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME",
+ Value: jsQuarkusDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD",
+ Value: jsQuarkusDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS",
+ Value: jsQuarkusDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getDBMigrationJobCfg() *DBMigrationJobCfg {
Review Comment:
newDBMigrationJobCfg instead?
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+// CreateJobDBMigration Creates DB Migration Job and returns to the caller
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := getDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: "MIGRATE_DB_DATAINDEX",
Review Comment:
I think we should use constants for this env var names.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1920722025
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
Review Comment:
Hi @wmedvede!
Somewhat inspired by https://github.com/apache/incubator-kie-tools/blob/main/packages/sonataflow-operator/internal/controller/platform/services/services_test.go I have added them now.
Please let me know if that is not in-line with the expecatations.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1919294541
##########
packages/sonataflow-operator/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml:
##########
Review Comment:
@wmedvede Where are DI and JS in this file? Please advise.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1919313818
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
Review Comment:
Hi @wmedvede!
They are included here e.g.
* [Service Based Migration](https://github.com/rhkp/incubator-kie-tools/blob/ab197e99ea446da684baa2a533a68413e2e23e22/packages/sonataflow-operator/test/e2e/platform_test.go#L229)
* [Job Based Migration](https://github.com/rhkp/incubator-kie-tools/blob/ab197e99ea446da684baa2a533a68413e2e23e22/packages/sonataflow-operator/test/e2e/platform_test.go#L282)
Please let me know if you are referring to something else.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1872021470
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
Review Comment:
We need this structure in all cases for use CreateJobDBMigration() function and not checking for the structure to be nil.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2671983063
> > > @rhkp I meant to review this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image to check if the image tag name is correct.
> >
> >
> > Hi @ricardozanini I understand what you are referring to.
> >
> > * Please note in the `kogito-db-migrator-tool-image` package currently we are making use of tag `main`.
> > * Earlier we were using `latest` tag.
> > * However based on [this review comment](https://github.com/apache/incubator-kie-tools/pull/2697#discussion_r1917118786) by @tiagobento we switched to using `main` there.
> > * So the `kogito-db-migrator-tool-image` package is correct and we shouldn't change it.
>
> So every place required the tag `docker.io/apache/incubator-kie-kogito-db-migrator-tool` is correct? I'm not referring to the tag version, but the whole naming.
Hi @ricardozanini
I totally agree we need to change the image names in `sonataflow-operator` package from `quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest` to `docker.io/apache/incubator-kie-kogito-db-migrator-tool:main`.
But please refer to my earlier [comment to @jakubschwan ](https://github.com/apache/incubator-kie-tools/pull/2790/files#r1924217939) and [to you too](https://github.com/apache/incubator-kie-tools/pull/2790/files#r1962263527) that we do not have the `docker.io/apache` image yet available on hub.docker as shown in [screenshot](https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2669579956) shared yesterday. So we cannot update this image right now in this package.
If we change the name at this moment to non-existent image, the operator will not work with DB migration job as the desired image `docker.io/apache/incubator-kie-kogito-db-migrator-tool:main` does not exist.
My recommendation is to keep the current name **only for now** so the testing can proceed. And as soon as the real `docker.io/apache` image for db migration is **available**, we will update this one.
Please let me know if we are on same understanding or still we have some difference in understanding?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2559754190
> Can someone please help me understand the relationship between this PR and #2697?
>
> This PR's issue has no description, which makes it hard to follow what's the overall plan for the DB Migrator image.
>
> Thanks!
In short, the SonataFlow Operator [PR#2790](https://github.com/apache/incubator-kie-tools/pull/2790) will make use of the image created by [PR#2697](https://github.com/apache/incubator-kie-tools/pull/2697).
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1924217939
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
Agreed as soon as the image PR is approved and image is available, we will do the same.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1979998584
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -229,41 +236,61 @@ func HandleDBMigrationJob(ctx context.Context, client client.Client, platform *o
return platform, nil
}
-func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+func newQuarkusDataSource(jdbcURL string, secretRefName string, secretUserKey string, secretPasswordKey string, schema string) *QuarkusDataSource {
return &QuarkusDataSource{
- JdbcUrl: jdbcURL,
- Username: userName,
- Password: password,
- Schema: schema,
+ JdbcUrl: jdbcURL,
+ SecretRefName: secretRefName,
+ SecretUserKey: secretUserKey,
+ SecretPasswordKey: secretPasswordKey,
+ Schema: schema,
}
}
func createJobDBMigration(platform *operatorapi.SonataFlowPlatform, dbmj *DBMigratorJob) *batchv1.Job {
// In DB Migrator Tool, smallrye will throw error for empty string "" while initializing properties.
// So use an empty space as a default value. Please see more at: https://github.com/eclipse/microprofile-config/issues/671
nonEmptyValue := " "
- diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
- jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
if dbmj.MigrateDBDataIndex && dbmj.DataIndexDataSource != nil {
diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
- diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
- diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.SecretRefName = dbmj.DataIndexDataSource.SecretRefName
+ diQuarkusDataSource.SecretUserKey = dbmj.DataIndexDataSource.SecretUserKey
+ diQuarkusDataSource.SecretPasswordKey = dbmj.DataIndexDataSource.SecretPasswordKey
diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
}
if dbmj.MigrateDBJobsService && dbmj.JobsServiceDataSource != nil {
jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
- jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
- jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.SecretRefName = dbmj.JobsServiceDataSource.SecretRefName
+ jsQuarkusDataSource.SecretUserKey = dbmj.JobsServiceDataSource.SecretUserKey
+ jsQuarkusDataSource.SecretPasswordKey = dbmj.JobsServiceDataSource.SecretPasswordKey
jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
}
+ diDBSecretRef := corev1.LocalObjectReference{
+ Name: diQuarkusDataSource.SecretRefName,
+ }
+
+ jsDBSecretRef := corev1.LocalObjectReference{
+ Name: jsQuarkusDataSource.SecretRefName,
+ }
+
dbMigrationJobCfg := newDBMigrationJobCfg()
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: dbMigrationJobCfg.JobName,
Namespace: platform.Namespace,
+ Labels: map[string]string{
+ workflowproj.LabelApp: platform.Name,
+ workflowproj.LabelAppNamespace: platform.Namespace,
+ workflowproj.LabelK8SComponent: fmt.Sprintf("%s-%s", platform.Name, dbMigrationJobCfg.JobName),
+ workflowproj.LabelK8SManagedBy: "sonataflow-operator",
+ workflowproj.LabelK8SName: dbMigrationJobCfg.JobName,
+ workflowproj.LabelK8SPartOF: platform.Name,
+ workflowproj.LabelService: fmt.Sprintf("%s-%s", "sonataflow-db-job", dbMigrationJobCfg.JobName),
Review Comment:
Why not creating a `GetDefaultLabelsMap` and refactor `GetDefaultLabels` to use the latter, so we reuse the method's body? We should not repeat ourselves in this case since labels must be manipulated in a single place.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2679160786
@rhkp the repository has been created: https://hub.docker.com/r/apache/kie-kogito-db-migrator-tool
As you can see, they removed the `incubator-` prefix. Can you update this PR and the packages merged accordingly? So that we can run Jenkins and check if the `:main` tag is pushed correctly?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1871971192
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
Updated to `"docker.io/apache/incubator-kie-kogito-db-migrator-tool:latest"` as named in DB Migrator Image package [here](https://github.com/rhkp/incubator-kie-tools/blob/flpath-1775-pr1/packages/kogito-db-migrator-tool-image/resources/incubator-kie-kogito-db-migrator-tool-image.yaml#L19).
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894296522
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
@wmedvede @ricardozanini I have updated the names as suggested, as follows
type DBMigrationOperatorType string
const (
DBMigrationOperatorService DBMigrationOperatorType = "service"
DBMigrationOperatorJob DBMigrationOperatorType = "job"
DBMigrationOperatorNone DBMigrationOperatorType = "none"
)
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1896078064
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,302 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
Review Comment:
Please check the changes now and let me know if meets your expectations.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1922267074
##########
packages/sonataflow-operator/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml:
##########
Review Comment:
@rhkp your observation is good, and mine too :thinking:
Rethinking here, It looks like we have a sort of outdated (and not necessarily outdated) specification of the CustomResourceDefinitions in this file... i.e., not all the fields were always added to the respective CRDs.
Some fields were added, and some other don't.
For example:
we have things like `path: services.jobService.podTemplate` but we don't have things like `services.jobService.persistence`
Which makes me think that not all the fields for the different CRDs owned by this operator where added to this file along the time. Question is, do we need them all added there? I think that not, see below.
Also, by looking at here: https://olm.operatorframework.io/docs/concepts/crds/clusterserviceversion I think the full specification of each CRD in that list is not needed (that information is not used for creating the respective CRDs), instead we could just only declare file the list of owned resources by this operator....
@ricardozanini is my reasoning correct?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2615992495
Hi @rhkp , I have built the db-migrator locally and pushed to my quay, etc, and also the latest changes in this RP.
Then, after installing everything in my OpenShift, etc, when deploying a SonataFlowPlatorm I go this error:

This is the platform I was working with:
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
name: sonataflow-platform
spec:
services:
dataIndex:
enabled: true
persistence:
dbMigrationStrategy: job
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
databaseSchema: data-index-schema
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
jobService:
enabled: true
persistence:
dbMigrationStrategy: job
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
databaseSchema: jobs-service-schema
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
However, the migrator tool image works well if I execute it locally.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2669299878
@jakubschwan can you please verify?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2692103188
@rhkp
**Persistence configuration at the SonataFlowPlatform not working:**
When we configure a platform like below, the migrator job creation procedure is calculating wrong the namespaces for the ID and JS respectively.
```
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
name: sonataflow-platform
spec:
services:
dataIndex:
enabled: true
persistence:
dbMigrationStrategy: job
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
jobService:
enabled: true
persistence:
dbMigrationStrategy: job
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
persistence:
postgresql:
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
serviceRef:
name: postgres
databaseName: sonataflow
```
Migrator job generator configures this:

The regular deployment procedure in that particular use case calculates this for each service:


--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2692092360
@rhkp
**Migrator job labels**
Similar to what we have for the other DI / JS, we must add the following labels to the migrator job.

--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2692093540
@rhkp
**Migrator job ownerReferences:**
Similar to what we have for the DI / JS we must configure the owner of the migrator job at creation time.
[see DI and JS as example]( https://github.com/apache/incubator-kie-tools/blob/aab8cc107809a519cf1650daf2c255cfd40a443a/packages/sonataflow-operator/internal/controller/platform/k8s.go#L197)

--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2694451699
@rhkp
**DB migrator Job uses user and password directly instead of secretKeyRef**
The db migrator job must be configured to use secretKeyRef for both DI and JS DB parameters, similar to what we are doing for these services.

--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894306059
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
@wmedvede I guess we should keep it as it is. Renaming this with `operator` causes confusing with a go operator, which is not the case specifically for these vars and are anyway part of SonataFlow-Operator?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "tiagobento (via GitHub)" <gi...@apache.org>.
tiagobento commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2557875484
Can someone please help me understand the relationship between this PR and https://github.com/apache/incubator-kie-tools/pull/2697?
This PR's issue has no description, which makes it hard to follow what's the overall plan for the DB Migrator image.
Thanks!
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1871981701
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := getNewQuarkusDataSource("", "", "", "")
+ quarkusDataSourceJobService := getNewQuarkusDataSource("", "", "", "")
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+ dbMigrationJobCfg := getDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: "MIGRATE_DB_DATAINDEX",
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL",
+ Value: dbmj.DataIndexDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_USERNAME",
+ Value: dbmj.DataIndexDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD",
+ Value: dbmj.DataIndexDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS",
+ Value: dbmj.DataIndexDataSource.Schema,
+ },
+ {
+ Name: "MIGRATE_DB_JOBSSERVICE",
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL",
+ Value: dbmj.JobsServiceDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME",
+ Value: dbmj.JobsServiceDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD",
+ Value: dbmj.JobsServiceDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS",
+ Value: dbmj.JobsServiceDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: dbMigratorToolImage,
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == 1 {
Review Comment:
May be not: as dbMigratorJobStatus is of type *batchv1.JobStatus defined in batch/v1/types.go with int32 data type.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1871998428
##########
packages/sonataflow-operator/internal/controller/platform/services/services.go:
##########
@@ -233,18 +249,51 @@ func (d *DataIndexHandler) hasPostgreSQLConfigured() bool {
(d.platform.Spec.Persistence != nil && d.platform.Spec.Persistence.PostgreSQL != nil))
}
+func GetDBMigrationStrategy(persistence *operatorapi.PersistenceOptionsSpec) operatorapi.DBMigrationStrategyType {
+ dbMigrationStrategy := operatorapi.DBMigrationStrategyNone
+
+ if persistence != nil {
+ return operatorapi.DBMigrationStrategyType(persistence.DBMigrationStrategy)
+ }
+
+ return dbMigrationStrategy
+}
+
+func IsServiceBasedDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyService
+}
+
+func IsJobsBasedDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyJob
+}
+
+func IsNoDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyNone || dbMigrationStrategy == ""
+}
+
+func isDBMigrationStrategyService(persistence *v1alpha08.PersistenceOptionsSpec) string {
Review Comment:
Great point. The `isDBMigrationStrategyService` function returns `string` version of serviceBasedDBMigration boolean flag. The string value is later used as follows in `ConfigurePersistence()` function
`
// specific to DataIndex
c.Env = append(c.Env, corev1.EnvVar{Name: quarkusHibernateORMDatabaseGeneration, Value: "update"}, corev1.EnvVar{Name: quarkusFlywayMigrateAtStart, Value: dbMigrationStrategyService})
`
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1871989928
##########
packages/sonataflow-operator/api/v1alpha08/sonataflowplatform_services_types.go:
##########
@@ -23,6 +23,11 @@ import (
// ServicesPlatformSpec describes the desired service configuration for workflows without the `sonataflow.org/profile: dev` annotation.
type ServicesPlatformSpec struct {
+ // true = Use DB Migration Job with DB Migrator tool image
+ // false = Use built-in DB migration capability within services e.g. DI/JS
+ // +optional
+ // +default: false
+ JobBasedDbMigration bool `json:"jobBasedDbMigration,omitempty"`
Review Comment:
I think this line is an invalid and has been removed as we are making use of dbMigrationStrategy and not jobBasedDbMigration.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1975847847
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
Resolving this as the image is now being pointed to `docker.io` instead of `quay.io/rhkp`.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2692124114
@rhkp
**Wrong default schema calculation when not set in the persistence config.**
When we configure a SPF like below, see that we are not providing the schema name.
```
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
name: sonataflow-platform
spec:
services:
dataIndex:
enabled: true
persistence:
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
jobService:
enabled: true
persistence:
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
```
The operator produces the following default schema name calculations for DI and JS

But, if we enable the DB migrator on the same SFP:
```
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
name: sonataflow-platform
spec:
services:
dataIndex:
enabled: true
persistence:
dbMigrationStrategy: job
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
jobService:
enabled: true
persistence:
dbMigrationStrategy: job
postgresql:
serviceRef:
name: postgres
databaseName: sonataflow
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
podTemplate:
initContainers:
- name: init-postgres
image: registry.access.redhat.com/ubi9/ubi-minimal:latest
imagePullPolicy: IfNotPresent
command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
```
We get the following results:
Migrator job generated these by default wrong schema names:

DI deployment was generated with the correct by default schema name:

JS deployment was generated with the correct by default schema name:

Migrator job must generate the correct by default schema names
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1978330776
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -229,41 +236,61 @@ func HandleDBMigrationJob(ctx context.Context, client client.Client, platform *o
return platform, nil
}
-func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+func newQuarkusDataSource(jdbcURL string, secretRefName string, secretUserKey string, secretPasswordKey string, schema string) *QuarkusDataSource {
return &QuarkusDataSource{
- JdbcUrl: jdbcURL,
- Username: userName,
- Password: password,
- Schema: schema,
+ JdbcUrl: jdbcURL,
+ SecretRefName: secretRefName,
+ SecretUserKey: secretUserKey,
+ SecretPasswordKey: secretPasswordKey,
+ Schema: schema,
}
}
func createJobDBMigration(platform *operatorapi.SonataFlowPlatform, dbmj *DBMigratorJob) *batchv1.Job {
// In DB Migrator Tool, smallrye will throw error for empty string "" while initializing properties.
// So use an empty space as a default value. Please see more at: https://github.com/eclipse/microprofile-config/issues/671
nonEmptyValue := " "
- diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
- jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
if dbmj.MigrateDBDataIndex && dbmj.DataIndexDataSource != nil {
diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
- diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
- diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.SecretRefName = dbmj.DataIndexDataSource.SecretRefName
+ diQuarkusDataSource.SecretUserKey = dbmj.DataIndexDataSource.SecretUserKey
+ diQuarkusDataSource.SecretPasswordKey = dbmj.DataIndexDataSource.SecretPasswordKey
diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
}
if dbmj.MigrateDBJobsService && dbmj.JobsServiceDataSource != nil {
jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
- jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
- jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.SecretRefName = dbmj.JobsServiceDataSource.SecretRefName
+ jsQuarkusDataSource.SecretUserKey = dbmj.JobsServiceDataSource.SecretUserKey
+ jsQuarkusDataSource.SecretPasswordKey = dbmj.JobsServiceDataSource.SecretPasswordKey
jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
}
+ diDBSecretRef := corev1.LocalObjectReference{
+ Name: diQuarkusDataSource.SecretRefName,
+ }
+
+ jsDBSecretRef := corev1.LocalObjectReference{
+ Name: jsQuarkusDataSource.SecretRefName,
+ }
+
dbMigrationJobCfg := newDBMigrationJobCfg()
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: dbMigrationJobCfg.JobName,
Namespace: platform.Namespace,
+ Labels: map[string]string{
+ workflowproj.LabelApp: platform.Name,
+ workflowproj.LabelAppNamespace: platform.Namespace,
+ workflowproj.LabelK8SComponent: fmt.Sprintf("%s-%s", platform.Name, dbMigrationJobCfg.JobName),
+ workflowproj.LabelK8SManagedBy: "sonataflow-operator",
+ workflowproj.LabelK8SName: dbMigrationJobCfg.JobName,
+ workflowproj.LabelK8SPartOF: platform.Name,
+ workflowproj.LabelService: fmt.Sprintf("%s-%s", "sonataflow-db-job", dbMigrationJobCfg.JobName),
Review Comment:
Hi @ricardozanini ,
Please note GetDefaultLabels(workflow *operatorapi.SonataFlow) needs SonataFlow which we do not have available in DB Migrator Job and thus we won't be able to use it.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1873792629
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_Job.go:
##########
@@ -0,0 +1,301 @@
+/*
Review Comment:
The name of the file has a capitalized `J`.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2616585100
> Hi @rhkp , I have built the db-migrator locally and pushed to my quay, etc, and also the latest changes in this RP.
>
> Then, after installing everything in my OpenShift, etc, when deploying a SonataFlowPlatorm I go this error:
>
> 
>
> This is the platform I was working with:
>
> ```
> apiVersion: sonataflow.org/v1alpha08
> kind: SonataFlowPlatform
> metadata:
> name: sonataflow-platform
> spec:
> services:
> dataIndex:
> enabled: true
> persistence:
> dbMigrationStrategy: job
> postgresql:
> serviceRef:
> name: postgres
> databaseName: sonataflow
> databaseSchema: data-index-schema
> secretRef:
> name: postgres-secrets
> userKey: POSTGRESQL_USER
> passwordKey: POSTGRESQL_PASSWORD
> podTemplate:
> initContainers:
> - name: init-postgres
> image: registry.access.redhat.com/ubi9/ubi-minimal:latest
> imagePullPolicy: IfNotPresent
> command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
> jobService:
> enabled: true
> persistence:
> dbMigrationStrategy: job
> postgresql:
> serviceRef:
> name: postgres
> databaseName: sonataflow
> databaseSchema: jobs-service-schema
> secretRef:
> name: postgres-secrets
> userKey: POSTGRESQL_USER
> passwordKey: POSTGRESQL_PASSWORD
> podTemplate:
> initContainers:
> - name: init-postgres
> image: registry.access.redhat.com/ubi9/ubi-minimal:latest
> imagePullPolicy: IfNotPresent
> command: [ 'sh', '-c', 'until (echo 1 > /dev/tcp/postgres.$(cat /var/run/secrets/kubernetes.io/serviceaccount/namespace).svc.cluster.local/5432) >/dev/null 2>&1; do echo "Waiting for postgres server"; sleep 3; done;' ]
> ```
>
> However, the migrator tool image works well if I execute it locally.
Hi @wmedvede ,
I am trying to make use of the DI/JS images from `registry.redhat.io` but seeing `ImagePullBack` errors while deploying SFP. Anything specific to be done there, before using these images?
jobsServicePostgreSQLImageTag: "[registry.redhat.io/openshift-serverless-1/logic-jobs-service-postgresql-rhel8:1.35.0](http://registry.redhat.io/openshift-serverless-1/logic-jobs-service-postgresql-rhel8:1.35.0)"
dataIndexPostgreSQLImageTag: "[registry.redhat.io/openshift-serverless-1/logic-data-index-postgresql-rhel8:1.35.0](http://registry.redhat.io/openshift-serverless-1/logic-data-index-postgresql-rhel8:1.35.0)"
<img width="807" alt="image" src="https://github.com/user-attachments/assets/9553302d-4baa-4d52-b9ec-0a75d9b29cc5" />
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1919160574
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := newDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: migrateDBDataIndex,
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: quarkusDataSourceDataIndexJdbcURL,
+ Value: diQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceDataIndexUserName,
+ Value: diQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceDataIndexPassword,
+ Value: diQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayDataIndexSchemas,
+ Value: diQuarkusDataSource.Schema,
+ },
+ {
+ Name: migrateDBJobsService,
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: quarkusDataSourceJobsServiceJdbcURL,
+ Value: jsQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceJobsServiceUserName,
+ Value: jsQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceJobsServicePassword,
+ Value: jsQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayJobsServiceSchemas,
+ Value: jsQuarkusDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getKogitoDBMigratorToolImageName() string {
+
+ imgTag := cfg.GetCfg().KogitoDBMigratorToolImageTag
+
+ if imgTag == "" {
+ // returns "docker.io/apache/incubator-kie-kogito-db-migrator-tool:<tag>"
+ imgTag = fmt.Sprintf("%s-%s:%s", constants.ImageNamePrefix, constants.KogitoDBMigratorTool, version.GetImageTagVersion())
+ }
+ return imgTag
+}
+
+func newDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: getKogitoDBMigratorToolImageName(),
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == dbMigrationJobFailed {
Review Comment:
Also added hasSucceeded method there.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1918428174
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
Review Comment:
same for this method, I don't believe it belongs to the serviceAction struct
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := newDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: migrateDBDataIndex,
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: quarkusDataSourceDataIndexJdbcURL,
+ Value: diQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceDataIndexUserName,
+ Value: diQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceDataIndexPassword,
+ Value: diQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayDataIndexSchemas,
+ Value: diQuarkusDataSource.Schema,
+ },
+ {
+ Name: migrateDBJobsService,
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: quarkusDataSourceJobsServiceJdbcURL,
+ Value: jsQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceJobsServiceUserName,
+ Value: jsQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceJobsServicePassword,
+ Value: jsQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayJobsServiceSchemas,
+ Value: jsQuarkusDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getKogitoDBMigratorToolImageName() string {
+
+ imgTag := cfg.GetCfg().KogitoDBMigratorToolImageTag
+
+ if imgTag == "" {
+ // returns "docker.io/apache/incubator-kie-kogito-db-migrator-tool:<tag>"
+ imgTag = fmt.Sprintf("%s-%s:%s", constants.ImageNamePrefix, constants.KogitoDBMigratorTool, version.GetImageTagVersion())
+ }
+ return imgTag
+}
+
+func newDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: getKogitoDBMigratorToolImageName(),
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == dbMigrationJobFailed {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = UpdateSonataFlowPlatformDBMigrationPhase(platform.Status.SonataFlowPlatformDBMigrationPhase, operatorapi.DBMigrationStatusFailed, operatorapi.MessageDBMigrationStatusFailed, operatorapi.ReasonDBMigrationStatusFailed)
+ klog.V(log.I).InfoS("DB migration job failed")
+ return dbMigratorJobStatus, errors.New("DB migration job failed")
Review Comment:
Information about the job namespace and name would be nice here for future error tracing.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := newDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: migrateDBDataIndex,
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: quarkusDataSourceDataIndexJdbcURL,
+ Value: diQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceDataIndexUserName,
+ Value: diQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceDataIndexPassword,
+ Value: diQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayDataIndexSchemas,
+ Value: diQuarkusDataSource.Schema,
+ },
+ {
+ Name: migrateDBJobsService,
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: quarkusDataSourceJobsServiceJdbcURL,
+ Value: jsQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceJobsServiceUserName,
+ Value: jsQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceJobsServicePassword,
+ Value: jsQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayJobsServiceSchemas,
+ Value: jsQuarkusDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getKogitoDBMigratorToolImageName() string {
+
+ imgTag := cfg.GetCfg().KogitoDBMigratorToolImageTag
+
+ if imgTag == "" {
+ // returns "docker.io/apache/incubator-kie-kogito-db-migrator-tool:<tag>"
+ imgTag = fmt.Sprintf("%s-%s:%s", constants.ImageNamePrefix, constants.KogitoDBMigratorTool, version.GetImageTagVersion())
+ }
+ return imgTag
+}
+
+func newDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: getKogitoDBMigratorToolImageName(),
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == dbMigrationJobFailed {
Review Comment:
I think this conditions to check the failure or sucesss fo the the job by using constants with the same value == 1 is a bit confusing when we read this method.
I'd recommend creating a function e.g. hasFailed(status * JobStatus) and do this calculations there instead
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
Review Comment:
same here, namespace and job name is very welcome
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
+
+ dbMigratorJob, err := action.createOrUpdateDBMigrationJob(ctx, action.client, platform, psDI, psJS)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJob != nil {
+ klog.V(log.E).InfoS("Created DB migration job")
+ dbMigratorJobStatus, err := dbMigratorJob.ReconcileDBMigrationJob(ctx, action.client, platform)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJobStatus.Failed == 1 {
+ return nil, errors.New("DB migration job failed")
+ } else if dbMigratorJobStatus.Succeeded == 1 {
+ return platform, nil
+ } else {
+ // DB migration is still running
+ return nil, nil
+ }
+ }
+
+ return platform, nil
+}
+
+func (action *serviceAction) isJobsBasedDBMigration(platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) bool {
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ return (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration)
+}
+
func (action *serviceAction) Handle(ctx context.Context, platform *operatorapi.SonataFlowPlatform) (*operatorapi.SonataFlowPlatform, *corev1.Event, error) {
// Refresh applied configuration
if err := CreateOrUpdateWithDefaults(ctx, platform, false); err != nil {
return nil, nil, err
}
psDI := services.NewDataIndexHandler(platform)
+ psJS := services.NewJobServiceHandler(platform)
+
+ if action.isJobsBasedDBMigration(platform, psDI, psJS) {
+ p, err := action.handleDBMigrationJob(ctx, platform, psDI, psJS)
+ if p == nil {
Review Comment:
if p == nill we return the err...., not good.
I suggest making this more clear as part of the suggestions for the isJobBasedDBMigration and handleDBMigratonJob functions.
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
Review Comment:
printing the job namespace and name will be very helpful for future error tracing, etc.
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
+
+ dbMigratorJob, err := action.createOrUpdateDBMigrationJob(ctx, action.client, platform, psDI, psJS)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJob != nil {
+ klog.V(log.E).InfoS("Created DB migration job")
+ dbMigratorJobStatus, err := dbMigratorJob.ReconcileDBMigrationJob(ctx, action.client, platform)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJobStatus.Failed == 1 {
+ return nil, errors.New("DB migration job failed")
+ } else if dbMigratorJobStatus.Succeeded == 1 {
+ return platform, nil
+ } else {
+ // DB migration is still running
+ return nil, nil
+ }
+ }
+
+ return platform, nil
+}
+
+func (action *serviceAction) isJobsBasedDBMigration(platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) bool {
Review Comment:
I believe this method is not particularly belonging to the serviceAction.
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
+
+ dbMigratorJob, err := action.createOrUpdateDBMigrationJob(ctx, action.client, platform, psDI, psJS)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJob != nil {
+ klog.V(log.E).InfoS("Created DB migration job")
+ dbMigratorJobStatus, err := dbMigratorJob.ReconcileDBMigrationJob(ctx, action.client, platform)
+ if err != nil {
+ return nil, err
+ }
+ if dbMigratorJobStatus.Failed == 1 {
+ return nil, errors.New("DB migration job failed")
+ } else if dbMigratorJobStatus.Succeeded == 1 {
+ return platform, nil
+ } else {
+ // DB migration is still running
+ return nil, nil
+ }
+ }
+
+ return platform, nil
+}
+
+func (action *serviceAction) isJobsBasedDBMigration(platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) bool {
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
Review Comment:
Consider my comments regarding a potential persistence configuration at the SFP level
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+
+ diQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+ jsQuarkusDataSource := newQuarkusDataSource("", "", "", "")
+
+ if dbmj.DataIndexDataSource != nil {
+ diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
+ diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
+ diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
+ }
+
+ if dbmj.JobsServiceDataSource != nil {
+ jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
+ jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
+ jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
+ }
+
+ dbMigrationJobCfg := newDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: migrateDBDataIndex,
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: quarkusDataSourceDataIndexJdbcURL,
+ Value: diQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceDataIndexUserName,
+ Value: diQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceDataIndexPassword,
+ Value: diQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayDataIndexSchemas,
+ Value: diQuarkusDataSource.Schema,
+ },
+ {
+ Name: migrateDBJobsService,
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: quarkusDataSourceJobsServiceJdbcURL,
+ Value: jsQuarkusDataSource.JdbcUrl,
+ },
+ {
+ Name: quarkusDataSourceJobsServiceUserName,
+ Value: jsQuarkusDataSource.Username,
+ },
+ {
+ Name: quarkusDataSourceJobsServicePassword,
+ Value: jsQuarkusDataSource.Password,
+ },
+ {
+ Name: quarkusFlywayJobsServiceSchemas,
+ Value: jsQuarkusDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getKogitoDBMigratorToolImageName() string {
+
+ imgTag := cfg.GetCfg().KogitoDBMigratorToolImageTag
+
+ if imgTag == "" {
+ // returns "docker.io/apache/incubator-kie-kogito-db-migrator-tool:<tag>"
+ imgTag = fmt.Sprintf("%s-%s:%s", constants.ImageNamePrefix, constants.KogitoDBMigratorTool, version.GetImageTagVersion())
+ }
+ return imgTag
+}
+
+func newDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: getKogitoDBMigratorToolImageName(),
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == dbMigrationJobFailed {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = UpdateSonataFlowPlatformDBMigrationPhase(platform.Status.SonataFlowPlatformDBMigrationPhase, operatorapi.DBMigrationStatusFailed, operatorapi.MessageDBMigrationStatusFailed, operatorapi.ReasonDBMigrationStatusFailed)
+ klog.V(log.I).InfoS("DB migration job failed")
+ return dbMigratorJobStatus, errors.New("DB migration job failed")
+ } else if dbMigratorJobStatus.Succeeded == dbMigrationJobSucceeded {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = UpdateSonataFlowPlatformDBMigrationPhase(platform.Status.SonataFlowPlatformDBMigrationPhase, operatorapi.DBMigrationStatusSucceeded, operatorapi.MessageDBMigrationStatusSucceeded, operatorapi.ReasonDBMigrationStatusSucceeded)
+ klog.V(log.I).InfoS("DB migration job succeeded")
Review Comment:
same here
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2669579956
> @rhkp can you please double check the image tag?
>
> Many thanks for this work, we really appreciate!
Hi @ricardozanini,
Thanks for approvals and comments.
I do not have access to push to `apache` on docker registry.
Last I had understood the `incubator-kie-tools CI` will push the image and not sure, I still do not see image on hub.docker.com?
Once the image is there I can change this line? Please advise. Thanks.
<img width="1509" alt="image" src="https://github.com/user-attachments/assets/9cb2e4d8-a993-486e-9922-6ad140d1b2e3" />
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2672893622
@rhkp I'm not talking about changing the image name here, but in this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image
Can you please double-check if all the naming there is correct and **have the expected** tag name?
If there's a place in that package that the name is not `docker.io/apache/incubator-kie-kogito-db-migrator-tool`, we won't be able to run anything.
And I have a ticket to create the Dockerhub namespace: https://issues.apache.org/jira/browse/INFRA-26557
Once it's created we can run the Jenkins job to publish the first tag and you change it here if the PR is still opened.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1895947096
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
I am resolving this comment for now. Please un-resolve it, if my proposal above does not make sense.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1920722471
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
Review Comment:
Please see comment above. Added with inspiration from https://github.com/apache/incubator-kie-tools/blob/main/packages/sonataflow-operator/internal/controller/platform/services/services_test.go
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1920818714
##########
packages/sonataflow-operator/operator.yaml:
##########
@@ -19403,9 +19422,14 @@ spec:
for the workflow
maxProperties: 2
properties:
- migrateDBOnStartUp:
- description: Whether to migrate database on service startup?
- type: boolean
+ dbMigrationStrategy:
Review Comment:
@wmedvede
- This is added by `make generate-all` command automatically.
- This is being added even though `DBMigrationStrategy` is annotated with `+optional`, operator-sdk adds it in `operator.yaml`. Please see [this](https://github.com/apache/incubator-kie-tools/blob/ab197e99ea446da684baa2a533a68413e2e23e22/packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go#L69).
- Also, as the `PersistenceOptionsSpec` is included in [sonataflow_types.go](https://github.com/apache/incubator-kie-tools/blob/ab197e99ea446da684baa2a533a68413e2e23e22/packages/sonataflow-operator/api/v1alpha08/sonataflow_types.go#L147) by SonataFlowSpec struct.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1916795669
##########
packages/sonataflow-operator/operator.yaml:
##########
@@ -19403,9 +19422,14 @@ spec:
for the workflow
maxProperties: 2
properties:
- migrateDBOnStartUp:
- description: Whether to migrate database on service startup?
- type: boolean
+ dbMigrationStrategy:
Review Comment:
I think that if we are not implementing the dbMigrationStrategy for the workflows, we shouldn't add it in the SonataFlow CRD.
##########
packages/sonataflow-operator/config/manifests/bases/sonataflow-operator.clusterserviceversion.yaml:
##########
Review Comment:
I think the dbMigrationStrategy must be added to the DI and JS in this file too.
dbMigrationStrategy:
default: service
description: |-
DB Migration approach for service?
job: use job based approach
service: service itself shall migrate the db
none: no db migration needed
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+kogitoDBMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
For the other DI and JS imageTags, we just say, `jobsServicePostgreSQLImageTag`, `jobsServiceEphemeralImageTag`, `dataIndexPostgreSQLImageTag`, `dataIndexEphemeralImageTag` and we don't prefix with kogito, even when they are.
I think we should just say: `dbMigratorToolImageTag` for consistency.
And propagate the change along the controller config struct, etc.
wdyt? @ricardozanini @rhkp
##########
packages/sonataflow-operator/internal/controller/cfg/controllers_cfg.go:
##########
@@ -63,6 +63,7 @@ type ControllersCfg struct {
JobsServiceEphemeralImageTag string `yaml:"jobsServiceEphemeralImageTag,omitempty"`
DataIndexPostgreSQLImageTag string `yaml:"dataIndexPostgreSQLImageTag,omitempty"`
DataIndexEphemeralImageTag string `yaml:"dataIndexEphemeralImageTag,omitempty"`
+ KogitoDBMigratorToolImageTag string `yaml:"kogitoDBMigratorToolImageTag,omitempty"`
Review Comment:
see comments on this field name
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/job_based_db_migration/sonataflow-platform/01-sonataflow_platform.yaml:
##########
@@ -0,0 +1,43 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong license format
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/job_based_db_migration/pg-service/kustomization.yaml:
##########
@@ -0,0 +1,30 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong licence format
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
Unused constant
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
Review Comment:
This file needs tests, the same as we have for other ones.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
Review Comment:
Also, to get the default schema name, we do
https://github.com/apache/incubator-kie-tools/blob/ab197e99ea446da684baa2a533a68413e2e23e22/packages/sonataflow-operator/internal/controller/platform/services/services.go#L291
I think we should do something similar here instead of setting "data-index-service"
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
Review Comment:
and same comment for default schema name calculation, see: j.GetServiceName()
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/job_based_db_migration/pg-service/01-postgres.yaml:
##########
@@ -0,0 +1,85 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong licence format
##########
packages/sonataflow-operator/internal/controller/platform/services/secrets.go:
##########
@@ -0,0 +1,38 @@
+// Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong licence header, we don't use the yearly format.
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/job_based_db_migration/sonataflow-platform/kustomization.yaml:
##########
@@ -0,0 +1,19 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong license format
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/service_based_db_migration/01-postgres.yaml:
##########
@@ -0,0 +1,85 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong license format
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/service_based_db_migration/02-sonataflow_platform.yaml:
##########
@@ -0,0 +1,65 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong license format
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/service_based_db_migration/kustomization.yaml:
##########
@@ -0,0 +1,31 @@
+# Copyright 2024 Apache Software Foundation (ASF)
Review Comment:
wrong license format
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
Review Comment:
tests please
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
Review Comment:
I believe this calculations are kind of duplicated here: https://github.com/apache/incubator-kie-tools/blob/c690d462602da4cf2c01b90279815b60a1959162/packages/sonataflow-operator/internal/controller/profiles/common/persistence/postgresql.go#L44
I think we should explore moving this calculation postgresql.go and reuse.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "jobs-service")
Review Comment:
same as for the DI, see comment above.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource := &QuarkusDataSource{}
+ quarkusDataSource.JdbcUrl = getJdbcUrl(persistence.PostgreSQL, defaultSchemaName)
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ return quarkusDataSource
+ }
+
+ return nil
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := &QuarkusDataSource{}
+ quarkusDataSourceJobService := &QuarkusDataSource{}
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "data-index-service")
Review Comment:
When get the DataSource, we must consider the comments above, i.e., the potential case where the persistence is defined at the SPF level.
In the file packages/sonataflow-operator/internal/controller/profiles/common/persistence/postgresql.go I think we have some methods that can be useful for these calculations.
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
+ databaseSchema := defaultDBSchemaName
+ dataSourcePort := constants.DefaultPostgreSQLPort
+ databaseName := constants.DefaultDatabaseName
+ postgresServiceName := constants.DefaultPostgresServiceName
+
+ dataSourceURL := ""
+
+ if postgresql.ServiceRef != nil {
+ if len(postgresql.ServiceRef.DatabaseSchema) > 0 {
+ databaseSchema = postgresql.ServiceRef.DatabaseSchema
+ }
+ if postgresql.ServiceRef.Port != nil {
+ dataSourcePort = *postgresql.ServiceRef.Port
+ }
+ if len(postgresql.ServiceRef.DatabaseName) > 0 {
+ databaseName = postgresql.ServiceRef.DatabaseName
+ }
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresql.ServiceRef.Name, dataSourcePort, databaseName, databaseSchema)
+ } else if len(postgresql.JdbcUrl) > 0 {
+ dataSourceURL = postgresql.JdbcUrl
+ } else {
+ dataSourceURL = fmt.Sprintf("jdbc:postgresql://%s:%d/%s?currentSchema=%s", postgresServiceName, dataSourcePort, databaseName, databaseSchema)
+ }
+
+ return dataSourceURL
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
Review Comment:
Important:
Persistence configuration for a service can be taken not only from eg. spec.services.jobsService but also from the SPF global persistence configuration.
see:
https://sonataflow.org/serverlessworkflow/main/cloud/operator/supporting-services.html#common-persistence-configuration
https://sonataflow.org/serverlessworkflow/main/cloud/operator/using-persistence.html#configuring-persistence-using-the-sonataflowplatform-cr
Along this PR, we must consider that potential case too.
I.e, the service don't have "persistence", but the SPF do.
Examples:
```
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlowPlatform
metadata:
name: sonataflow-platform
spec:
services:
# no persistence is defined for the DI, it will take it from the SFP if any.
# and apply the by default DBMigrationStrategy
dataIndex:
enabled: true
jobService:
# The only persistence setting we do is the DBMigrationStrategy
# So, the service grabs the persistence configuation from the SPF and the given DBMigrationStrategy
# from here.
enabled: true
persistence:
dbMigrationStrategy: "job"
# global SPF persitence configuration.
persistence:
postgresql:
secretRef:
name: postgres-secrets
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
serviceRef:
name: postgres
databaseName: sonataflow
```
@rhkp take look please and propagate in all places where needed.
@ricardozanini see my considerations for this particular case, where a service takes the persistence from the SPF, but we still can mark at the service level the dbMigrationStrategy
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "pkliczewski (via GitHub)" <gi...@apache.org>.
pkliczewski commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2648096589
@wmedvede @ricardozanini any news about this?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2678760156
> docker.io/apache/incubator-kie-kogito-db-migrator-tool
Hi @ricardozanini,
I can confirm all the following image tags in the `kogito-db-migrator-tool-image` package are `docker.io/apache/incubator-kie-kogito-db-migrator-tool` tags as expected...
- [ReadMe#L31](https://github.com/apache/incubator-kie-tools/blob/main/packages/kogito-db-migrator-tool-image/README.md?plain=1#L31)
- [ReadMe#L67](https://github.com/apache/incubator-kie-tools/blob/main/packages/kogito-db-migrator-tool-image/README.md?plain=1#L67)
- [incubator-kie-kogito-db-migrator-tool-image.yaml#L19](https://github.com/apache/incubator-kie-tools/blob/main/packages/kogito-db-migrator-tool-image/resources/incubator-kie-kogito-db-migrator-tool-image.yaml#L19).
Please let me know if this is as per your expectations. If not I can look further into it.
Thanks.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2691220154
@rhkp I have been working on the error above, and we have potential fix for the productized image, that is slightly different that the one we generate in community. Same stuff, but with some minor configs different.
The image in community is good
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1978330776
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -229,41 +236,61 @@ func HandleDBMigrationJob(ctx context.Context, client client.Client, platform *o
return platform, nil
}
-func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+func newQuarkusDataSource(jdbcURL string, secretRefName string, secretUserKey string, secretPasswordKey string, schema string) *QuarkusDataSource {
return &QuarkusDataSource{
- JdbcUrl: jdbcURL,
- Username: userName,
- Password: password,
- Schema: schema,
+ JdbcUrl: jdbcURL,
+ SecretRefName: secretRefName,
+ SecretUserKey: secretUserKey,
+ SecretPasswordKey: secretPasswordKey,
+ Schema: schema,
}
}
func createJobDBMigration(platform *operatorapi.SonataFlowPlatform, dbmj *DBMigratorJob) *batchv1.Job {
// In DB Migrator Tool, smallrye will throw error for empty string "" while initializing properties.
// So use an empty space as a default value. Please see more at: https://github.com/eclipse/microprofile-config/issues/671
nonEmptyValue := " "
- diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
- jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
if dbmj.MigrateDBDataIndex && dbmj.DataIndexDataSource != nil {
diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
- diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
- diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.SecretRefName = dbmj.DataIndexDataSource.SecretRefName
+ diQuarkusDataSource.SecretUserKey = dbmj.DataIndexDataSource.SecretUserKey
+ diQuarkusDataSource.SecretPasswordKey = dbmj.DataIndexDataSource.SecretPasswordKey
diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
}
if dbmj.MigrateDBJobsService && dbmj.JobsServiceDataSource != nil {
jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
- jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
- jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.SecretRefName = dbmj.JobsServiceDataSource.SecretRefName
+ jsQuarkusDataSource.SecretUserKey = dbmj.JobsServiceDataSource.SecretUserKey
+ jsQuarkusDataSource.SecretPasswordKey = dbmj.JobsServiceDataSource.SecretPasswordKey
jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
}
+ diDBSecretRef := corev1.LocalObjectReference{
+ Name: diQuarkusDataSource.SecretRefName,
+ }
+
+ jsDBSecretRef := corev1.LocalObjectReference{
+ Name: jsQuarkusDataSource.SecretRefName,
+ }
+
dbMigrationJobCfg := newDBMigrationJobCfg()
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: dbMigrationJobCfg.JobName,
Namespace: platform.Namespace,
+ Labels: map[string]string{
+ workflowproj.LabelApp: platform.Name,
+ workflowproj.LabelAppNamespace: platform.Namespace,
+ workflowproj.LabelK8SComponent: fmt.Sprintf("%s-%s", platform.Name, dbMigrationJobCfg.JobName),
+ workflowproj.LabelK8SManagedBy: "sonataflow-operator",
+ workflowproj.LabelK8SName: dbMigrationJobCfg.JobName,
+ workflowproj.LabelK8SPartOF: platform.Name,
+ workflowproj.LabelService: fmt.Sprintf("%s-%s", "sonataflow-db-job", dbMigrationJobCfg.JobName),
Review Comment:
Hi @ricardozanini ,
Please note GetDefaultLabels(workflow *operatorapi.SonataFlow) needs SonataFlow which we do not have available in DB Migrator Job and thus we won't be able to use it.
Unless we create a fake workflow struct just for sake of getting labels. I feel it will confuse us later. Please let me know if this is what should we do it?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2690600988
Hi @rhkp , I have configured the operator locally to use the image produced by @rgdoliveira and that locally works fine:
registry-proxy.engineering.redhat.com/rh-osbs/openshift-serverless-1-logic-db-migrator-tool-rhel8:openshift-serverless-nightly-rhel-8-containers-candidate-68139-20250226193811](http://registry-proxy.engineering.redhat.com/rh-osbs/openshift-serverless-1-logic-db-migrator-tool-rhel8:openshift-serverless-nightly-rhel-8-containers-candidate-68139-20250226193811
I have just pushed it to my quay here, to simplify: quay.io/wmedvede/openshift-serverless-1-logic-db-migrator-tool-rhel8:openshift-serverless-nightly-rhel-8-containers-candidate-68139-20250226193811
All good, image locally works wood.
But, when the image is used by the db-migrator Job in OpenShift, I can see the following error:

The produced image by @rgdoliveira includes all the latest changes from main, since he has synchronized the latest changes from main.
would you mind take a look?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1962123213
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
```suggestion
dbMigratorToolImageTag: "docker.io/apache/incubator-kie-kogito-db-migrator-tool:latest"
```
Can you please also review this image name in the DBMigrator Image package? https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image
I think it's wrong there.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1962263527
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
I agree but we need the built image to be available on docker registry before we change this line. That is why we still have this comment in unresolved state. Once the image is available on docker, we will update this line and resolve this comment.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1871875459
##########
packages/sonataflow-operator/api/v1alpha08/sonataflowplatform_services_types.go:
##########
@@ -23,6 +23,11 @@ import (
// ServicesPlatformSpec describes the desired service configuration for workflows without the `sonataflow.org/profile: dev` annotation.
type ServicesPlatformSpec struct {
+ // true = Use DB Migration Job with DB Migrator tool image
+ // false = Use built-in DB migration capability within services e.g. DI/JS
+ // +optional
+ // +default: false
+ JobBasedDbMigration bool `json:"jobBasedDbMigration,omitempty"`
Review Comment:
Why do we have a `bool` value here, whereas the type is an `enum`? Is this attribute to propagate `DBMigrationStrategyType`? In this case, we should use the same field.
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
Review Comment:
The file names do not use `camelCase`. Please rename it to `db_migrator_job.go` and all other files.
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
Review Comment:
Instead, you should return nil to make it easier for client code to handle this structure. It's easier to just check if a variable is nil.
```go
func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
if persistence != nil && persistence.PostgreSQL != nil {
quarkusDataSource := &QuarkusDataSource{}
quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
return quarkusDataSource
}
return nil
}
```
##########
packages/sonataflow-operator/test/e2e/testdata/platform/persistence/service_based_db_migration/02-sonataflow_platform.yaml:
##########
@@ -0,0 +1,66 @@
+# Copyright 2024 Apache Software Foundation (ASF)
+#
+# 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.
+apiVersion: sonataflow.org/v1alpha08
+kind: SonataFlowPlatform
+metadata:
+ name: sonataflow-platform
+spec:
+ build:
+ config:
+ strategyOptions:
+ KanikoBuildCacheEnabled: "true"
+ services:
+ # jobBasedDbMigration: false
Review Comment:
Leftovers?
##########
packages/sonataflow-operator/internal/controller/platform/services/secrets.go:
##########
@@ -0,0 +1,41 @@
+// Copyright 2024 Apache Software Foundation (ASF)
+//
+// 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 services
+
+import (
+ "context"
+
+ corev1 "k8s.io/api/core/v1"
+ "k8s.io/klog/v2"
+ ctrl "sigs.k8s.io/controller-runtime/pkg/client"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/utils"
+)
+
+func GetSecretKeyValueString(ctx context.Context, secretName string, secretKey string, nameSpace string) (string, error) {
+ secret := corev1.Secret{}
+ err := utils.GetClient().Get(ctx, ctrl.ObjectKey{Namespace: nameSpace, Name: secretName}, &secret)
+ if err != nil {
+ panic(err.Error())
Review Comment:
Please don't do this, or you will break the operator run.
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
Review Comment:
These parameters are always passed in blank. You can simplify this by removing this function and just instantiate the struct instead:
```go
quarkusDataSource := &QuarkusDataSource{}
```
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
This image must come from the image package. So can you bring that here? Or we can merge the image first and then you review this const. I'm about to change this versioning/image naming in the operator package to read this info from ENV/Configuration.
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := getNewQuarkusDataSource("", "", "", "")
+ quarkusDataSourceJobService := getNewQuarkusDataSource("", "", "", "")
Review Comment:
Same comment here regarding the usage of this function.
##########
packages/sonataflow-operator/internal/controller/platform/services/services.go:
##########
@@ -233,18 +249,51 @@ func (d *DataIndexHandler) hasPostgreSQLConfigured() bool {
(d.platform.Spec.Persistence != nil && d.platform.Spec.Persistence.PostgreSQL != nil))
}
+func GetDBMigrationStrategy(persistence *operatorapi.PersistenceOptionsSpec) operatorapi.DBMigrationStrategyType {
+ dbMigrationStrategy := operatorapi.DBMigrationStrategyNone
+
+ if persistence != nil {
+ return operatorapi.DBMigrationStrategyType(persistence.DBMigrationStrategy)
+ }
+
+ return dbMigrationStrategy
+}
+
+func IsServiceBasedDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyService
+}
+
+func IsJobsBasedDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyJob
+}
+
+func IsNoDBMigration(persistence *operatorapi.PersistenceOptionsSpec) bool {
+ dbMigrationStrategy := GetDBMigrationStrategy(persistence)
+ return dbMigrationStrategy == operatorapi.DBMigrationStrategyNone || dbMigrationStrategy == ""
+}
+
+func isDBMigrationStrategyService(persistence *v1alpha08.PersistenceOptionsSpec) string {
Review Comment:
Why do we need this? Sound confusing since we already have the `IsServiceBasedDBMigration`.
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := getNewQuarkusDataSource("", "", "", "")
+ quarkusDataSourceJobService := getNewQuarkusDataSource("", "", "", "")
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+ dbMigrationJobCfg := getDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: "MIGRATE_DB_DATAINDEX",
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL",
+ Value: dbmj.DataIndexDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_USERNAME",
+ Value: dbmj.DataIndexDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD",
+ Value: dbmj.DataIndexDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS",
+ Value: dbmj.DataIndexDataSource.Schema,
+ },
+ {
+ Name: "MIGRATE_DB_JOBSSERVICE",
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL",
+ Value: dbmj.JobsServiceDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME",
+ Value: dbmj.JobsServiceDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD",
+ Value: dbmj.JobsServiceDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS",
+ Value: dbmj.JobsServiceDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: dbMigratorToolImage,
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == 1 {
Review Comment:
Can we use `bool` instead?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1872043751
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
Review Comment:
We should do a nil check when calling this function for all cases because persistence can be `nil` by reading your code.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1872282580
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
For now, unresolving this and reverting to old image for sake of seeing how CI behaves.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894296522
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
@wmedvede @ricardozanini I have updated the names as suggested, as follows
type DBMigrationOperatorType string
const (
DBMigrationOperatorService DBMigrationOperatorType = "service"
DBMigrationOperatorJob DBMigrationOperatorType = "job"
DBMigrationOperatorNone DBMigrationOperatorType = "none"
)
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
I am fine with suggested naming. @ricardozanini please confirm and we will replace it across the board from:
- `DBMigrationStrategyService` to `DBMigrationServiceOperator`
- `DBMigrationStrategyJob` to `DBMigrationJobOperator`
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "pkliczewski (via GitHub)" <gi...@apache.org>.
pkliczewski commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2666007609
@ricardozanini any progress with this change?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini merged PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1922670937
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -0,0 +1,356 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/version"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/cfg"
+ "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"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+ dbMigrationJobFailed = 1
+ dbMigrationJobSucceeded = 1
+
+ migrateDBDataIndex = "MIGRATE_DB_DATAINDEX"
+ quarkusDataSourceDataIndexJdbcURL = "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL"
+ quarkusDataSourceDataIndexUserName = "QUARKUS_DATASOURCE_DATAINDEX_USERNAME"
+ quarkusDataSourceDataIndexPassword = "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD"
+ quarkusFlywayDataIndexSchemas = "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS"
+
+ migrateDBJobsService = "MIGRATE_DB_JOBSSERVICE"
+ quarkusDataSourceJobsServiceJdbcURL = "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL"
+ quarkusDataSourceJobsServiceUserName = "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME"
+ quarkusDataSourceJobsServicePassword = "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD"
+ quarkusFlywayJobsServiceSchemas = "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ if persistencePostgreSQL != nil && persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+
+ if persistencePostgreSQL != nil && len(persistencePostgreSQL.JdbcUrl) > 0 {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getJdbcUrl(postgresql *operatorapi.PersistencePostgreSQL, defaultDBSchemaName string) string {
Review Comment:
I agree. Now we use JdbcURL calculations from postgresql.go.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1918879555
##########
packages/sonataflow-operator/internal/controller/platform/k8s.go:
##########
@@ -62,20 +63,86 @@ func (action *serviceAction) CanHandle(platform *operatorapi.SonataFlowPlatform)
return platform.Status.IsReady()
}
+func (action *serviceAction) createOrUpdateDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) (*DBMigratorJob, error) {
+ dbMigratorJob := NewDBMigratorJobData(ctx, action.client, platform, pshDI, pshJS)
+
+ // Invoke DB Migration only if both or either DI/JS services are requested, in addition to DBMigrationStrategyJob
+ if dbMigratorJob != nil {
+ klog.V(log.I).InfoS("Starting DB Migration Job: ")
+
+ job := dbMigratorJob.CreateJobDBMigration(platform)
+ if op, err := controllerutil.CreateOrUpdate(ctx, client, job, func() error {
+ return nil
+ }); err != nil {
+ return dbMigratorJob, err
+ } else {
+ klog.V(log.I).InfoS("DB Migration Job successfully created on cluster", "operation", op)
+ }
+ }
+ return dbMigratorJob, nil
+}
+
+func (action *serviceAction) handleDBMigrationJob(ctx context.Context, platform *operatorapi.SonataFlowPlatform, psDI services.PlatformServiceHandler, psJS services.PlatformServiceHandler) (*operatorapi.SonataFlowPlatform, error) {
Review Comment:
Moved to db_migrator_job.go and now won't belong to serviceAction.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2669763016
@rhkp I meant to review this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image to check if the image tag name is correct.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2669949246
> @rhkp I meant to review this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image to check if the image tag name is correct.
Hi @ricardozanini I understand what you are referring to.
- Please note in the `kogito-db-migrator-tool-image` package currently we are making use of tag `main`.
- Earlier we were using `latest` tag.
- However based on [this review comment](https://github.com/apache/incubator-kie-tools/pull/2697#discussion_r1917118786) by @tiagobento we switched to using `main` there.
- So the `kogito-db-migrator-tool-image` package is correct and we shouldn't change it.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "wmedvede (via GitHub)" <gi...@apache.org>.
wmedvede commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2631746350
Hi @rhkp ,
while doing some testing I have found a small issue in the DB Migrator:
Let me explain:
A database produced by the DB Migrator looks like this:

On the other hand, if we start the data index service (not using the db migrator) and we enable flyway for the data index, we can see a database like this:

So we have a 1.5.0 and 1.5.1 files that are included by the data index service but not by the db migrator.
This is basically because the data index service has a dependency on the `persistence-commons` module that incorporates the missing files.
Your work is good! but we need to make the db migrator incorporate the .sql files provided by that module.
See here in the db migrator build structure:

would you mind take a look ?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2631931280
> Hi @rhkp , while doing some testing I have found a small issue in the DB Migrator:
>
> Let me explain:
>
> A database produced by the DB Migrator looks like this:
>
> 
>
> On the other hand, if we start the data index service (not using the db migrator) and we enable flyway for the data index, we can see a database like this:
>
> 
>
> So we have a 1.5.0 and 1.5.1 files that are included by the data index service but not by the db migrator.
>
> This is basically because the data index service has a dependency on the `persistence-commons` module that incorporates the missing files.
>
> Your work is good! but we need to make the db migrator incorporate the .sql files provided by that module.
>
> See here in the db migrator build structure:
>
> 
>
> would you mind take a look ?
Hi @wmedvede / @ricardozanini,
Please note we are using maven's [`maven-dependency-plugin`](https://github.com/rhkp/incubator-kie-tools/blob/main/packages/kogito-db-migrator-tool/pom.xml#L69) to download ddl files dynamically and use them for DB migration for DI & JS .
Should not all the sql files needed by data-index and jobs-service be available from zip file that we download with maven-dependency-plugin?
Please advise.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "pkliczewski (via GitHub)" <gi...@apache.org>.
pkliczewski commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2615928557
@ricardozanini @wmedvede once https://github.com/apache/incubator-kie-tools/pull/2697, will this PR get approved or is there any more work needed?
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1894263414
##########
packages/sonataflow-operator/api/v1alpha08/sonataflow_persistence_types.go:
##########
@@ -17,6 +17,14 @@
package v1alpha08
+type DBMigrationStrategyType string
+
+const (
+ DBMigrationStrategyService DBMigrationStrategyType = "service"
+ DBMigrationStrategyJob DBMigrationStrategyType = "job"
Review Comment:
I am fine with suggested naming. @ricardozanini please confirm and we will replace it across the board from:
- `DBMigrationStrategyService` to `DBMigrationServiceOperator`
- `DBMigrationStrategyJob` to `DBMigrationJobOperator`
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1872042528
##########
packages/sonataflow-operator/internal/controller/platform/dbMigratorJob.go:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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 platform
+
+import (
+ "context"
+ "errors"
+ "strconv"
+ "strings"
+
+ batchv1 "k8s.io/api/batch/v1"
+ corev1 "k8s.io/api/core/v1"
+ metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
+ "k8s.io/klog/v2"
+ "k8s.io/utils/pointer"
+
+ operatorapi "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/api/v1alpha08"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/container-builder/client"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/internal/controller/platform/services"
+ "github.com/apache/incubator-kie-tools/packages/sonataflow-operator/log"
+)
+
+type QuarkusDataSource struct {
+ JdbcUrl string
+ Username string
+ Password string
+ Schema string
+}
+
+type DBMigratorJob struct {
+ MigrateDBDataIndex bool
+ DataIndexDataSource *QuarkusDataSource
+ MigrateDBJobsService bool
+ JobsServiceDataSource *QuarkusDataSource
+}
+
+const (
+ dbMigrationJobName = "sonataflow-db-migrator-job"
+ dbMigrationContainerName = "db-migration-container"
+ dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
+ dbMigrationCmd = "./migration.sh"
+)
+
+type DBMigrationJobCfg struct {
+ JobName string
+ ContainerName string
+ ToolImageName string
+ MigrationCmd string
+}
+
+func getDBSchemaName(persistencePostgreSQL *operatorapi.PersistencePostgreSQL, defaultSchemaName string) string {
+ jdbcURL := persistencePostgreSQL.JdbcUrl
+
+ if len(jdbcURL) == 0 {
+ if persistencePostgreSQL.ServiceRef != nil && len(persistencePostgreSQL.ServiceRef.DatabaseSchema) > 0 {
+ return persistencePostgreSQL.ServiceRef.DatabaseSchema
+ }
+ } else {
+ _, a, found := strings.Cut(jdbcURL, "currentSchema=")
+
+ if found {
+ if strings.Contains(a, "&") {
+ b, _, found := strings.Cut(a, "&")
+ if found {
+ return b
+ }
+ } else {
+ return a
+ }
+ }
+ }
+ return defaultSchemaName
+}
+
+func getNewQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+ return &QuarkusDataSource{
+ JdbcUrl: jdbcURL,
+ Username: userName,
+ Password: password,
+ Schema: schema,
+ }
+}
+
+func getQuarkusDataSourceFromPersistence(ctx context.Context, platform *operatorapi.SonataFlowPlatform, persistence *operatorapi.PersistenceOptionsSpec, defaultSchemaName string) *QuarkusDataSource {
+ quarkusDataSource := getNewQuarkusDataSource("", "", "", "")
+ if persistence != nil && persistence.PostgreSQL != nil {
+ quarkusDataSource.JdbcUrl = persistence.PostgreSQL.JdbcUrl
+ quarkusDataSource.Username, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.UserKey, platform.Namespace)
+ quarkusDataSource.Password, _ = services.GetSecretKeyValueString(ctx, persistence.PostgreSQL.SecretRef.Name, persistence.PostgreSQL.SecretRef.PasswordKey, platform.Namespace)
+ quarkusDataSource.Schema = getDBSchemaName(persistence.PostgreSQL, defaultSchemaName)
+ }
+ return quarkusDataSource
+}
+
+func NewDBMigratorJobData(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform, pshDI services.PlatformServiceHandler, pshJS services.PlatformServiceHandler) *DBMigratorJob {
+
+ diJobsBasedDBMigration := false
+ jsJobsBasedDBMigration := false
+
+ if pshDI.IsPersistenceEnabledtInSpec() {
+ diJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.DataIndex.Persistence)
+ }
+ if pshJS.IsPersistenceEnabledtInSpec() {
+ jsJobsBasedDBMigration = services.IsJobsBasedDBMigration(platform.Spec.Services.JobService.Persistence)
+ }
+
+ if (pshDI.IsServiceSetInSpec() && diJobsBasedDBMigration) || (pshJS.IsServiceSetInSpec() && jsJobsBasedDBMigration) {
+ quarkusDataSourceDataIndex := getNewQuarkusDataSource("", "", "", "")
+ quarkusDataSourceJobService := getNewQuarkusDataSource("", "", "", "")
+
+ if diJobsBasedDBMigration {
+ quarkusDataSourceDataIndex = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.DataIndex.Persistence, "defaultDi")
+ }
+
+ if jsJobsBasedDBMigration {
+ quarkusDataSourceJobService = getQuarkusDataSourceFromPersistence(ctx, platform, platform.Spec.Services.JobService.Persistence, "defaultJs")
+ }
+
+ return &DBMigratorJob{
+ MigrateDBDataIndex: diJobsBasedDBMigration,
+ DataIndexDataSource: quarkusDataSourceDataIndex,
+ MigrateDBJobsService: jsJobsBasedDBMigration,
+ JobsServiceDataSource: quarkusDataSourceJobService,
+ }
+ }
+ return nil
+}
+
+func (dbmj DBMigratorJob) CreateJobDBMigration(platform *operatorapi.SonataFlowPlatform) *batchv1.Job {
+ dbMigrationJobCfg := getDBMigrationJobCfg()
+ job := &batchv1.Job{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: dbMigrationJobCfg.JobName,
+ Namespace: platform.Namespace,
+ },
+ Spec: batchv1.JobSpec{
+ Template: corev1.PodTemplateSpec{
+ Spec: corev1.PodSpec{
+ Containers: []corev1.Container{
+ {
+ Name: dbMigrationJobCfg.ContainerName,
+ Image: dbMigrationJobCfg.ToolImageName,
+ Env: []corev1.EnvVar{
+ {
+ Name: "MIGRATE_DB_DATAINDEX",
+ Value: strconv.FormatBool(dbmj.MigrateDBDataIndex),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_JDBC_URL",
+ Value: dbmj.DataIndexDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_USERNAME",
+ Value: dbmj.DataIndexDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_DATAINDEX_PASSWORD",
+ Value: dbmj.DataIndexDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_DATAINDEX_SCHEMAS",
+ Value: dbmj.DataIndexDataSource.Schema,
+ },
+ {
+ Name: "MIGRATE_DB_JOBSSERVICE",
+ Value: strconv.FormatBool(dbmj.MigrateDBJobsService),
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_JDBC_URL",
+ Value: dbmj.JobsServiceDataSource.JdbcUrl,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_USERNAME",
+ Value: dbmj.JobsServiceDataSource.Username,
+ },
+ {
+ Name: "QUARKUS_DATASOURCE_JOBSSERVICE_PASSWORD",
+ Value: dbmj.JobsServiceDataSource.Password,
+ },
+ {
+ Name: "QUARKUS_FLYWAY_JOBSSERVICE_SCHEMAS",
+ Value: dbmj.JobsServiceDataSource.Schema,
+ },
+ },
+ Command: []string{
+ dbMigrationJobCfg.MigrationCmd,
+ },
+ },
+ },
+ RestartPolicy: "Never",
+ },
+ },
+ BackoffLimit: pointer.Int32(0),
+ },
+ }
+ return job
+}
+
+// GetDBMigrationJobStatus Returns db migration job status
+func (dbmj DBMigratorJob) GetDBMigrationJobStatus(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ job, err := client.BatchV1().Jobs(platform.Namespace).Get(ctx, dbMigrationJobName, metav1.GetOptions{})
+ if err != nil {
+ klog.V(log.E).InfoS("Error getting DB migrator job while monitoring completion: ", "error", err)
+ return nil, err
+ }
+ return &job.Status, nil
+}
+
+// NewSonataFlowPlatformDBMigrationPhase Returns a new DB migration phase for SonataFlowPlatform
+func NewSonataFlowPlatformDBMigrationPhase(status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ return &operatorapi.SonataFlowPlatformDBMigrationPhase{
+ Status: status,
+ Message: message,
+ Reason: reason,
+ }
+}
+
+// UpdateSonataFlowPlatformDBMigrationPhase Updates a given SonataFlowPlatformDBMigrationPhase with the supplied values
+func UpdateSonataFlowPlatformDBMigrationPhase(dbMigrationStatus *operatorapi.SonataFlowPlatformDBMigrationPhase, status operatorapi.DBMigrationStatus, message string, reason string) *operatorapi.SonataFlowPlatformDBMigrationPhase {
+ if dbMigrationStatus != nil {
+ dbMigrationStatus.Status = status
+ dbMigrationStatus.Message = message
+ dbMigrationStatus.Reason = reason
+ return dbMigrationStatus
+ }
+ return nil
+}
+
+func getDBMigrationJobCfg() *DBMigrationJobCfg {
+ return &DBMigrationJobCfg{
+ JobName: dbMigrationJobName,
+ ContainerName: dbMigrationContainerName,
+ ToolImageName: dbMigratorToolImage,
+ MigrationCmd: dbMigrationCmd,
+ }
+}
+
+// ReconcileDBMigrationJob Check the status of running DB migration job and return status
+func (dbmj DBMigratorJob) ReconcileDBMigrationJob(ctx context.Context, client client.Client, platform *operatorapi.SonataFlowPlatform) (*batchv1.JobStatus, error) {
+ platform.Status.SonataFlowPlatformDBMigrationPhase = NewSonataFlowPlatformDBMigrationPhase(operatorapi.DBMigrationStatusStarted, operatorapi.MessageDBMigrationStatusStarted, operatorapi.ReasonDBMigrationStatusStarted)
+
+ dbMigratorJobStatus, err := dbmj.GetDBMigrationJobStatus(ctx, client, platform)
+ if err != nil {
+ return nil, err
+ }
+
+ klog.V(log.I).InfoS("Db migration job status: ", "active", dbMigratorJobStatus.Active, "ready", dbMigratorJobStatus.Ready, "failed", dbMigratorJobStatus.Failed, "success", dbMigratorJobStatus.Succeeded, "CompletedIndexes", dbMigratorJobStatus.CompletedIndexes, "terminatedPods", dbMigratorJobStatus.UncountedTerminatedPods)
+
+ if dbMigratorJobStatus.Failed == 1 {
Review Comment:
In this case you can create a const instead of comparing to a Magic Number.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1873807528
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_Job.go:
##########
@@ -0,0 +1,301 @@
+/*
Review Comment:
Great catch...
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1962123213
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
```suggestion
dbMigratorToolImageTag: "docker.io/apache/incubator-kie-kogito-service-db-migration-postgresql:latest"
```
Can you please also review this image name in the DBMigrator Image package? https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image
I think it's wrong there.
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
@rhkp ^
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2671696693
> > @rhkp I meant to review this package: https://github.com/apache/incubator-kie-tools/tree/main/packages/kogito-db-migrator-tool-image to check if the image tag name is correct.
>
> Hi @ricardozanini I understand what you are referring to.
>
> * Please note in the `kogito-db-migrator-tool-image` package currently we are making use of tag `main`.
> * Earlier we were using `latest` tag.
> * However based on [this review comment](https://github.com/apache/incubator-kie-tools/pull/2697#discussion_r1917118786) by @tiagobento we switched to using `main` there.
> * So the `kogito-db-migrator-tool-image` package is correct and we shouldn't change it.
So every place required the tag `docker.io/apache/incubator-kie-kogito-db-migrator-tool` is correct? I'm not referring to the tag version, but the whole naming.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1962263527
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
I agree but we need the built image to be available on docker registry before we change this line.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#issuecomment-2679650542
> @rhkp the repository has been created: https://hub.docker.com/r/apache/kie-kogito-db-migrator-tool
>
> As you can see, they removed the `incubator-` prefix. Can you update this PR and the packages merged accordingly? So that we can run Jenkins and check if the `:main` tag is pushed correctly?
@ricardozanini Please check and acknowledge/merge this new [PR](https://github.com/apache/incubator-kie-tools/pull/2928) or let me know of changes to be made.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "rhkp (via GitHub)" <gi...@apache.org>.
rhkp commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1975847392
##########
packages/sonataflow-operator/config/manager/controllers_cfg.yaml:
##########
@@ -30,6 +30,8 @@ jobsServiceEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-jobs-servic
# The Data Index image to use, if empty the operator will use the default Apache Community one based on the current operator's version
dataIndexPostgreSQLImageTag: "docker.io/apache/incubator-kie-kogito-data-index-postgresql:main"
dataIndexEphemeralImageTag: "docker.io/apache/incubator-kie-kogito-data-index-ephemeral:main"
+# The Kogito PostgreSQL DB Migrator image to use (TBD: to replace with apache image)
+dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Review Comment:
Resolving this as the image is now being pointed to `docker.io` instead of `quay.io/rhkp`.
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org
Re: [PR] kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator [incubator-kie-tools]
Posted by "ricardozanini (via GitHub)" <gi...@apache.org>.
ricardozanini commented on code in PR #2790:
URL: https://github.com/apache/incubator-kie-tools/pull/2790#discussion_r1978304298
##########
packages/sonataflow-operator/internal/controller/platform/db_migrator_job.go:
##########
@@ -229,41 +236,61 @@ func HandleDBMigrationJob(ctx context.Context, client client.Client, platform *o
return platform, nil
}
-func newQuarkusDataSource(jdbcURL string, userName string, password string, schema string) *QuarkusDataSource {
+func newQuarkusDataSource(jdbcURL string, secretRefName string, secretUserKey string, secretPasswordKey string, schema string) *QuarkusDataSource {
return &QuarkusDataSource{
- JdbcUrl: jdbcURL,
- Username: userName,
- Password: password,
- Schema: schema,
+ JdbcUrl: jdbcURL,
+ SecretRefName: secretRefName,
+ SecretUserKey: secretUserKey,
+ SecretPasswordKey: secretPasswordKey,
+ Schema: schema,
}
}
func createJobDBMigration(platform *operatorapi.SonataFlowPlatform, dbmj *DBMigratorJob) *batchv1.Job {
// In DB Migrator Tool, smallrye will throw error for empty string "" while initializing properties.
// So use an empty space as a default value. Please see more at: https://github.com/eclipse/microprofile-config/issues/671
nonEmptyValue := " "
- diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
- jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ diQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
+ jsQuarkusDataSource := newQuarkusDataSource(nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue, nonEmptyValue)
if dbmj.MigrateDBDataIndex && dbmj.DataIndexDataSource != nil {
diQuarkusDataSource.JdbcUrl = dbmj.DataIndexDataSource.JdbcUrl
- diQuarkusDataSource.Username = dbmj.DataIndexDataSource.Username
- diQuarkusDataSource.Password = dbmj.DataIndexDataSource.Password
+ diQuarkusDataSource.SecretRefName = dbmj.DataIndexDataSource.SecretRefName
+ diQuarkusDataSource.SecretUserKey = dbmj.DataIndexDataSource.SecretUserKey
+ diQuarkusDataSource.SecretPasswordKey = dbmj.DataIndexDataSource.SecretPasswordKey
diQuarkusDataSource.Schema = dbmj.DataIndexDataSource.Schema
}
if dbmj.MigrateDBJobsService && dbmj.JobsServiceDataSource != nil {
jsQuarkusDataSource.JdbcUrl = dbmj.JobsServiceDataSource.JdbcUrl
- jsQuarkusDataSource.Username = dbmj.JobsServiceDataSource.Username
- jsQuarkusDataSource.Password = dbmj.JobsServiceDataSource.Password
+ jsQuarkusDataSource.SecretRefName = dbmj.JobsServiceDataSource.SecretRefName
+ jsQuarkusDataSource.SecretUserKey = dbmj.JobsServiceDataSource.SecretUserKey
+ jsQuarkusDataSource.SecretPasswordKey = dbmj.JobsServiceDataSource.SecretPasswordKey
jsQuarkusDataSource.Schema = dbmj.JobsServiceDataSource.Schema
}
+ diDBSecretRef := corev1.LocalObjectReference{
+ Name: diQuarkusDataSource.SecretRefName,
+ }
+
+ jsDBSecretRef := corev1.LocalObjectReference{
+ Name: jsQuarkusDataSource.SecretRefName,
+ }
+
dbMigrationJobCfg := newDBMigrationJobCfg()
job := &batchv1.Job{
ObjectMeta: metav1.ObjectMeta{
Name: dbMigrationJobCfg.JobName,
Namespace: platform.Namespace,
+ Labels: map[string]string{
+ workflowproj.LabelApp: platform.Name,
+ workflowproj.LabelAppNamespace: platform.Namespace,
+ workflowproj.LabelK8SComponent: fmt.Sprintf("%s-%s", platform.Name, dbMigrationJobCfg.JobName),
+ workflowproj.LabelK8SManagedBy: "sonataflow-operator",
+ workflowproj.LabelK8SName: dbMigrationJobCfg.JobName,
+ workflowproj.LabelK8SPartOF: platform.Name,
+ workflowproj.LabelService: fmt.Sprintf("%s-%s", "sonataflow-db-job", dbMigrationJobCfg.JobName),
Review Comment:
Use this instead: https://github.com/apache/incubator-kie-tools/blob/main/packages/sonataflow-operator/workflowproj/operator.go#L102-L129
--
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: commits-unsubscribe@kie.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org