@@ -274,6 +274,63 @@ def get_context_list_from_args(
274274 ]
275275
276276
277+ class ConfigValuesUpdater (ABC ):
278+ """Abstract class for updating configuration values for different service instances."""
279+
280+ def get_updated_config (self , orig_config_yaml : str , instance_index : int ) -> str :
281+ """Get updated configuration YAML for a specific instance.
282+
283+ Args:
284+ orig_config_yaml: Original configuration as YAML string
285+ instance_index: Index of the instance to update configuration for
286+
287+ Returns:
288+ Updated configuration as YAML string
289+ """
290+ config , config_data = parse_config_from_yaml (orig_config_yaml )
291+ updated_config_data = self .get_updated_config_for_instance (config_data , instance_index )
292+ return serialize_config_to_yaml (config , updated_config_data )
293+
294+ @abstractmethod
295+ def get_updated_config_for_instance (
296+ self , config_data : dict [str , any ], instance_index : int
297+ ) -> dict [str , any ]:
298+ """Get updated configuration data for a specific instance.
299+
300+ Args:
301+ config_data: Current configuration data dictionary
302+ instance_index: Index of the instance to update configuration for
303+
304+ Returns:
305+ Updated configuration data dictionary
306+ """
307+ pass
308+
309+
310+ class ConstConfigValuesUpdater (ConfigValuesUpdater ):
311+ """Concrete implementation that applies constant configuration overrides."""
312+
313+ def __init__ (self , config_overrides : dict [str , any ]):
314+ """Initialize with configuration overrides.
315+
316+ Args:
317+ config_overrides: Dictionary of configuration keys and values to override
318+ """
319+ self .config_overrides = config_overrides
320+
321+ def get_updated_config_for_instance (
322+ self , config_data : dict [str , any ], instance_index : int
323+ ) -> dict [str , any ]:
324+ """Apply the same configuration overrides to the config data for each instance."""
325+ updated_config = config_data .copy ()
326+
327+ for key , value in self .config_overrides .items ():
328+ print_colored (f" Overriding config: { key } = { value } " )
329+ updated_config [key ] = value
330+
331+ return updated_config
332+
333+
277334class ServiceRestarter (ABC ):
278335 """Abstract class for restarting service instances."""
279336
@@ -541,22 +598,6 @@ def represent_literal_str(dumper, data):
541598 return result
542599
543600
544- def update_config_values (
545- config_content : str ,
546- config_overrides : dict [str , Any ] = None ,
547- ) -> str :
548- """Update configuration values in the YAML content and return the updated YAML"""
549- # Parse the configuration
550- config , config_data = parse_config_from_yaml (config_content )
551-
552- for key , value in config_overrides .items ():
553- print_colored (f" Overriding config: { key } = { value } " )
554- config_data [key ] = value
555-
556- # Serialize back to YAML
557- return serialize_config_to_yaml (config , config_data )
558-
559-
560601def normalize_config (config_content : str ) -> str :
561602 """Normalize configuration by parsing and re-serializing without changes.
562603
@@ -633,12 +674,12 @@ def apply_configmap(
633674
634675
635676def update_config_and_restart_nodes (
636- config_overrides : dict [ str , Any ] ,
677+ config_values_updater : ConfigValuesUpdater ,
637678 namespace_and_instruction_args : NamespaceAndInstructionArgs ,
638679 service : Service ,
639680 restarter : ServiceRestarter ,
640681) -> None :
641- assert config_overrides is not None , "config_overrides must be provided"
682+ assert config_values_updater is not None , "config_values_updater must be provided"
642683 assert namespace_and_instruction_args .namespace_list is not None , "namespaces must be provided"
643684
644685 if not namespace_and_instruction_args .cluster_list :
@@ -669,7 +710,7 @@ def update_config_and_restart_nodes(
669710 )
670711
671712 # Update config
672- updated_config = update_config_values (original_config , config_overrides )
713+ updated_config = config_values_updater . get_updated_config (original_config , index )
673714
674715 # Store configs
675716 configs .append ({"original" : original_config , "updated" : updated_config })
0 commit comments