@@ -37,6 +37,7 @@ use stackable_operator::{
3737 core:: { DeserializeGuard , error_boundary} ,
3838 runtime:: { controller:: Action , reflector:: ObjectRef } ,
3939 } ,
40+ kvp:: Label ,
4041 logging:: controller:: ReconcilerError ,
4142 product_config_utils:: ValidatedRoleConfigByPropertyKind ,
4243 product_logging:: {
@@ -610,27 +611,32 @@ fn pod_template(
610611 ) ;
611612 }
612613
614+ let mut omb = ObjectMetaBuilder :: new ( ) ;
615+ omb. name ( & container_name)
616+ // this reference is not pointing to a controller but only provides a UID that can used to clean up resources
617+ // cleanly (specifically driver pods and related config maps) when the spark application is deleted.
618+ . ownerreference_from_resource ( spark_application, None , None )
619+ . context ( ObjectMissingMetadataForOwnerRefSnafu ) ?
620+ . with_recommended_labels (
621+ spark_application
622+ . build_recommended_labels ( & spark_image. app_version_label , & container_name) ,
623+ )
624+ . context ( MetadataBuildSnafu ) ?;
625+
626+ // Only the driver pod should be scraped by Prometheus
627+ // because the executor metrics are also available via /metrics/executors/prometheus/
628+ if role == SparkApplicationRole :: Driver {
629+ omb. with_label ( Label :: try_from ( ( "prometheus.io/scrape" , "true" ) ) . context ( LabelBuildSnafu ) ?) ;
630+ }
631+
613632 let mut pb = PodBuilder :: new ( ) ;
614- pb. metadata (
615- ObjectMetaBuilder :: new ( )
616- . name ( & container_name)
617- // this reference is not pointing to a controller but only provides a UID that can used to clean up resources
618- // cleanly (specifically driver pods and related config maps) when the spark application is deleted.
619- . ownerreference_from_resource ( spark_application, None , None )
620- . context ( ObjectMissingMetadataForOwnerRefSnafu ) ?
621- . with_recommended_labels (
622- spark_application
623- . build_recommended_labels ( & spark_image. app_version_label , & container_name) ,
624- )
625- . context ( MetadataBuildSnafu ) ?
626- . build ( ) ,
627- )
628- . add_container ( cb. build ( ) )
629- . add_volumes ( volumes. to_vec ( ) )
630- . context ( AddVolumeSnafu ) ?
631- . security_context ( security_context ( ) )
632- . image_pull_secrets_from_product_image ( spark_image)
633- . affinity ( & config. affinity ) ;
633+ pb. metadata ( omb. build ( ) )
634+ . add_container ( cb. build ( ) )
635+ . add_volumes ( volumes. to_vec ( ) )
636+ . context ( AddVolumeSnafu ) ?
637+ . security_context ( security_context ( ) )
638+ . image_pull_secrets_from_product_image ( spark_image)
639+ . affinity ( & config. affinity ) ;
634640
635641 let init_containers = init_containers (
636642 spark_application,
0 commit comments