Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kie-issues#2789: [sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator #2790

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

rhkp
Copy link
Contributor

@rhkp rhkp commented Dec 4, 2024

Closes #2789
Implement DB Migrator Changes into SonataFlow Operator.

const (
dbMigrationJobName = "sonataflow-db-migrator-job"
dbMigrationContainerName = "db-migration-container"
dbMigratorToolImage = "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to "docker.io/apache/incubator-kie-kogito-db-migrator-tool:latest" as named in DB Migrator Image package here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, unresolving this and reverting to old image for sake of seeing how CI behaves.

Copy link
Contributor

@wmedvede wmedvede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @rhkp I have added some comments, but couldn't finish the review.
Will continue on this after Christmas.

Many thanks!

@tiagobento
Copy link
Contributor

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!

@rhkp
Copy link
Contributor Author

rhkp commented Dec 23, 2024

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 will make use of the image created by PR#2697.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wmedvede Where are DI and JS in this file? Please advise.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhkp your observation is good, and mine too 🤔

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?

Comment on lines +33 to +34
# 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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not forget to replace with apache image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed as soon as the image PR is approved and image is available, we will do the same.

@pkliczewski
Copy link

@ricardozanini @wmedvede once #2697, will this PR get approved or is there any more work needed?

@wmedvede
Copy link
Contributor

wmedvede commented Jan 27, 2025

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:

image

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.

@rhkp
Copy link
Contributor Author

rhkp commented Jan 27, 2025

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:

image

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 ,
The image package has been updated and now works with OpenShift as well. Please do check and let me know if you face any problems.
image
FYI only, prior to this, I had tried the following 3 approaches, which unfortunately did not work.

  1. Use Maven Archiver with classpath options.
  2. Use Quarkus Class Loading by specifying loading quarkus runner first.
  3. Use classpath option in java -jar command while executing the image.

@wmedvede
Copy link
Contributor

wmedvede commented Feb 3, 2025

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:

DataBase-DB-Migrator

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:

DataBase-DataIndex

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:

MissingSqlFiles

would you mind take a look ?

@rhkp rhkp force-pushed the flpath-1909-work branch from f0687a7 to 7f1d3d2 Compare February 3, 2025 19:34
@rhkp
Copy link
Contributor Author

rhkp commented Feb 3, 2025

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:

DataBase-DB-Migrator

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:

DataBase-DataIndex

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:

MissingSqlFiles

would you mind take a look ?

Hi @wmedvede / @ricardozanini,
The DB Migrator will now apply persistence-commons sql files too for data-index. Please let me know if this is in-line with your expectations?
Thanks.

@pkliczewski
Copy link

@wmedvede @ricardozanini any news about this?

@pkliczewski
Copy link

@ricardozanini any progress with this change?

@ricardozanini
Copy link
Member

@jakubschwan can you please verify?

@@ -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"
Copy link
Member

@ricardozanini ricardozanini Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
dbMigratorToolImageTag: "quay.io/rhkp/incubator-kie-kogito-service-db-migration-postgresql:latest"
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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhkp ^

Copy link
Contributor Author

@rhkp rhkp Feb 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member

@ricardozanini ricardozanini left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rhkp can you please double check the image tag?

Many thanks for this work, we really appreciate!

@rhkp
Copy link
Contributor Author

rhkp commented Feb 19, 2025

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

image

@ricardozanini
Copy link
Member

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

@rhkp
Copy link
Contributor Author

rhkp commented Feb 19, 2025

@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 by @tiagobento we switched to using main there.
  • So the kogito-db-migrator-tool-image package is correct and we shouldn't change it.

@ricardozanini
Copy link
Member

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

@rhkp
Copy link
Contributor Author

rhkp commented Feb 20, 2025

@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 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 and to you too that we do not have the docker.io/apache image yet available on hub.docker as shown in screenshot 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?

@ricardozanini
Copy link
Member

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

@rhkp
Copy link
Contributor Author

rhkp commented Feb 21, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[sonataflow-operator] Implement DB Migrator Changes into SonataFlow Operator
6 participants