@@ -49,7 +49,7 @@ use stackable_operator::{
4949 status:: condition:: { ClusterCondition , HasStatusCondition } ,
5050 time:: Duration ,
5151 utils:: {
52- cluster_domain :: KUBERNETES_CLUSTER_DOMAIN , crds:: raw_object_list_schema,
52+ cluster_info :: KubernetesClusterInfo , crds:: raw_object_list_schema,
5353 COMMON_BASH_TRAP_FUNCTIONS ,
5454 } ,
5555} ;
@@ -720,14 +720,16 @@ impl DruidCluster {
720720 }
721721
722722 /// The fully-qualified domain name of the role-level load-balanced Kubernetes `Service`
723- pub fn role_service_fqdn ( & self , role : & DruidRole ) -> Option < String > {
724- let cluster_domain = KUBERNETES_CLUSTER_DOMAIN
725- . get ( )
726- . expect ( "KUBERNETES_CLUSTER_DOMAIN must first be set by calling initialize_operator" ) ;
723+ pub fn role_service_fqdn (
724+ & self ,
725+ role : & DruidRole ,
726+ cluster_info : & KubernetesClusterInfo ,
727+ ) -> Option < String > {
727728 Some ( format ! (
728- "{}.{}.svc.{cluster_domain}" ,
729- self . role_service_name( role) ?,
730- self . metadata. namespace. as_ref( ) ?,
729+ "{service_name}.{namespace}.svc.{cluster_domain}" ,
730+ service_name = self . role_service_name( role) ?,
731+ namespace = self . metadata. namespace. as_ref( ) ?,
732+ cluster_domain = cluster_info. cluster_domain,
731733 ) )
732734 }
733735
@@ -1487,23 +1489,17 @@ pub fn build_recommended_labels<'a, T>(
14871489
14881490#[ cfg( test) ]
14891491mod tests {
1492+ use stackable_operator:: commons:: networking:: DomainName ;
1493+
14901494 use super :: * ;
14911495
14921496 #[ test]
14931497 fn test_service_name_generation ( ) {
14941498 let cluster =
14951499 deserialize_yaml_file :: < DruidCluster > ( "test/resources/role_service/druid_cluster.yaml" ) ;
1496-
1497- // As we are not calling stackable_operator::client::initialize_operator, we need to set the
1498- // Kubernetes cluster domain ourselves.
1499- KUBERNETES_CLUSTER_DOMAIN
1500- . set (
1501- "cluster.local"
1502- . to_owned ( )
1503- . try_into ( )
1504- . expect ( "must always be a valid domain" ) ,
1505- )
1506- . expect ( "failed to set Kubernetes cluster domain" ) ;
1500+ let dummy_cluster_info = KubernetesClusterInfo {
1501+ cluster_domain : DomainName :: try_from ( "cluster.local" ) . unwrap ( ) ,
1502+ } ;
15071503
15081504 assert_eq ! ( cluster. metadata. name, Some ( "testcluster" . to_string( ) ) ) ;
15091505
@@ -1513,7 +1509,7 @@ mod tests {
15131509 ) ;
15141510
15151511 assert_eq ! (
1516- cluster. role_service_fqdn( & DruidRole :: Router ) ,
1512+ cluster. role_service_fqdn( & DruidRole :: Router , & dummy_cluster_info ) ,
15171513 Some ( "testcluster-router.default.svc.cluster.local" . to_string( ) )
15181514 )
15191515 }
0 commit comments