@@ -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,104 @@ 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+ def get_namespace_list_from_args (
517+ args : argparse .Namespace ,
518+ ) -> list [str ]:
519+ """Get a list of namespaces based on the arguments"""
520+ if args .namespace_list :
521+ return args .namespace_list
522+
523+ return [
524+ f"{ args .namespace_prefix } -{ i } "
525+ for i in range (args .start_index , args .start_index + args .num_nodes )
526+ ]
527+
528+ def get_context_list_from_args (
529+ args : argparse .Namespace ,
530+ ) -> list [str ]:
531+ """Get a list of contexts based on the arguments"""
532+ if args .cluster_list :
533+ return args .cluster_list
534+
535+ if args .cluster_prefix is None :
536+ return None
537+
538+ return [
539+ f"{ args .cluster_prefix } -{ i } "
540+ for i in range (args .start_index , args .start_index + args .num_nodes )
541+ ]
542+
543+
513544def update_config_and_restart_nodes (
514545 config_overrides : dict [str , Any ],
515- namespace_list : list [ str ] ,
546+ namespace_and_instruction_args : NamespaceAndInstructionArgs ,
516547 service : Service ,
517- cluster_list : Optional [list [str ]],
518548 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 ,
521549) -> None :
522550 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 )} "
551+ assert (
552+ namespace_and_instruction_args .namespace_list is not None
553+ and len (namespace_and_instruction_args .namespace_list ) > 0
554+ ), "namespaces must be provided"
529555
530- if not cluster_list :
556+ if not namespace_and_instruction_args . cluster_list :
531557 print_colored (
532558 "cluster-prefix/cluster-list not provided. Assuming all nodes are on the current cluster" ,
533559 Colors .RED ,
534560 )
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 } "
539561
540562 # Store original and updated configs for all nodes
541563 configs = []
542564
543565 # Process each node's configuration
544- for index , namespace in enumerate (namespace_list ):
545- cluster = cluster_list [index ] if cluster_list else None
566+ for index in range (namespace_and_instruction_args .size ()):
567+ namespace = namespace_and_instruction_args .get_namespace (index )
568+ cluster = namespace_and_instruction_args .get_cluster (index )
569+
546570 print_colored (
547571 f"\n Processing node for namespace { namespace } (cluster: { cluster if cluster else 'current cluster' } )..."
548572 )
549573
550574 # 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 ))
575+ original_config = normalize_config (
576+ get_configmap (
577+ namespace ,
578+ cluster ,
579+ service ,
580+ )
581+ )
552582
553583 # Update config
554584 updated_config = update_config_values (original_config , config_overrides )
@@ -567,19 +597,22 @@ def update_config_and_restart_nodes(
567597 print_colored ("\n Applying configurations..." )
568598 for index , config in enumerate (configs ):
569599 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- )
600+ # apply_configmap(
601+ # config["updated"],
602+ # namespace_and_instruction_args.get_namespace( index) ,
603+ # index,
604+ # namespace_and_instruction_args.get_cluster(index) ,
605+ # )
576606
577607 if restart_strategy != RestartStrategy .NO_RESTART :
578608 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
609+ # restart_pod(
610+ # namespace_and_instruction_args.get_namespace(index),
611+ # service,
612+ # index,
613+ # namespace_and_instruction_args.get_cluster(index),
614+ # )
615+ instructions = namespace_and_instruction_args .get_instruction (index )
583616 print_colored (f"Restarted pod.\n { instructions if instructions else '' } " , Colors .YELLOW )
584617 if restart_strategy == RestartStrategy .ONE_BY_ONE :
585618 # Don't ask in the case of the last job.
0 commit comments