@@ -37,7 +37,7 @@ use stackable_operator::{
3737 DeepMerge ,
3838 api:: {
3939 apps:: v1:: { StatefulSet , StatefulSetSpec } ,
40- core:: v1:: { ConfigMap , EnvVar , HTTPGetAction , Probe , Service , ServiceSpec } ,
40+ core:: v1:: { ConfigMap , EnvVar , HTTPGetAction , Probe } ,
4141 } ,
4242 apimachinery:: pkg:: { apis:: meta:: v1:: LabelSelector , util:: intstr:: IntOrString } ,
4343 } ,
@@ -87,6 +87,7 @@ use crate::{
8787 listener:: { LISTENER_VOLUME_DIR , LISTENER_VOLUME_NAME , build_group_listener} ,
8888 operations:: { graceful_shutdown:: add_graceful_shutdown_config, pdb:: add_pdbs} ,
8989 product_logging:: { LOG_CONFIG_FILE , extend_config_map_with_log_config} ,
90+ service:: { build_node_rolegroup_headless_service, build_node_rolegroup_metrics_service} ,
9091 util:: { build_recommended_labels, rolegroup_metrics_service_name} ,
9192} ;
9293
@@ -299,6 +300,8 @@ pub enum Error {
299300 } ,
300301 #[ snafu( display( "failed to configure listener" ) ) ]
301302 ListenerConfiguration { source : crate :: listener:: Error } ,
303+ #[ snafu( display( "faild to configure service" ) ) ]
304+ ServiceConfiguration { source : crate :: service:: Error } ,
302305}
303306
304307type Result < T , E = Error > = std:: result:: Result < T , E > ;
@@ -430,16 +433,29 @@ pub async fn reconcile_superset(
430433 & rbac_sa. name_any ( ) ,
431434 & config,
432435 ) ?;
433- for rg_service in
434- build_node_rolegroup_services ( superset, & resolved_product_image, & rolegroup) ?
435- {
436- cluster_resources
437- . add ( client, rg_service)
438- . await
439- . with_context ( |_| ApplyRoleGroupServiceSnafu {
440- rolegroup : rolegroup. clone ( ) ,
441- } ) ?;
442- }
436+
437+ let rg_metrics_service =
438+ build_node_rolegroup_metrics_service ( superset, & resolved_product_image, & rolegroup)
439+ . context ( ServiceConfigurationSnafu ) ?;
440+
441+ let rg_headless_service =
442+ build_node_rolegroup_headless_service ( superset, & resolved_product_image, & rolegroup)
443+ . context ( ServiceConfigurationSnafu ) ?;
444+
445+ cluster_resources
446+ . add ( client, rg_metrics_service)
447+ . await
448+ . with_context ( |_| ApplyRoleGroupServiceSnafu {
449+ rolegroup : rolegroup. clone ( ) ,
450+ } ) ?;
451+
452+ cluster_resources
453+ . add ( client, rg_headless_service)
454+ . await
455+ . with_context ( |_| ApplyRoleGroupServiceSnafu {
456+ rolegroup : rolegroup. clone ( ) ,
457+ } ) ?;
458+
443459 cluster_resources
444460 . add ( client, rg_configmap)
445461 . await
@@ -619,96 +635,10 @@ fn build_rolegroup_config_map(
619635 } )
620636}
621637
622- /// The rolegroup [`Service`] is a headless service that allows direct access to the instances of a certain rolegroup
623- ///
624- /// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing.
625- fn build_node_rolegroup_services (
626- superset : & SupersetCluster ,
627- resolved_product_image : & ResolvedProductImage ,
628- rolegroup : & RoleGroupRef < SupersetCluster > ,
629- ) -> Result < Vec < Service > > {
630- let service = vec ! [
631- Service {
632- metadata: ObjectMetaBuilder :: new( )
633- . name_and_namespace( superset)
634- . name( superset. rolegroup_headless_metrics_service_name( rolegroup) )
635- . ownerreference_from_resource( superset, None , Some ( true ) )
636- . context( ObjectMissingMetadataForOwnerRefSnafu ) ?
637- . with_recommended_labels( build_recommended_labels(
638- superset,
639- SUPERSET_CONTROLLER_NAME ,
640- & resolved_product_image. app_version_label,
641- & rolegroup. role,
642- & rolegroup. role_group,
643- ) )
644- . context( MetadataBuildSnafu ) ?
645- . with_label(
646- Label :: try_from( ( "prometheus.io/scrape" , "true" ) ) . context( LabelBuildSnafu ) ?,
647- )
648- . build( ) ,
649- spec: Some ( ServiceSpec {
650- // Internal communication does not need to be exposed
651- type_: Some ( "ClusterIP" . to_owned( ) ) ,
652- cluster_ip: Some ( "None" . to_owned( ) ) ,
653- ports: Some ( superset. metrics_ports( ) ) ,
654- selector: Some (
655- Labels :: role_group_selector(
656- superset,
657- APP_NAME ,
658- & rolegroup. role,
659- & rolegroup. role_group,
660- )
661- . context( LabelBuildSnafu ) ?
662- . into( ) ,
663- ) ,
664- publish_not_ready_addresses: Some ( true ) ,
665- ..ServiceSpec :: default ( )
666- } ) ,
667- status: None ,
668- } ,
669- Service {
670- metadata: ObjectMetaBuilder :: new( )
671- . name_and_namespace( superset)
672- . name( superset. rolegroup_headless_service_name( rolegroup) )
673- . ownerreference_from_resource( superset, None , Some ( true ) )
674- . context( ObjectMissingMetadataForOwnerRefSnafu ) ?
675- . with_recommended_labels( build_recommended_labels(
676- superset,
677- SUPERSET_CONTROLLER_NAME ,
678- & resolved_product_image. app_version_label,
679- & rolegroup. role,
680- & rolegroup. role_group,
681- ) )
682- . context( MetadataBuildSnafu ) ?
683- . build( ) ,
684- spec: Some ( ServiceSpec {
685- // Internal communication does not need to be exposed
686- type_: Some ( "ClusterIP" . to_owned( ) ) ,
687- cluster_ip: Some ( "None" . to_owned( ) ) ,
688- ports: Some ( superset. service_ports( ) ) ,
689- selector: Some (
690- Labels :: role_group_selector(
691- superset,
692- APP_NAME ,
693- & rolegroup. role,
694- & rolegroup. role_group,
695- )
696- . context( LabelBuildSnafu ) ?
697- . into( ) ,
698- ) ,
699- publish_not_ready_addresses: Some ( true ) ,
700- ..ServiceSpec :: default ( )
701- } ) ,
702- status: None ,
703- } ,
704- ] ;
705-
706- Ok ( service)
707- }
708-
709638/// The rolegroup [`StatefulSet`] runs the rolegroup, as configured by the administrator.
710639///
711- /// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the corresponding [`Service`] (from [`build_node_rolegroup_services`]).
640+ /// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the corresponding
641+ /// [`Service`](`stackable_operator::k8s_openapi::api::core::v1::Service`) (from [`build_node_rolegroup_headless_service`] and [`build_node_rolegroup_metrics_service`]).
712642#[ allow( clippy:: too_many_arguments) ]
713643fn build_server_rolegroup_statefulset (
714644 superset : & SupersetCluster ,
0 commit comments