@@ -43,8 +43,8 @@ use stackable_operator::{
4343 api:: {
4444 apps:: v1:: { StatefulSet , StatefulSetSpec } ,
4545 core:: v1:: {
46- ConfigMap , ConfigMapVolumeSource , EmptyDirVolumeSource , Probe , Service ,
47- ServicePort , ServiceSpec , TCPSocketAction , Volume ,
46+ ConfigMap , ConfigMapVolumeSource , EmptyDirVolumeSource , Probe , TCPSocketAction ,
47+ Volume ,
4848 } ,
4949 } ,
5050 apimachinery:: pkg:: {
@@ -56,7 +56,7 @@ use stackable_operator::{
5656 core:: { DeserializeGuard , error_boundary} ,
5757 runtime:: controller:: Action ,
5858 } ,
59- kvp:: { Label , Labels , ObjectLabels } ,
59+ kvp:: { Labels , ObjectLabels } ,
6060 logging:: controller:: ReconcilerError ,
6161 memory:: { BinaryMultiple , MemoryQuantity } ,
6262 product_config_utils:: { transform_all_roles_to_config, validate_all_roles_and_groups_config} ,
@@ -94,14 +94,18 @@ use crate::{
9494 STACKABLE_LOG_DIR_NAME ,
9595 v1alpha1:: { self , HiveMetastoreRoleConfig } ,
9696 } ,
97- discovery:: { self , build_headless_role_group_metrics_service_name } ,
97+ discovery:: { self } ,
9898 kerberos:: {
9999 self , add_kerberos_pod_config, kerberos_config_properties,
100100 kerberos_container_start_commands,
101101 } ,
102102 listener:: { LISTENER_VOLUME_DIR , LISTENER_VOLUME_NAME , build_role_listener} ,
103103 operations:: { graceful_shutdown:: add_graceful_shutdown_config, pdb:: add_pdbs} ,
104104 product_logging:: extend_role_group_config_map,
105+ service:: {
106+ build_rolegroup_headless_service, build_rolegroup_metrics_service,
107+ rolegroup_headless_service_name,
108+ } ,
105109} ;
106110
107111pub const HIVE_CONTROLLER_NAME : & str = "hivecluster" ;
@@ -345,6 +349,9 @@ pub enum Error {
345349 BuildListenerVolume {
346350 source : ListenerOperatorVolumeSourceBuilderError ,
347351 } ,
352+
353+ #[ snafu( display( "faild to configure service" ) ) ]
354+ ServiceConfiguration { source : crate :: service:: Error } ,
348355}
349356type Result < T , E = Error > = std:: result:: Result < T , E > ;
350357
@@ -456,7 +463,14 @@ pub async fn reconcile_hive(
456463 . merged_config ( & HiveRole :: MetaStore , & rolegroup)
457464 . context ( FailedToResolveResourceConfigSnafu ) ?;
458465
459- let rg_service = build_rolegroup_service ( hive, & resolved_product_image, & rolegroup) ?;
466+ let rg_metrics_service =
467+ build_rolegroup_metrics_service ( hive, & resolved_product_image, & rolegroup)
468+ . context ( ServiceConfigurationSnafu ) ?;
469+
470+ let rg_headless_service =
471+ build_rolegroup_headless_service ( hive, & resolved_product_image, & rolegroup)
472+ . context ( ServiceConfigurationSnafu ) ?;
473+
460474 let rg_configmap = build_metastore_rolegroup_config_map (
461475 hive,
462476 & hive_namespace,
@@ -479,7 +493,14 @@ pub async fn reconcile_hive(
479493 ) ?;
480494
481495 cluster_resources
482- . add ( client, rg_service)
496+ . add ( client, rg_metrics_service)
497+ . await
498+ . context ( ApplyRoleGroupServiceSnafu {
499+ rolegroup : rolegroup. clone ( ) ,
500+ } ) ?;
501+
502+ cluster_resources
503+ . add ( client, rg_headless_service)
483504 . await
484505 . context ( ApplyRoleGroupServiceSnafu {
485506 rolegroup : rolegroup. clone ( ) ,
@@ -713,52 +734,10 @@ fn build_metastore_rolegroup_config_map(
713734 } )
714735}
715736
716- /// The rolegroup [`Service`] is a headless service that allows direct access to the instances of a certain rolegroup
717- ///
718- /// This is mostly useful for internal communication between peers, or for clients that perform client-side load balancing.
719- fn build_rolegroup_service (
720- hive : & v1alpha1:: HiveCluster ,
721- resolved_product_image : & ResolvedProductImage ,
722- rolegroup : & RoleGroupRef < v1alpha1:: HiveCluster > ,
723- ) -> Result < Service > {
724- Ok ( Service {
725- metadata : ObjectMetaBuilder :: new ( )
726- . name_and_namespace ( hive)
727- . name ( build_headless_role_group_metrics_service_name (
728- rolegroup. object_name ( ) ,
729- ) )
730- . ownerreference_from_resource ( hive, None , Some ( true ) )
731- . context ( ObjectMissingMetadataForOwnerRefSnafu ) ?
732- . with_recommended_labels ( build_recommended_labels (
733- hive,
734- & resolved_product_image. app_version_label ,
735- & rolegroup. role ,
736- & rolegroup. role_group ,
737- ) )
738- . context ( MetadataBuildSnafu ) ?
739- . with_label ( Label :: try_from ( ( "prometheus.io/scrape" , "true" ) ) . context ( LabelBuildSnafu ) ?)
740- . build ( ) ,
741- spec : Some ( ServiceSpec {
742- // Internal communication does not need to be exposed
743- type_ : Some ( "ClusterIP" . to_string ( ) ) ,
744- cluster_ip : Some ( "None" . to_string ( ) ) ,
745- ports : Some ( service_ports ( ) ) ,
746- selector : Some (
747- Labels :: role_group_selector ( hive, APP_NAME , & rolegroup. role , & rolegroup. role_group )
748- . context ( LabelBuildSnafu ) ?
749- . into ( ) ,
750- ) ,
751- publish_not_ready_addresses : Some ( true ) ,
752- ..ServiceSpec :: default ( )
753- } ) ,
754- status : None ,
755- } )
756- }
757-
758737/// The rolegroup [`StatefulSet`] runs the rolegroup, as configured by the administrator.
759738///
760739/// The [`Pod`](`stackable_operator::k8s_openapi::api::core::v1::Pod`)s are accessible through the
761- /// corresponding [`Service`] ( from [`build_rolegroup_service `]).
740+ /// corresponding [`Service`](`stackable_operator::k8s_openapi::api::core::v1::Service`) (via [`build_rolegroup_headless_service`] and metrics from [`build_rolegroup_metrics_service `]).
762741#[ allow( clippy:: too_many_arguments) ]
763742fn build_metastore_rolegroup_statefulset (
764743 hive : & v1alpha1:: HiveCluster ,
@@ -1100,9 +1079,8 @@ fn build_metastore_rolegroup_statefulset(
11001079 ) ,
11011080 ..LabelSelector :: default ( )
11021081 } ,
1103- service_name : Some ( build_headless_role_group_metrics_service_name (
1104- rolegroup_ref. object_name ( ) ,
1105- ) ) ,
1082+ // TODO: Use method on RoleGroupRef once op-rs is released
1083+ service_name : Some ( rolegroup_headless_service_name ( rolegroup_ref) ) ,
11061084 template : pod_template,
11071085 volume_claim_templates : Some ( vec ! [ pvc] ) ,
11081086 ..StatefulSetSpec :: default ( )
@@ -1123,15 +1101,6 @@ pub fn error_policy(
11231101 }
11241102}
11251103
1126- pub fn service_ports ( ) -> Vec < ServicePort > {
1127- vec ! [ ServicePort {
1128- name: Some ( METRICS_PORT_NAME . to_string( ) ) ,
1129- port: METRICS_PORT . into( ) ,
1130- protocol: Some ( "TCP" . to_string( ) ) ,
1131- ..ServicePort :: default ( )
1132- } ]
1133- }
1134-
11351104/// Creates recommended `ObjectLabels` to be used in deployed resources
11361105pub fn build_recommended_labels < ' a , T > (
11371106 owner : & ' a T ,
0 commit comments