11//! Discovery for Druid. We make Druid discoverable by putting a connection string to the router service
22//! inside a config map. We only provide a connection string to the router service, since it serves as
33//! a gateway to the cluster for client queries.
4- use snafu:: { OptionExt , ResultExt , Snafu } ;
4+ use snafu:: { ResultExt , Snafu } ;
55use stackable_operator:: {
66 builder:: { configmap:: ConfigMapBuilder , meta:: ObjectMetaBuilder } ,
77 commons:: product_image_selection:: ResolvedProductImage ,
8+ crd:: listener:: v1alpha1:: Listener ,
89 k8s_openapi:: api:: core:: v1:: ConfigMap ,
910 kube:: { Resource , ResourceExt , runtime:: reflector:: ObjectRef } ,
10- utils:: cluster_info:: KubernetesClusterInfo ,
1111} ;
1212
1313use crate :: {
1414 DRUID_CONTROLLER_NAME ,
1515 crd:: { DruidRole , build_recommended_labels, security:: DruidTlsSecurity , v1alpha1} ,
16+ listener:: build_listener_connection_string,
1617} ;
1718
1819#[ derive( Snafu , Debug ) ]
@@ -35,47 +36,45 @@ pub enum Error {
3536 AddRecommendedLabels {
3637 source : stackable_operator:: builder:: meta:: Error ,
3738 } ,
39+
40+ #[ snafu( display( "failed to configure listener discovery configmap" ) ) ]
41+ ListenerConfiguration { source : crate :: listener:: Error } ,
3842}
3943
4044/// Builds discovery [`ConfigMap`]s for connecting to a [`v1alpha1::DruidCluster`].
4145pub async fn build_discovery_configmaps (
4246 druid : & v1alpha1:: DruidCluster ,
4347 owner : & impl Resource < DynamicType = ( ) > ,
44- cluster_info : & KubernetesClusterInfo ,
4548 resolved_product_image : & ResolvedProductImage ,
4649 druid_tls_security : & DruidTlsSecurity ,
50+ listener : Listener ,
4751) -> Result < Vec < ConfigMap > , Error > {
4852 let name = owner. name_unchecked ( ) ;
4953 Ok ( vec ! [ build_discovery_configmap(
5054 druid,
5155 owner,
52- cluster_info,
5356 resolved_product_image,
5457 druid_tls_security,
5558 & name,
59+ listener,
5660 ) ?] )
5761}
5862
5963/// Build a discovery [`ConfigMap`] containing information about how to connect to a certain [`v1alpha1::DruidCluster`].
6064fn build_discovery_configmap (
6165 druid : & v1alpha1:: DruidCluster ,
6266 owner : & impl Resource < DynamicType = ( ) > ,
63- cluster_info : & KubernetesClusterInfo ,
6467 resolved_product_image : & ResolvedProductImage ,
6568 druid_tls_security : & DruidTlsSecurity ,
6669 name : & str ,
70+ listener : Listener ,
6771) -> Result < ConfigMap , Error > {
68- let router_host = format ! (
69- "{}:{}" ,
70- druid
71- . role_service_fqdn( & DruidRole :: Router , cluster_info)
72- . with_context( || NoServiceFqdnSnafu ) ?,
73- if druid_tls_security. tls_enabled( ) {
74- DruidRole :: Router . get_https_port( )
75- } else {
76- DruidRole :: Router . get_http_port( )
77- }
78- ) ;
72+ let router_host = build_listener_connection_string (
73+ listener,
74+ druid_tls_security,
75+ & DruidRole :: Router . to_string ( ) ,
76+ )
77+ . context ( ListenerConfigurationSnafu ) ?;
7978 let sqlalchemy_conn_str = format ! ( "druid://{}/druid/v2/sql" , router_host) ;
8079 let avatica_conn_str = format ! (
8180 "jdbc:avatica:remote:url=http://{}/druid/v2/sql/avatica/" ,
0 commit comments