@@ -23,6 +23,11 @@ use crate::{
2323const SPOOLING_S3_AWS_ACCESS_KEY : & str = "SPOOLING_S3_AWS_ACCESS_KEY" ;
2424const SPOOLING_S3_AWS_SECRET_KEY : & str = "SPOOLING_S3_AWS_SECRET_KEY" ;
2525
26+ #[ derive( Clone , Debug , Deserialize , JsonSchema , PartialEq , Serialize ) ]
27+ #[ serde( rename_all = "camelCase" ) ]
28+ pub enum ClientProtocolConfig {
29+ Spooling ( ClientSpoolingProtocolConfig ) ,
30+ }
2631#[ derive( Clone , Debug , Deserialize , JsonSchema , PartialEq , Serialize ) ]
2732#[ serde( rename_all = "camelCase" ) ]
2833pub struct ClientSpoolingProtocolConfig {
@@ -70,7 +75,7 @@ pub struct S3SpoolingConfig {
7075 pub upload_part_size : Option < Quantity > ,
7176}
7277
73- pub struct ResolvedSpoolingProtocolConfig {
78+ pub struct ResolvedClientProtocolConfig {
7479 /// Properties to add to config.properties
7580 pub config_properties : BTreeMap < String , String > ,
7681
@@ -92,11 +97,11 @@ pub struct ResolvedSpoolingProtocolConfig {
9297 pub init_container_extra_start_commands : Vec < String > ,
9398}
9499
95- impl ResolvedSpoolingProtocolConfig {
100+ impl ResolvedClientProtocolConfig {
96101 /// Resolve S3 connection properties from Kubernetes resources
97102 /// and prepare spooling filesystem configuration.
98103 pub async fn from_config (
99- config : & ClientSpoolingProtocolConfig ,
104+ config : & ClientProtocolConfig ,
100105 client : Option < & Client > ,
101106 namespace : & str ,
102107 ) -> Result < Self , Error > {
@@ -109,39 +114,43 @@ impl ResolvedSpoolingProtocolConfig {
109114 init_container_extra_start_commands : Vec :: new ( ) ,
110115 } ;
111116
112- // Resolve external resources if Kubernetes client is available
113- // This should always be the case, except for when this function is called during unit tests
114- if let Some ( client) = client {
115- match & config. filesystem {
116- SpoolingFileSystemConfig :: S3 ( s3_config) => {
117- resolved_config
118- . resolve_s3_backend ( s3_config, client, namespace)
119- . await ?;
117+ match config {
118+ ClientProtocolConfig :: Spooling ( spooling_config) => {
119+ // Resolve external resources if Kubernetes client is available
120+ // This should always be the case, except for when this function is called during unit tests
121+ if let Some ( client) = client {
122+ match & spooling_config. filesystem {
123+ SpoolingFileSystemConfig :: S3 ( s3_config) => {
124+ resolved_config
125+ . resolve_s3_backend ( s3_config, client, namespace)
126+ . await ?;
127+ }
128+ }
120129 }
121- }
122- }
123130
124- resolved_config. spooling_manager_properties . extend ( [
125- ( "fs.location" . to_string ( ) , config . location . clone ( ) ) ,
126- (
127- "spooling-manager.name" . to_string ( ) ,
128- "filesystem" . to_string ( ) ,
129- ) ,
130- ] ) ;
131-
132- // Enable spooling protocol
133- resolved_config. config_properties . extend ( [
134- ( "protocol.spooling.enabled" . to_string ( ) , "true" . to_string ( ) ) ,
135- (
136- "protocol.spooling.shared-secret-key" . to_string ( ) ,
137- format ! ( "${{ENV:{secret}}}" , secret = ENV_SPOOLING_SECRET ) ,
138- ) ,
139- ] ) ;
131+ resolved_config. spooling_manager_properties . extend ( [
132+ ( "fs.location" . to_string ( ) , spooling_config . location . clone ( ) ) ,
133+ (
134+ "spooling-manager.name" . to_string ( ) ,
135+ "filesystem" . to_string ( ) ,
136+ ) ,
137+ ] ) ;
138+
139+ // Enable spooling protocol
140+ resolved_config. config_properties . extend ( [
141+ ( "protocol.spooling.enabled" . to_string ( ) , "true" . to_string ( ) ) ,
142+ (
143+ "protocol.spooling.shared-secret-key" . to_string ( ) ,
144+ format ! ( "${{ENV:{secret}}}" , secret = ENV_SPOOLING_SECRET ) ,
145+ ) ,
146+ ] ) ;
140147
141- // Finally, extend the spooling manager properties with any user configuration
142- resolved_config
143- . spooling_manager_properties
144- . extend ( config. config_overrides . clone ( ) ) ;
148+ // Finally, extend the spooling manager properties with any user configuration
149+ resolved_config
150+ . spooling_manager_properties
151+ . extend ( spooling_config. config_overrides . clone ( ) ) ;
152+ }
153+ }
145154
146155 Ok ( resolved_config)
147156 }
@@ -252,7 +261,7 @@ mod tests {
252261
253262 #[ tokio:: test]
254263 async fn test_spooling_config ( ) {
255- let config = ClientSpoolingProtocolConfig {
264+ let config = ClientProtocolConfig :: Spooling ( ClientSpoolingProtocolConfig {
256265 location : "s3://my-bucket/spooling" . to_string ( ) ,
257266 filesystem : SpoolingFileSystemConfig :: S3 ( S3SpoolingConfig {
258267 connection :
@@ -265,9 +274,9 @@ mod tests {
265274 upload_part_size : None ,
266275 } ) ,
267276 config_overrides : HashMap :: new ( ) ,
268- } ;
277+ } ) ;
269278
270- let resolved_spooling_config = ResolvedSpoolingProtocolConfig :: from_config (
279+ let resolved_spooling_config = ResolvedClientProtocolConfig :: from_config (
271280 & config, None , // No client, so no external resolution
272281 "default" ,
273282 )
@@ -292,7 +301,7 @@ mod tests {
292301
293302 #[ tokio:: test]
294303 async fn test_spooling_config_overrides ( ) {
295- let config = ClientSpoolingProtocolConfig {
304+ let config = ClientProtocolConfig :: Spooling ( ClientSpoolingProtocolConfig {
296305 location : "s3://my-bucket/spooling" . to_string ( ) ,
297306 filesystem : SpoolingFileSystemConfig :: S3 ( S3SpoolingConfig {
298307 connection :
@@ -308,9 +317,9 @@ mod tests {
308317 "protocol.spooling.retrieval-mode" . to_string ( ) ,
309318 "STORAGE" . to_string ( ) ,
310319 ) ] ) ,
311- } ;
320+ } ) ;
312321
313- let resolved_spooling_config = ResolvedSpoolingProtocolConfig :: from_config (
322+ let resolved_spooling_config = ResolvedClientProtocolConfig :: from_config (
314323 & config, None , // No client, so no external resolution
315324 "default" ,
316325 )
0 commit comments