@@ -12,7 +12,7 @@ use crate::{
1212 apimachinery:: pkg:: api:: resource:: Quantity ,
1313 } ,
1414 kube:: Resource ,
15- quantity:: { BinaryByteMultiple , MemoryQuantity , Suffix } ,
15+ quantity:: { BinaryMultiple , MemoryQuantity , Suffix } ,
1616 role_utils:: RoleGroupRef ,
1717} ;
1818
@@ -69,21 +69,15 @@ pub enum LoggingError {
6969/// pod::PodBuilder,
7070/// meta::ObjectMetaBuilder,
7171/// },
72- /// memory ::{
72+ /// quantity ::{
7373/// BinaryMultiple,
7474/// MemoryQuantity,
7575/// },
7676/// };
7777/// # use stackable_operator::product_logging;
7878///
79- /// const MAX_INIT_CONTAINER_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
80- /// value: 1.0,
81- /// unit: BinaryMultiple::Mebi,
82- /// };
83- /// const MAX_MAIN_CONTAINER_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity {
84- /// value: 10.0,
85- /// unit: BinaryMultiple::Mebi,
86- /// };
79+ /// const MAX_INIT_CONTAINER_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity::from_mebi(1.0);
80+ /// const MAX_MAIN_CONTAINER_LOG_FILES_SIZE: MemoryQuantity = MemoryQuantity::from_mebi(10.0);
8781///
8882/// PodBuilder::new()
8983/// .metadata(ObjectMetaBuilder::default().build())
@@ -101,9 +95,11 @@ pub enum LoggingError {
10195/// .unwrap();
10296/// ```
10397pub fn calculate_log_volume_size_limit ( max_log_files_size : & [ MemoryQuantity ] ) -> Quantity {
104- let mut log_volume_size_limit = max_log_files_size. iter ( ) . cloned ( ) . sum :: < MemoryQuantity > ( ) ;
105- log_volume_size_limit. scale_to ( Suffix :: BinaryByteMultiple ( BinaryByteMultiple :: Mebi ) ) ;
106- log_volume_size_limit
98+ let log_volume_size_limit = max_log_files_size
99+ . iter ( )
100+ . cloned ( )
101+ . sum :: < MemoryQuantity > ( )
102+ . scale_to ( Suffix :: BinaryMultiple ( BinaryMultiple :: Mebi ) )
107103 // According to the reasons mentioned in the function documentation, the multiplier must be
108104 // greater than 2. Manual tests with ZooKeeper 3.8 in an OpenShift cluster showed that 3 is
109105 // absolutely sufficient.
@@ -1527,10 +1523,10 @@ mod tests {
15271523 use super :: * ;
15281524 use crate :: product_logging:: spec:: { AppenderConfig , LoggerConfig } ;
15291525 use rstest:: rstest;
1530- use std:: collections:: BTreeMap ;
1526+ use std:: { collections:: BTreeMap , str :: FromStr } ;
15311527
15321528 #[ rstest]
1533- #[ case( "0Mi " , & [ ] ) ]
1529+ #[ case( "0 " , & [ ] ) ]
15341530 #[ case( "3Mi" , & [ "1Mi" ] ) ]
15351531 #[ case( "5Mi" , & [ "1.5Mi" ] ) ]
15361532 #[ case( "1Mi" , & [ "100Ki" ] ) ]
@@ -1541,7 +1537,7 @@ mod tests {
15411537 ) {
15421538 let input = max_log_files_sizes
15431539 . iter ( )
1544- . map ( |v| MemoryQuantity :: try_from ( Quantity ( v . to_string ( ) ) ) . unwrap ( ) )
1540+ . map ( |v| MemoryQuantity :: from_str ( v ) . unwrap ( ) )
15451541 . collect :: < Vec < _ > > ( ) ;
15461542 let calculated_log_volume_size_limit = calculate_log_volume_size_limit ( & input) ;
15471543 assert_eq ! (
0 commit comments