11//! Builds the per-rolegroup [`StatefulSet`] that runs a Trino role group.
22
3- use std:: { collections:: BTreeMap , convert:: Infallible } ;
3+ use std:: { collections:: BTreeMap , convert:: Infallible , str :: FromStr } ;
44
55use snafu:: { OptionExt , ResultExt , Snafu } ;
66use stackable_operator:: {
@@ -31,16 +31,13 @@ use stackable_operator::{
3131 apimachinery:: pkg:: { apis:: meta:: v1:: LabelSelector , util:: intstr:: IntOrString } ,
3232 } ,
3333 kvp:: { Annotation , Annotations , Labels } ,
34- product_logging:: {
35- self ,
36- framework:: LoggingError ,
37- spec:: {
38- ConfigMapLogConfig , ContainerLogConfig , ContainerLogConfigChoice ,
39- CustomContainerLogConfig ,
40- } ,
41- } ,
34+ product_logging,
4235 shared:: time:: Duration ,
43- v2:: builder:: pod:: container:: EnvVarSet ,
36+ v2:: {
37+ builder:: pod:: container:: EnvVarSet ,
38+ product_logging:: framework:: { ValidatedContainerLogConfigChoice , vector_container} ,
39+ types:: kubernetes:: { ContainerName , VolumeName } ,
40+ } ,
4441} ;
4542
4643use crate :: {
@@ -59,16 +56,23 @@ use crate::{
5956 crd:: {
6057 APP_NAME , CONFIG_DIR_NAME , Container , ENV_INTERNAL_SECRET , ENV_SPOOLING_SECRET , HTTP_PORT ,
6158 HTTP_PORT_NAME , HTTPS_PORT , HTTPS_PORT_NAME , MAX_TRINO_LOG_FILES_SIZE , METRICS_PORT ,
62- METRICS_PORT_NAME , RW_CONFIG_DIR_NAME , STACKABLE_CLIENT_TLS_DIR , STACKABLE_INTERNAL_TLS_DIR ,
63- STACKABLE_MOUNT_INTERNAL_TLS_DIR , STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR ,
64- STACKABLE_TLS_STORE_PASSWORD , TrinoRole , v1alpha1,
59+ METRICS_PORT_NAME , RW_CONFIG_DIR_NAME , STACKABLE_CLIENT_TLS_DIR ,
60+ STACKABLE_INTERNAL_TLS_DIR , STACKABLE_MOUNT_INTERNAL_TLS_DIR ,
61+ STACKABLE_MOUNT_SERVER_TLS_DIR , STACKABLE_SERVER_TLS_DIR , STACKABLE_TLS_STORE_PASSWORD ,
62+ TrinoRole , v1alpha1,
6563 } ,
6664 trino_controller:: {
6765 MAX_PREPARE_LOG_FILE_SIZE , STACKABLE_LOG_CONFIG_DIR , STACKABLE_LOG_DIR ,
6866 build_recommended_labels, shared_internal_secret_name, shared_spooling_secret_name,
6967 } ,
7068} ;
7169
70+ stackable_operator:: constant!( VECTOR_CONTAINER_NAME : ContainerName = "vector" ) ;
71+ // The Vector agent reads its `vector.yaml` from the rolegroup ConfigMap (mounted as the "config"
72+ // volume) and writes its state under the shared "log" volume.
73+ stackable_operator:: constant!( VECTOR_LOG_CONFIG_VOLUME_NAME : VolumeName = "config" ) ;
74+ stackable_operator:: constant!( VECTOR_LOG_VOLUME_NAME : VolumeName = "log" ) ;
75+
7276#[ derive( Snafu , Debug ) ]
7377pub enum Error {
7478 #[ snafu( display( "missing secret lifetime" ) ) ]
@@ -88,12 +92,6 @@ pub enum Error {
8892 container_name : String ,
8993 } ,
9094
91- #[ snafu( display( "vector agent is enabled but vector aggregator ConfigMap is missing" ) ) ]
92- VectorAggregatorConfigMapMissing ,
93-
94- #[ snafu( display( "failed to build vector container" ) ) ]
95- BuildVectorContainer { source : LoggingError } ,
96-
9795 #[ snafu( display( "failed to configure graceful shutdown" ) ) ]
9896 GracefulShutdown {
9997 source : build:: graceful_shutdown:: Error ,
@@ -263,9 +261,8 @@ pub fn build_rolegroup_statefulset(
263261 ) ?;
264262
265263 let mut prepare_args = vec ! [ ] ;
266- if let Some ( ContainerLogConfig {
267- choice : Some ( ContainerLogConfigChoice :: Automatic ( log_config) ) ,
268- } ) = merged_config. logging . containers . get ( & Container :: Prepare )
264+ if let ValidatedContainerLogConfigChoice :: Automatic ( log_config) =
265+ & merged_config. logging . prepare_container
269266 {
270267 prepare_args. push ( product_logging:: framework:: capture_shell_output (
271268 STACKABLE_LOG_DIR ,
@@ -380,60 +377,33 @@ pub fn build_rolegroup_statefulset(
380377 // add password-update container if required
381378 trino_authentication_config. add_authentication_containers ( trino_role, & mut pod_builder) ;
382379
383- if let Some ( ContainerLogConfig {
384- choice :
385- Some ( ContainerLogConfigChoice :: Custom ( CustomContainerLogConfig {
386- custom : ConfigMapLogConfig { config_map } ,
387- } ) ) ,
388- } ) = merged_config. logging . containers . get ( & Container :: Trino )
389- {
390- pod_builder
391- . add_volume ( Volume {
392- name : "log-config" . to_string ( ) ,
393- config_map : Some ( ConfigMapVolumeSource {
394- name : config_map. into ( ) ,
395- ..ConfigMapVolumeSource :: default ( )
396- } ) ,
397- ..Volume :: default ( )
398- } )
399- . context ( AddVolumeSnafu ) ?;
400- } else {
401- pod_builder
402- . add_volume ( Volume {
403- name : "log-config" . to_string ( ) ,
404- config_map : Some ( ConfigMapVolumeSource {
405- name : config_map_name. clone ( ) ,
406- ..ConfigMapVolumeSource :: default ( )
407- } ) ,
408- ..Volume :: default ( )
409- } )
410- . context ( AddVolumeSnafu ) ?;
411- }
380+ // The log-config volume mounts either the rolegroup ConfigMap (which carries the automatic
381+ // `log.properties`) or a user-provided custom ConfigMap, depending on the validated choice.
382+ let log_config_volume_config_map = match & merged_config. logging . trino_container {
383+ ValidatedContainerLogConfigChoice :: Custom ( config_map) => config_map. to_string ( ) ,
384+ ValidatedContainerLogConfigChoice :: Automatic ( _) => config_map_name. clone ( ) ,
385+ } ;
386+ pod_builder
387+ . add_volume ( Volume {
388+ name : "log-config" . to_string ( ) ,
389+ config_map : Some ( ConfigMapVolumeSource {
390+ name : log_config_volume_config_map,
391+ ..ConfigMapVolumeSource :: default ( )
392+ } ) ,
393+ ..Volume :: default ( )
394+ } )
395+ . context ( AddVolumeSnafu ) ?;
412396
413- if merged_config. logging . enable_vector_agent {
414- match & trino. spec . cluster_config . vector_aggregator_config_map_name {
415- Some ( vector_aggregator_config_map_name) => {
416- pod_builder. add_container (
417- product_logging:: framework:: vector_container (
418- resolved_product_image,
419- "config" ,
420- "log" ,
421- merged_config. logging . containers . get ( & Container :: Vector ) ,
422- ResourceRequirementsBuilder :: new ( )
423- . with_cpu_request ( "250m" )
424- . with_cpu_limit ( "500m" )
425- . with_memory_request ( "128Mi" )
426- . with_memory_limit ( "128Mi" )
427- . build ( ) ,
428- vector_aggregator_config_map_name,
429- )
430- . context ( BuildVectorContainerSnafu ) ?,
431- ) ;
432- }
433- None => {
434- VectorAggregatorConfigMapMissingSnafu . fail ( ) ?;
435- }
436- }
397+ if let Some ( vector_log_config) = & merged_config. logging . vector_container {
398+ pod_builder. add_container ( vector_container (
399+ & VECTOR_CONTAINER_NAME ,
400+ resolved_product_image,
401+ vector_log_config,
402+ & resource_names,
403+ & VECTOR_LOG_CONFIG_VOLUME_NAME ,
404+ & VECTOR_LOG_VOLUME_NAME ,
405+ EnvVarSet :: new ( ) ,
406+ ) ) ;
437407 }
438408
439409 let metadata = ObjectMetaBuilder :: new ( )
0 commit comments