7.2. Configuring persistence using the SonataFlow CR
The SonataFlow custom resource (CR) enables workflow-specific persistence configuration. You can use this configuration independently, even if SonataFlowPlatform persistence is already set up in the current namespace.
Procedure
-
Configure persistence by using the
persistencefield in theSonataFlowCR specification as shown in the following example:
apiVersion: sonataflow.org/v1alpha08
kind: SonataFlow
metadata:
name: example-workflow
annotations:
sonataflow.org/description: Example Workflow
sonataflow.org/version: 0.0.1
spec:
persistence:
postgresql:
serviceRef:
name: postgres-example
namespace: postgres-example-namespace
databaseName: example-database
databaseSchema: example-schema
port: 1234
secretRef:
name: postgres-secrets-example
userKey: POSTGRESQL_USER
passwordKey: POSTGRESQL_PASSWORD
flow:
- 1
- Name of the Kubernetes Service that connects to the PostgreSQL database server.
- 2
- Optional: Namespace containing the PostgreSQL Service. Defaults to the workflow namespace.
- 3
- Name of the PostgreSQL database where workflow data is stored.
- 4
- Optional: Name of the database schema for workflow data. Defaults to the workflow name.
- 5
- Optional: Port to connect to the PostgreSQL Service. Defaults to
5432. - 6
- Name of the Kubernetes Secret containing database credentials.
- 7
- Key in the
Secretobject containing the database username. - 8
- Key in the
Secretobject containing the database password.
This configuration informs the OpenShift Serverless Logic Operator that the workflow must connect to the specified PostgreSQL database server when deployed. The OpenShift Serverless Logic Operator adds the relevant JDBC connection parameters as environment variables to the workflow container.
PostgreSQL is currently the only supported database for persistence.
For SonataFlow CR deployments using the preview profile, the OpenShift Serverless Logic build system includes the required Quarkus extensions to enable persistence automatically.