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

PostgreSQL service binding does not get recognised by Quarkus app #30682

Closed
mjurc opened this issue Jan 28, 2023 · 9 comments · Fixed by #30955
Closed

PostgreSQL service binding does not get recognised by Quarkus app #30682

mjurc opened this issue Jan 28, 2023 · 9 comments · Fixed by #30955
Labels
area/kubernetes kind/bug Something isn't working
Milestone

Comments

@mjurc
Copy link

mjurc commented Jan 28, 2023

Describe the bug

Since Quarkus 2.15, Quarkus application is unable to bind to PostgreSQL service provided by CrunchyDB.

PostgresCluster used:

apiVersion: postgres-operator.crunchydata.com/v1beta1
kind: PostgresCluster
metadata:
  name: hippo
spec:
  openshift: true
  image: registry.developers.crunchydata.com/crunchydata/crunchy-postgres:ubi8-14.2-1
  postgresVersion: 14
  instances:
    - name: instance1
      dataVolumeClaimSpec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: 150Mi
  backups:
    pgbackrest:
      image: registry.developers.crunchydata.com/crunchydata/crunchy-pgbackrest:ubi8-2.38-0
      repos:
        - name: repo1
          volume:
            volumeClaimSpec:
              accessModes:
                - "ReadWriteOnce"
              resources:
                requests:
                  storage: 150Mi

application.properties:

quarkus.kubernetes-service-binding.services.postgresql.api-version=postgres-operator.crunchydata.com/v1beta1
quarkus.kubernetes-service-binding.services.postgresql.kind=PostgresCluster
quarkus.kubernetes-service-binding.services.postgresql.name=hippo

quarkus.datasource.db-kind=postgresql
quarkus.hibernate-orm.database.generation=drop-and-create
quarkus.hibernate-orm.sql-load-script=import.sql

quarkus.openshift.route.expose=true
quarkus.kubernetes.deployment-target=openshift

These settings have worked since Quarkus 2.2.

Expected behavior

Service is bound to Quarkus application and the application launches

Actual behavior

Quarkus fails the service binding, application misses datasource configuration and thus fails to start with

Model classes are defined for the default persistence unit <default> but configured datasource <default> not found: the default EntityManagerFactory will not be created. To solve this, configure the default datasource. Refer to https://quarkus.io/guides/datasource for guidance.

How to Reproduce?

Reproducer is available at https://github.com/quarkus-qe/quarkus-test-suite

  1. Login to OpenShift with SBO and CrunchyDB operator
  2. check out https://github.com/quarkus-qe/quarkus-test-suite
  3. cd service-binding/postrgres-crunchy-classic
  4. Run the test to create the PostgresCluster, deploy the application and run crud operations on it: mvn clean verify -Dopenshift

To run with Quarkus that worked with this SB, you can run mvn clean verify -Dopenshift -Dquarkus.platform.version=2.14.3.Final

To manually deploy the PostgresCluster and the application, run the following:

oc apply -f ./src/test/resources/pg-cluster.yml
# wait for PostgresCluster
oc -n ${YOUR_NAMESPACE} wait --for condition=Ready --timeout=300s pods --all
# build + deploy app in OCP
mvn clean install -Dquarkus.kubernetes-client.trust-certs=true -Dquarkus.kubernetes.deploy=true

Output of uname -a or ver

Linux tigris 6.1.7-200.fc37.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jan 18 17:11:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "17.0.5" 2022-10-18

GraalVM version (if different from Java)

No response

Quarkus version or git rev

since 2.15.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.5 (Red Hat 3.8.5-3)

Additional information

This also fails for reactive Hibernate - for the reproducer, see https://github.com/quarkus-qe/quarkus-test-suite/tree/main/service-binding/postgresql-crunchy-reactive.

The application manages to boot there, but it fails when it tries to access the datasource with bogus URL:

18:29:46,010 INFO  [app] 17:29:40,998 HR000057: Failed to execute statement [select todo0_.id as id1_0_0_, todo0_.completed as complete2_0_0_, todo0_.title as title3_0_0_ from Todo todo0_ where todo0_.id=$1]: could not load an entity: [io.quarkus.ts.sb.reactive.Todo#1]: java.util.concurrent.CompletionException: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:5432
@mjurc mjurc added the kind/bug Something isn't working label Jan 28, 2023
@quarkus-bot
Copy link

quarkus-bot bot commented Jan 28, 2023

/cc @Sgitario (kubernetes), @geoand (kubernetes,openshift), @iocanel (kubernetes,openshift)

mjurc added a commit to mjurc/quarkus-test-suite that referenced this issue Jan 28, 2023
* Disabling the service binding tests caused by
  quarkusio/quarkus#30682
@Sgitario
Copy link
Contributor

Sgitario commented Feb 7, 2023

I'm having a look into this issue

@Sgitario
Copy link
Contributor

Sgitario commented Feb 7, 2023

@mjurc the traces you shared seem to be caused because the Service Binding Operator is not installed. If you install it, then you will reach to the actual issue:

 --/ __ \/ / / / _ | / _ \/ //_/ / / / __/ 
 -/ /_/ / /_/ / __ |/ , _/ ,< / /_/ /\ \   
--\___\_\____/_/ |_/_/|_/_/|_|\____/___/   
2023-02-07 12:39:55,703 WARN  [io.agr.pool] (main) Datasource '<default>': Driver does not support the provided URL: postgresql://hippo:f1%3Cm5liNIB%3CbwpWQMi+.zjA%[email protected]:5432/hippo
2023-02-07 12:39:55,953 WARN  [io.agr.pool] (agroal-11) Datasource '<default>': Driver does not support the provided URL: postgresql://hippo:f1%3Cm5liNIB%3CbwpWQMi+.zjA%[email protected]:5432/hippo
2023-02-07 12:39:55,954 WARN  [org.hib.eng.jdb.env.int.JdbcEnvironmentInitiator] (JPA Startup Thread) HHH000342: Could not obtain connection to query metadata: java.sql.SQLException: Driver does not support the provided URL: postgresql://hippo:f1%3Cm5liNIB%3CbwpWQMi+.zjA%[email protected]:5432/hippo

And this issue is caused by the changes in #29702 because the crunchy operator does not provide the jdbc-url property, but the uri property. So, after the changes in the mentioned pull request, the uri property is used, but this property does not have the JDBC prefix and hence it's not working.

I will address this issue by:

  • reading the jdbc-uri property which the crunchy operator is providing
  • plus, in case the uri property does not follow the expected format, we do not use it.
    wdyt? @geoand

@geoand
Copy link
Contributor

geoand commented Feb 7, 2023

👍🏼

Let's also add proper warning messages in cases we encounter unexpected values

Sgitario added a commit to Sgitario/quarkus that referenced this issue Feb 7, 2023
Plus, log a warning when the uri property does not have the expected format
Fix quarkusio#30682
Sgitario added a commit to Sgitario/quarkus that referenced this issue Feb 7, 2023
Plus, log a warning when the uri property does not have the expected format
Fix quarkusio#30682
Sgitario added a commit to Sgitario/quarkus that referenced this issue Feb 7, 2023
Plus, log a warning when the uri property does not have the expected format
Fix quarkusio#30682
Sgitario added a commit to Sgitario/quarkus that referenced this issue Feb 7, 2023
Plus, log a warning when the uri property does not have the expected format
Fix quarkusio#30682
@quarkus-bot quarkus-bot bot added this to the 3.0 - main milestone Feb 8, 2023
@mjurc
Copy link
Author

mjurc commented Apr 19, 2023

@geoand @Sgitario We've got back to this issue now. The fix didn't work, and this is certainly not an issue of cluster setup - it works on 2.13.5.Final and early 2.14 versions too.

New issue: #32773

@geoand
Copy link
Contributor

geoand commented Apr 19, 2023

Okay. @Sgitario can you have a look or do you want me to?

@Sgitario
Copy link
Contributor

Okay. @Sgitario can you have a look or do you want me to?

I'm having a look.

@geoand
Copy link
Contributor

geoand commented Apr 20, 2023

🙏🏼

@EE1234EE
Copy link

EE1234EE commented Aug 23, 2023

Hey folks,

any updates to this issue? I followed the quickstart guide crunchy operator. Quarkus Version 3.3.0 and still mentioned error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/kubernetes kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants