@@ -12,7 +12,7 @@ use crate::{
12
12
apimachinery:: pkg:: api:: resource:: Quantity ,
13
13
} ,
14
14
kube:: Resource ,
15
- quantity:: { BinaryByteMultiple , MemoryQuantity , Suffix } ,
15
+ quantity:: { BinaryMultiple , MemoryQuantity , Suffix } ,
16
16
role_utils:: RoleGroupRef ,
17
17
} ;
18
18
@@ -69,21 +69,15 @@ pub enum LoggingError {
69
69
/// pod::PodBuilder,
70
70
/// meta::ObjectMetaBuilder,
71
71
/// },
72
- /// memory ::{
72
+ /// quantity ::{
73
73
/// BinaryMultiple,
74
74
/// MemoryQuantity,
75
75
/// },
76
76
/// };
77
77
/// # use stackable_operator::product_logging;
78
78
///
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);
87
81
///
88
82
/// PodBuilder::new()
89
83
/// .metadata(ObjectMetaBuilder::default().build())
@@ -101,9 +95,11 @@ pub enum LoggingError {
101
95
/// .unwrap();
102
96
/// ```
103
97
pub 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 ) )
107
103
// According to the reasons mentioned in the function documentation, the multiplier must be
108
104
// greater than 2. Manual tests with ZooKeeper 3.8 in an OpenShift cluster showed that 3 is
109
105
// absolutely sufficient.
@@ -1527,10 +1523,10 @@ mod tests {
1527
1523
use super :: * ;
1528
1524
use crate :: product_logging:: spec:: { AppenderConfig , LoggerConfig } ;
1529
1525
use rstest:: rstest;
1530
- use std:: collections:: BTreeMap ;
1526
+ use std:: { collections:: BTreeMap , str :: FromStr } ;
1531
1527
1532
1528
#[ rstest]
1533
- #[ case( "0Mi " , & [ ] ) ]
1529
+ #[ case( "0 " , & [ ] ) ]
1534
1530
#[ case( "3Mi" , & [ "1Mi" ] ) ]
1535
1531
#[ case( "5Mi" , & [ "1.5Mi" ] ) ]
1536
1532
#[ case( "1Mi" , & [ "100Ki" ] ) ]
@@ -1541,7 +1537,7 @@ mod tests {
1541
1537
) {
1542
1538
let input = max_log_files_sizes
1543
1539
. iter ( )
1544
- . map ( |v| MemoryQuantity :: try_from ( Quantity ( v . to_string ( ) ) ) . unwrap ( ) )
1540
+ . map ( |v| MemoryQuantity :: from_str ( v ) . unwrap ( ) )
1545
1541
. collect :: < Vec < _ > > ( ) ;
1546
1542
let calculated_log_volume_size_limit = calculate_log_volume_size_limit ( & input) ;
1547
1543
assert_eq ! (
0 commit comments