[ 
https://issues.apache.org/jira/browse/CAMEL-21924?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17951187#comment-17951187
 ] 

Claudio Miranda commented on CAMEL-21924:
-----------------------------------------

The maven project had a [yaml route which was creating the 
datasource|https://github.com/claudio4j/apache-camel-on-ocp-best-practices/commit/171864cc1feb161f032aae099c4f07e2570fb0b6#diff-9226b32b6619093daefb2d2ed12e2d44d216effa869b191e9f44ef5d47027a0e],
 that was interfering with the java route creating the datasource and giving 
the wrong impression the datasource created in the java route was working, so I 
removed the yaml route and discovered the Datasource cannot use the kubernetes 
property placeholder function, failing with
{code:java}
Caused by: [java.sql.SQLException - Cannot create JDBC driver of class 
'org.postgresql.Driver' for connect URL 
'jdbc:postgresql://{{secret:secret-basic-auth/host}}:{{secret:secret-basic-auth/port}}/testdb']:
 java.sql.SQLException: Cannot create JDBC driver of class 
'org.postgresql.Driver' for connect URL 
'jdbc:postgresql://{{secret:secret-basic-auth/host}}:{{secret:secret-basic-auth/port}}/testdb'
{code}
The Datasource method using the kubernetes property placeholder function:
{code:java}
@BindToRegistry
public DataSource datasource(){
    org.apache.commons.dbcp2.BasicDataSource ds = new 
org.apache.commons.dbcp2.BasicDataSource();
    log.info(">>> creating DBCP Datasource");
    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}}/testdb");
    ds.setDriverClassName("org.postgresql.Driver");
    return ds;
}
{code}
Hard coding the credentials works to set the datasource
{code:java}
@BindToRegistry
public DataSource datasource(){
    org.apache.commons.dbcp2.BasicDataSource ds = new 
org.apache.commons.dbcp2.BasicDataSource();
    log.info(">>> creating DBCP Datasource");
    ds.setUsername("user1");
    ds.setPassword("1admin123");
    ds.setUrl("jdbc:postgresql://postgresql-host:30765/testdb");
    ds.setDriverClassName("org.postgresql.Driver");
    return ds;
}
{code}
Then I changed to use quarkus only datasource and the quarkus-kubernetes-config 
(to retrieve the credentials from secret), but this way the kubernetes property 
placeholder function (from camel) is not used at all and the camel route is not 
reloaded.

Also, it seems the quarkus-kubernetes-config cannot hot reload the secrets in 
case the secret changes over time.

I will explore another way with camel to use the camel-kubernetes secret 
component to hot reload the credentials and hot reload the camel route.

 

 

> 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)

Reply via email to