[
https://issues.apache.org/jira/browse/CAMEL-21924?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17950844#comment-17950844
]
Claus Ibsen commented on CAMEL-21924:
-------------------------------------
The datasource should be created with the values injected such as
{code:java}
@jakarta.inject.Inject
public javax.sql.DataSource datasource(
@PropertyInject("{{secret:secret-basic-auth/username}}") String
username,
@PropertyInject("{{secret:secret-basic-auth/password}}") String
password,
@PropertyInject("{{secret:secret-basic-auth/host}}") String host,
@PropertyInject("{{secret:secret-basic-auth/port:5432}}") int port) {
System.out.println("Creating datasource3");
org.apache.commons.dbcp2.BasicDataSource ds = new
org.apache.commons.dbcp2.BasicDataSource();
ds.setUsername(username);
ds.setPassword(password);
ds.setUrl("jdbc:postgresql://" + host + ":" + port + "/testdb");
ds.setDriverClassName("org.postgresql.Driver");
return ds;
} {code}
The @PropertyInject is from Camel but when you use CEQ then you use their
annotation: org.eclipse.microprofile.config.inject.ConfigProperty
> context reload fails to reload the kubernetes property placeholder functions
> ----------------------------------------------------------------------------
>
> Key: CAMEL-21924
> URL: https://issues.apache.org/jira/browse/CAMEL-21924
> Project: Camel
> Issue Type: Bug
> Components: camel-kubernetes
> Reporter: Claudio Miranda
> Priority: Major
>
> When use the kubernetes property placeholder function
> "{{{{secret:secret-basic-auth/username}}}}" in a "DataSource" object to set
> the authentication credentials, then update the kubernetes secret, the camel
> context is reloaded but the datasource object is not updated with the new
> values from the secret.
> An example route:
> {code}
> public class JdbcLog extends RouteBuilder {
> @Inject
> DataSource datasource() {
> org.apache.commons.dbcp2.BasicDataSource ds = new
> org.apache.commons.dbcp2.BasicDataSource();
> ds.setUsername("{{secret:secret-basic-auth/username}}");
> ds.setPassword("{{secret:secret-basic-auth/password}}");
>
> ds.setUrl("jdbc:postgresql://{{secret:secret-basic-auth/host}}:{{secret:secret-basic-auth/port:5432}}/testdb");
> ds.setDriverClassName("org.postgresql.Driver");
> return ds;
> }
> @Override
> public void configure() throws Exception {
> from("timer:JAVA?period=30s")
> .setBody(simple("SELECT * FROM foo"))
> .to("jdbc:datasource")
> .process(e ->
> e.getContext().getRegistry().findByType(DataSource.class).forEach(b -> {
> org.apache.commons.dbcp2.BasicDataSource ds =
> (BasicDataSource) b;
> log.info(">> datasource user: " + ds.getUserName());
> }))
> .log("db username: {{secret:secret-basic-auth/username}} - body:
> ${body}");
> }
> }
> {code}
> The log shows the secret is reloaded and triggers a camel context reload
> {code}
> [org.apa.cam.com.kub.sec.vau.SecretsReloadTriggerTask] Matching secret id:
> secret-basic-auth=secret-basic-auth -> true
> [org.apa.cam.com.kub.sec.vau.SecretsReloadTriggerTask] Update for Kubernetes
> Secret: secret-basic-auth detected, triggering CamelContext reload
> [org.apa.cam.sup.DefaultContextReloadStrategy] Reloading CamelContext
> (camel-2) triggered by:
> org.apache.camel.component.kubernetes.secrets.vault.SecretsReloadTriggerTask$1@7e53b383
> {code}
> But the datasource object still uses the previous value:
> {code}
> [sam.JdbcLog] (Camel thread #9 - timer://JAVA) >> datasource user: user1
> {code}
> The [full reproducer and detailed
> explanation|https://github.com/claudio4j/apache-camel-on-ocp-best-practices/tree/add_hotreload_ceq/examples/ocp/hot-reload/camel-quarkus].
--
This message was sent by Atlassian Jira
(v8.20.10#820010)