Repository: quarkusio/quarkus
Issue: PostgreSQL service binding does not get recognised by Quarkus app

### 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
```

Changed files:
extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java

diff --git a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java
index 26f6f31dd35..c1285724923 100644
--- a/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java
+++ b/extensions/kubernetes-service-binding/runtime/src/main/java/io/quarkus/kubernetes/service/binding/runtime/DatasourceServiceBindingConfigSourceFactory.java
@@ -8,18 +8,19 @@
 
 public abstract class DatasourceServiceBindingConfigSourceFactory
         implements Function<ServiceBinding, ServiceBindingConfigSource> {
-
     private static final Logger log = Logger.getLogger(DatasourceServiceBindingConfigSourceFactory.class);
 
     private final String configSourceNamePrefix;
     private final String urlPropertyName;
+    private final String prefix;
     private final String urlFormat;
     protected ServiceBinding serviceBinding;
 
     private DatasourceServiceBindingConfigSourceFactory(String configSourceNamePrefix, String urlPropertyName,
-            String urlFormat) {
+            String prefix, String urlFormat) {
         this.configSourceNamePrefix = configSourceNamePrefix;
         this.urlPropertyName = urlPropertyName;
+        this.prefix = prefix;
         this.urlFormat = urlFormat;
     }
 
@@ -47,14 +48,13 @@ private Map<String, String> getServiceBindingProperties() {
             log.debugf("Property 'password' was not found for datasource of type %s", serviceBinding.getType());
         }
 
-        String jdbcURL = bindingProperties.get("jdbc-url");
-        if (jdbcURL != null) {
-            properties.put(urlPropertyName, jdbcURL);
+        if (configureUrlPropertyUsingKey(properties, "jdbc-url")) {
+            return properties;
+        }
+        if (configureUrlPropertyUsingKey(properties, "jdbc-uri")) {
             return properties;
         }
-        String uri = bindingProperties.get("uri");
-        if (uri != null) {
-            properties.put(urlPropertyName, uri);
+        if (configureUrlPropertyUsingKey(properties, "uri")) {
             return properties;
         }
 
@@ -79,23 +79,37 @@ protected String formatUrl(String urlFormat, String type, String host, String da
         return String.format(urlFormat, type, host, portPart, database);
     }
 
+    private boolean configureUrlPropertyUsingKey(Map<String, String> properties, String key) {
+        String value = serviceBinding.getProperties().get(key);
+        if (value == null) {
+            return false;
+        } else if (value.startsWith(prefix)) {
+            properties.put(urlPropertyName, value);
+            return true;
+        }
+
+        log.warnf("The value '%s' from the property '%s' does not start with '%s'. It will be ignored.",
+                value, key, prefix);
+        return false;
+    }
+
     public static class Jdbc extends DatasourceServiceBindingConfigSourceFactory {
         public Jdbc() {
-            super("jdbc", "quarkus.datasource.jdbc.url", "jdbc:%s://%s%s/%s");
+            this("jdbc:%s://%s%s/%s");
         }
 
         public Jdbc(String urlFormat) {
-            super("jdbc", "quarkus.datasource.jdbc.url", urlFormat);
+            super("jdbc", "quarkus.datasource.jdbc.url", "jdbc:", urlFormat);
         }
     }
 
     public static class Reactive extends DatasourceServiceBindingConfigSourceFactory {
         public Reactive() {
-            super("reactive", "quarkus.datasource.reactive.url", "%s://%s%s/%s");
+            this("%s://%s%s/%s");
         }
 
         public Reactive(String urlFormat) {
-            super("reactive", "quarkus.datasource.reactive.url", urlFormat);
+            super("reactive", "quarkus.datasource.reactive.url", "", urlFormat);
         }
     }
 }