@@ -211,35 +211,6 @@ def validate_arguments(args: argparse.Namespace) -> None:
211211 sys .exit (1 )
212212
213213
214- def get_namespace_list_from_args (
215- args : argparse .Namespace ,
216- ) -> list [str ]:
217- """Get a list of namespaces based on the arguments"""
218- if args .namespace_list :
219- return args .namespace_list
220-
221- return [
222- f"{ args .namespace_prefix } -{ i } "
223- for i in range (args .start_index , args .start_index + args .num_nodes )
224- ]
225-
226-
227- def get_context_list_from_args (
228- args : argparse .Namespace ,
229- ) -> list [str ]:
230- """Get a list of contexts based on the arguments"""
231- if args .cluster_list :
232- return args .cluster_list
233-
234- if args .cluster_prefix is None :
235- return None
236-
237- return [
238- f"{ args .cluster_prefix } -{ i } "
239- for i in range (args .start_index , args .start_index + args .num_nodes )
240- ]
241-
242-
243214def get_logs_explorer_url (
244215 query : str ,
245216 project_name : Optional [str ] = None ,
@@ -510,45 +481,106 @@ def restart_pod(
510481 sys .exit (1 )
511482
512483
484+ class NamespaceAndInstructionArgs :
485+ def __init__ (
486+ self ,
487+ namespace_list : list [str ],
488+ cluster_list : Optional [list [str ]],
489+ instruction_list : Optional [list [str ]] = None ,
490+ ):
491+ assert (
492+ namespace_list is not None and len (namespace_list ) > 0
493+ ), "Namespace list cannot be None or empty."
494+ self .namespace_list = namespace_list
495+ assert cluster_list is None or len (cluster_list ) == len (
496+ namespace_list
497+ ), "cluster_list must have the same length as namespace_list"
498+ self .cluster_list = cluster_list
499+ assert instruction_list is None or len (namespace_list ) == len (
500+ instruction_list
501+ ), "instruction_list must have the same length as namespace_list"
502+ self .instruction_list = instruction_list
503+
504+ def size (self ) -> int :
505+ return len (self .namespace_list )
506+
507+ def get_namespace (self , index : int ) -> str :
508+ return self .namespace_list [index ]
509+
510+ def get_cluster (self , index : int ) -> Optional [str ]:
511+ return self .cluster_list [index ] if self .cluster_list else None
512+
513+ def get_instruction (self , index : int ) -> Optional [str ]:
514+ return self .instruction_list [index ] if self .instruction_list else None
515+
516+ @staticmethod
517+ def get_namespace_list_from_args (
518+ args : argparse .Namespace ,
519+ ) -> list [str ]:
520+ """Get a list of namespaces based on the arguments"""
521+ if args .namespace_list :
522+ return args .namespace_list
523+
524+ return [
525+ f"{ args .namespace_prefix } -{ i } "
526+ for i in range (args .start_index , args .start_index + args .num_nodes )
527+ ]
528+
529+ @staticmethod
530+ def get_context_list_from_args (
531+ args : argparse .Namespace ,
532+ ) -> list [str ]:
533+ """Get a list of contexts based on the arguments"""
534+ if args .cluster_list :
535+ return args .cluster_list
536+
537+ if args .cluster_prefix is None :
538+ return None
539+
540+ return [
541+ f"{ args .cluster_prefix } -{ i } "
542+ for i in range (args .start_index , args .start_index + args .num_nodes )
543+ ]
544+
545+
513546def update_config_and_restart_nodes (
514547 config_overrides : dict [str , Any ],
515- namespace_list : list [ str ] ,
548+ namespace_and_instruction_args : NamespaceAndInstructionArgs ,
516549 service : Service ,
517- cluster_list : Optional [list [str ]],
518550 restart_strategy : RestartStrategy ,
519- # TODO(guy.f): Add more abstraction to restart strategy so that the instructions are abstracted as part of it.
520- post_restart_instructions : Optional [list [str ]] = None ,
521551) -> None :
522552 assert config_overrides is not None , "config_overrides must be provided"
523- assert namespace_list is not None and len (namespace_list ) > 0 , "namespaces must be provided"
524-
525- if post_restart_instructions is not None :
526- assert len (post_restart_instructions ) == len (
527- namespace_list
528- ), f"post_restart_instructions must have the same length as namespace_list. logs_explorer_urls: { len (post_restart_instructions )} , namespace_list: { len (namespace_list )} "
553+ assert (
554+ namespace_and_instruction_args .namespace_list is not None
555+ and len (namespace_and_instruction_args .namespace_list ) > 0
556+ ), "namespaces must be provided"
529557
530- if not cluster_list :
558+ if not namespace_and_instruction_args . cluster_list :
531559 print_colored (
532560 "cluster-prefix/cluster-list not provided. Assuming all nodes are on the current cluster" ,
533561 Colors .RED ,
534562 )
535- else :
536- assert len (cluster_list ) == len (
537- namespace_list
538- ), f"cluster_list must have the same number of values as namespace_list. cluster_list: { cluster_list } , namespace_list: { namespace_list } "
539563
540564 # Store original and updated configs for all nodes
541565 configs = []
542566
543567 # Process each node's configuration
544- for index , namespace in enumerate (namespace_list ):
545- cluster = cluster_list [index ] if cluster_list else None
568+ for index in range (namespace_and_instruction_args .size ()):
569+ namespace = namespace_and_instruction_args .get_namespace (index )
570+ cluster = namespace_and_instruction_args .get_cluster (index )
571+
546572 print_colored (
547573 f"\n Processing node for namespace { namespace } (cluster: { cluster if cluster else 'current cluster' } )..."
548574 )
549575
550576 # Get current config and normalize it (e.g. " vs ') to ensure not showing bogus diffs.
551- original_config = normalize_config (get_configmap (namespace , cluster , service ))
577+ original_config = normalize_config (
578+ get_configmap (
579+ namespace ,
580+ cluster ,
581+ service ,
582+ )
583+ )
552584
553585 # Update config
554586 updated_config = update_config_values (original_config , config_overrides )
@@ -567,19 +599,22 @@ def update_config_and_restart_nodes(
567599 print_colored ("\n Applying configurations..." )
568600 for index , config in enumerate (configs ):
569601 print (f"Applying config { index } ..." )
570- apply_configmap (
571- config ["updated" ],
572- namespace_list [ index ] ,
573- index ,
574- cluster_list [ index ] if cluster_list else None ,
575- )
602+ # apply_configmap(
603+ # config["updated"],
604+ # namespace_and_instruction_args.get_namespace( index) ,
605+ # index,
606+ # namespace_and_instruction_args.get_cluster(index) ,
607+ # )
576608
577609 if restart_strategy != RestartStrategy .NO_RESTART :
578610 for index , config in enumerate (configs ):
579- restart_pod (
580- namespace_list [index ], service , index , cluster_list [index ] if cluster_list else None
581- )
582- instructions = post_restart_instructions [index ] if post_restart_instructions else None
611+ # restart_pod(
612+ # namespace_and_instruction_args.get_namespace(index),
613+ # service,
614+ # index,
615+ # namespace_and_instruction_args.get_cluster(index),
616+ # )
617+ instructions = namespace_and_instruction_args .get_instruction (index )
583618 print_colored (f"Restarted pod.\n { instructions if instructions else '' } " , Colors .YELLOW )
584619 if restart_strategy == RestartStrategy .ONE_BY_ONE :
585620 # Don't ask in the case of the last job.
0 commit comments