@@ -176,85 +176,64 @@ impl NodeConfig {
176176 /// Creates the main OpenSearch configuration file in YAML format
177177 pub fn opensearch_config_file_content ( & self ) -> String {
178178 serde_yaml:: to_string ( & self . opensearch_config ( ) )
179- . expect ( "serde_json::Value should always be serializable" )
179+ . expect ( "serde_json::Value should always be serializable as a string of YAML " )
180180 }
181181
182182 pub fn opensearch_config ( & self ) -> serde_json:: Value {
183183 let mut config = self . static_opensearch_config ( ) ;
184184
185185 config. merge_from ( self . tls_config ( ) ) ;
186186
187- let json_config_overrides : JsonConfigOverrides = self
187+ let overrides : JsonConfigOverrides = self
188188 . role_group_config
189189 . config_overrides
190190 . opensearch_yml
191- . clone ( )
192- . into ( ) ;
191+ . clone ( ) ;
193192
194- json_config_overrides . apply ( & config) . into_owned ( )
193+ overrides . apply ( & config) . into_owned ( )
195194 }
196195
197196 /// Creates the main OpenSearch configuration file as JSON map
198197 ///
199198 /// The file should only contain cluster-wide configuration options. Node-specific options
200199 /// should be defined as environment variables.
201200 pub fn static_opensearch_config ( & self ) -> serde_json:: Value {
202- let mut config = serde_json:: Map :: new ( ) ;
203-
204- config. insert (
205- CONFIG_OPTION_CLUSTER_NAME . to_owned ( ) ,
206- json ! ( self . cluster. name. to_string( ) ) ,
207- ) ;
208- config. insert (
209- CONFIG_OPTION_NETWORK_HOST . to_owned ( ) ,
201+ let mut config = json ! ( {
202+ CONFIG_OPTION_CLUSTER_NAME : self . cluster. name,
210203 // Bind to all interfaces because the IP address is not known in advance.
211- json ! ( "0.0.0.0" . to_owned( ) ) ,
212- ) ;
213- config. insert (
214- CONFIG_OPTION_DISCOVERY_TYPE . to_owned ( ) ,
215- json ! ( self . discovery_type( ) ) ,
216- ) ;
217- config. insert
218- // Accept certificates generated by the secret-operator
219- (
220- CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN . to_owned ( ) ,
221- json ! ( [ "CN=generated certificate for pod" . to_owned( ) ] ) ,
222- ) ;
223- config. insert (
224- CONFIG_OPTION_NODE_ATTR_ROLE_GROUP . to_owned ( ) ,
225- json ! ( self . role_group_name) ,
226- ) ;
227- config. insert (
228- CONFIG_OPTION_PATH_LOGS . to_owned ( ) ,
229- json ! ( format!(
204+ CONFIG_OPTION_NETWORK_HOST : "0.0.0.0" ,
205+ CONFIG_OPTION_DISCOVERY_TYPE : self . discovery_type( ) ,
206+ // Accept certificates generated by the secret-operator
207+ CONFIG_OPTION_PLUGINS_SECURITY_NODES_DN : [
208+ "CN=generated certificate for pod"
209+ ] ,
210+ CONFIG_OPTION_NODE_ATTR_ROLE_GROUP : self . role_group_name,
211+ CONFIG_OPTION_PATH_LOGS : format!(
230212 "{STACKABLE_LOG_DIR}/{container}" ,
231213 container = v1alpha1:: Container :: OpenSearch . to_container_name( )
232- ) ) ,
233- ) ;
214+ ) ,
215+ } ) ;
234216
235- match self . role_group_security_mode {
217+ config . merge_from ( match self . role_group_security_mode {
236218 RoleGroupSecurityMode :: Initializing { .. } => {
237- config. insert (
238- CONFIG_OPTION_PLUGINS_SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX . to_owned ( ) ,
239- json ! ( true ) ,
240- ) ;
219+ json ! ( {
220+ CONFIG_OPTION_PLUGINS_SECURITY_ALLOW_DEFAULT_INIT_SECURITYINDEX : true
221+ } )
241222 }
242223 RoleGroupSecurityMode :: Managing { .. }
243224 | RoleGroupSecurityMode :: Participating { .. } => {
244- config. insert (
245- CONFIG_OPTION_PLUGINS_SECURITY_AUTHCZ_ADMIN_DN . to_owned ( ) ,
246- json ! ( self . super_admin_dn( ) ) ,
247- ) ;
225+ json ! ( {
226+ CONFIG_OPTION_PLUGINS_SECURITY_AUTHCZ_ADMIN_DN : self . super_admin_dn( )
227+ } )
248228 }
249229 RoleGroupSecurityMode :: Disabled => {
250- config. insert (
251- CONFIG_OPTION_PLUGINS_SECURITY_DISABLED . to_owned ( ) ,
252- json ! ( true ) ,
253- ) ;
230+ json ! ( {
231+ CONFIG_OPTION_PLUGINS_SECURITY_DISABLED : true
232+ } )
254233 }
255- } ;
234+ } ) ;
256235
257- json ! ( config)
236+ config
258237 }
259238
260239 /// Distinguished name (DN) of the super admin certificate
@@ -264,7 +243,7 @@ impl NodeConfig {
264243 }
265244
266245 pub fn tls_config ( & self ) -> serde_json:: Value {
267- let mut config = serde_json :: Map :: new ( ) ;
246+ let mut config = json ! ( { } ) ;
268247
269248 let opensearch_path_conf = self . opensearch_path_conf ( ) ;
270249
@@ -273,53 +252,32 @@ impl NodeConfig {
273252 . tls_internal_secret_class ( )
274253 . is_some ( )
275254 {
276- config. insert (
277- CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_ENABLED . to_owned ( ) ,
278- json ! ( true ) ,
279- ) ;
280- config. insert (
281- CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMCERT_FILEPATH . to_owned ( ) ,
282- json ! ( format!( "{opensearch_path_conf}/tls/internal/tls.crt" ) ) ,
283- ) ;
284- config. insert (
285- CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMKEY_FILEPATH . to_owned ( ) ,
286- json ! ( format!( "{opensearch_path_conf}/tls/internal/tls.key" ) ) ,
287- ) ;
288- config. insert (
289- CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMTRUSTEDCAS_FILEPATH . to_owned ( ) ,
290- json ! ( format!( "{opensearch_path_conf}/tls/internal/ca.crt" ) ) ,
291- ) ;
255+ config. merge_from ( json ! ( {
256+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_ENABLED : true ,
257+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMCERT_FILEPATH : format!( "{opensearch_path_conf}/tls/internal/tls.crt" ) ,
258+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMKEY_FILEPATH : format!( "{opensearch_path_conf}/tls/internal/tls.key" ) ,
259+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_TRANSPORT_PEMTRUSTEDCAS_FILEPATH : format!( "{opensearch_path_conf}/tls/internal/ca.crt" ) ,
260+ } ) ) ;
292261 }
293262
294263 if self
295264 . role_group_security_mode
296265 . tls_server_secret_class ( )
297266 . is_some ( )
298267 {
299- config. insert (
300- CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED . to_owned ( ) ,
301- json ! ( true ) ,
302- ) ;
303- config. insert (
304- CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMCERT_FILEPATH . to_owned ( ) ,
305- json ! ( format!( "{opensearch_path_conf}/tls/server/tls.crt" ) ) ,
306- ) ;
307- config. insert (
308- CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMKEY_FILEPATH . to_owned ( ) ,
309- json ! ( format!( "{opensearch_path_conf}/tls/server/tls.key" ) ) ,
310- ) ;
311- config. insert (
312- CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMTRUSTEDCAS_FILEPATH . to_owned ( ) ,
313- json ! ( format!( "{opensearch_path_conf}/tls/server/ca.crt" ) ) ,
314- ) ;
268+ config. merge_from ( json ! ( {
269+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED : true ,
270+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMCERT_FILEPATH : format!( "{opensearch_path_conf}/tls/server/tls.crt" ) ,
271+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMKEY_FILEPATH : format!( "{opensearch_path_conf}/tls/server/tls.key" ) ,
272+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_PEMTRUSTEDCAS_FILEPATH : format!( "{opensearch_path_conf}/tls/server/ca.crt" ) ,
273+ } ) ) ;
315274 } else {
316- config. insert (
317- CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED . to_owned ( ) ,
318- json ! ( false ) ,
319- ) ;
275+ config. merge_from ( json ! ( {
276+ CONFIG_OPTION_PLUGINS_SECURITY_SSL_HTTP_ENABLED : false
277+ } ) ) ;
320278 }
321279
322- json ! ( config)
280+ config
323281 }
324282
325283 /// Creates environment variables for the OpenSearch configurations
@@ -542,10 +500,12 @@ mod tests {
542500
543501 use super :: * ;
544502 use crate :: {
545- controller:: { ValidatedLogging , ValidatedOpenSearchConfig , ValidatedSecurity } ,
503+ controller:: {
504+ ValidatedLogging , ValidatedOpenSearchConfig , ValidatedOpenSearchConfigOverrides ,
505+ ValidatedSecurity ,
506+ } ,
546507 crd:: v1alpha1,
547508 framework:: {
548- config_overrides:: KeyValueConfigOverrides ,
549509 product_logging:: framework:: ValidatedContainerLogConfigChoice ,
550510 role_utils:: GenericCommonConfig ,
551511 types:: {
@@ -559,15 +519,15 @@ mod tests {
559519
560520 struct TestConfig {
561521 replicas : u16 ,
562- config_settings : & ' static [ ( & ' static str , & ' static str ) ] ,
522+ config_settings : serde_json :: Value ,
563523 env_vars : & ' static [ ( & ' static str , & ' static str ) ] ,
564524 }
565525
566526 impl Default for TestConfig {
567527 fn default ( ) -> Self {
568528 Self {
569529 replicas : 3 ,
570- config_settings : & [ ] ,
530+ config_settings : json ! ( { } ) ,
571531 env_vars : & [ ] ,
572532 }
573533 }
@@ -603,16 +563,8 @@ mod tests {
603563 resources : Resources :: default ( ) ,
604564 termination_grace_period_seconds : 30 ,
605565 } ,
606- config_overrides : v1alpha1:: OpenSearchConfigOverrides {
607- opensearch_yml : v1alpha1:: ConfigOverridesChoice :: KeyValue (
608- KeyValueConfigOverrides {
609- overrides : test_config
610- . config_settings
611- . iter ( )
612- . map ( |( k, v) | ( k. to_string ( ) , Some ( v. to_string ( ) ) ) )
613- . collect ( ) ,
614- } ,
615- ) ,
566+ config_overrides : ValidatedOpenSearchConfigOverrides {
567+ opensearch_yml : JsonConfigOverrides :: JsonMergePatch ( test_config. config_settings ) ,
616568 } ,
617569 env_overrides : EnvVarSet :: new ( ) . with_values (
618570 test_config
@@ -693,7 +645,7 @@ mod tests {
693645 #[ test]
694646 pub fn test_static_opensearch_config_file ( ) {
695647 let node_config = node_config ( TestConfig {
696- config_settings : & [ ( "test" , "value" ) ] ,
648+ config_settings : json ! ( { "test" : "value" } ) ,
697649 ..TestConfig :: default ( )
698650 } ) ;
699651
0 commit comments