-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
K8S service binding support for Reactive SQL Clients
This commit introduces support for K8S service binding when using Reactive SQL Clients.
- Loading branch information
1 parent
cf92045
commit 0d08b98
Showing
35 changed files
with
623 additions
and
5 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
...bernetes/service/binding/runtime/ReactiveDatasourceServiceBindingConfigSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.kubernetes.service.binding.runtime; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Function; | ||
|
||
import org.jboss.logging.Logger; | ||
|
||
public class ReactiveDatasourceServiceBindingConfigSourceFactory | ||
implements Function<ServiceBinding, ServiceBindingConfigSource> { | ||
|
||
private static final Logger log = Logger.getLogger(ReactiveDatasourceServiceBindingConfigSourceFactory.class); | ||
|
||
private final String type; | ||
|
||
public ReactiveDatasourceServiceBindingConfigSourceFactory(String type) { | ||
this.type = type; | ||
} | ||
|
||
@Override | ||
public ServiceBindingConfigSource apply(ServiceBinding serviceBinding) { | ||
return new ServiceBindingConfigSource("reactive-" + type + "-k8s-service-binding-source", | ||
getServiceBindingProperties(serviceBinding)); | ||
} | ||
|
||
private Map<String, String> getServiceBindingProperties(ServiceBinding binding) { | ||
Map<String, String> properties = new HashMap<>(); | ||
Map<String, String> bindingProperties = binding.getProperties(); | ||
|
||
String username = bindingProperties.get("username"); | ||
if (username != null) { | ||
properties.put("quarkus.datasource.username", username); | ||
} else { | ||
log.debugf("Property 'username' was not found for datasource of type %s", type); | ||
} | ||
String password = bindingProperties.get("password"); | ||
if (password != null) { | ||
properties.put("quarkus.datasource.password", password); | ||
} else { | ||
log.debugf("Property 'password' was not found for datasource of type %s", type); | ||
} | ||
|
||
String host = bindingProperties.get("host"); | ||
String port = bindingProperties.get("port"); | ||
String database = bindingProperties.get("database"); | ||
if ((host != null) && (database != null)) { | ||
String portPart = ""; | ||
if (port != null) { | ||
portPart = ":" + port; | ||
} | ||
properties.put(urlPropertyName(), formatUrl(host, database, portPart)); | ||
} else { | ||
log.debugf("One or more of 'host' or 'database' properties were not found for datasource of type %s", type); | ||
} | ||
|
||
return properties; | ||
} | ||
|
||
protected String urlPropertyName() { | ||
return "quarkus.datasource.reactive.url"; | ||
} | ||
|
||
protected String formatUrl(String host, String database, String portPart) { | ||
return String.format("%s://%s%s/%s", type, host, portPart, database); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...time/src/main/java/io/quarkus/reactive/db2/client/runtime/DB2ServiceBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.reactive.db2.client.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ReactiveDatasourceServiceBindingConfigSourceFactory; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class DB2ServiceBindingConverter implements ServiceBindingConverter { | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
return ServiceBinding.singleMatchingByType("db2", serviceBindings) | ||
.map(new ReactiveDatasourceServiceBindingConfigSourceFactory("db2")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
.../resources/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.reactive.db2.client.runtime.DB2ServiceBindingConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../src/main/java/io/quarkus/reactive/mssql/client/runtime/MsSQLServiceBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.reactive.mssql.client.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ReactiveDatasourceServiceBindingConfigSourceFactory; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class MsSQLServiceBindingConverter implements ServiceBindingConverter { | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
return ServiceBinding.singleMatchingByType("sqlserver", serviceBindings) | ||
.map(new ReactiveDatasourceServiceBindingConfigSourceFactory("sqlserver")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.reactive.mssql.client.runtime.MsSQLServiceBindingConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
.../src/main/java/io/quarkus/reactive/mysql/client/runtime/MySQLServiceBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.reactive.mysql.client.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ReactiveDatasourceServiceBindingConfigSourceFactory; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class MySQLServiceBindingConverter implements ServiceBindingConverter { | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
return ServiceBinding.singleMatchingByType("mysql", serviceBindings) | ||
.map(new ReactiveDatasourceServiceBindingConfigSourceFactory("mysql")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.reactive.mysql.client.runtime.MySQLServiceBindingConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...rc/main/java/io/quarkus/reactive/oracle/client/runtime/OracleServiceBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.reactive.oracle.client.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ReactiveDatasourceServiceBindingConfigSourceFactory; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class OracleServiceBindingConverter implements ServiceBindingConverter { | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
return ServiceBinding.singleMatchingByType("oracle", serviceBindings) | ||
.map(new ReactiveDatasourceServiceBindingConfigSourceFactory("oracle")); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.reactive.oracle.client.runtime.OracleServiceBindingConverter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...rc/main/java/io/quarkus/reactive/pg/client/runtime/PostgreSQLServiceBindingConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.quarkus.reactive.pg.client.runtime; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.kubernetes.service.binding.runtime.ReactiveDatasourceServiceBindingConfigSourceFactory; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBinding; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConfigSource; | ||
import io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter; | ||
|
||
public class PostgreSQLServiceBindingConverter implements ServiceBindingConverter { | ||
|
||
@Override | ||
public Optional<ServiceBindingConfigSource> convert(List<ServiceBinding> serviceBindings) { | ||
return ServiceBinding.singleMatchingByType("postgresql", serviceBindings) | ||
.map(new ReactiveDatasourceServiceBindingConfigSourceFactory("postgresql")); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...s/META-INF/services/io.quarkus.kubernetes.service.binding.runtime.ServiceBindingConverter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.quarkus.reactive.pg.client.runtime.PostgreSQLServiceBindingConverter |
Oops, something went wrong.