@@ -505,15 +505,14 @@ def collect_logs_from_pod(namespace, pod, logs_dir):
505505 # getting the logs of the containers before the restart can help us with debugging potential bugs
506506 get_logs_before_restart_cmd = "kubectl logs -c {} -n {} {} -p" \
507507 .format (container , namespace , pod )
508- with open (os .path .join (logs_dir , "{}.log" .format (f'{ pod } -{ container } -instance-before-restart' )),
509- "w+" ) as file_handle :
510- err_code , output = run_shell_command (get_logs_before_restart_cmd )
511- if err_code == 0 :
508+ err_code , output = run_shell_command (get_logs_before_restart_cmd )
509+ container_log_before_restart_file = os .path .join (logs_dir ,
510+ "{}.log" .format (f'{ pod } -{ container } -instance-before-restart' ))
511+ if err_code == 0 : # Previous container instance found; did restart.
512+ with open (container_log_before_restart_file , "w+" ) as file_handle :
512513 file_handle .write (output )
513- else : # no previous container instance found; did not restart
514- os .unlink (file_handle .name )
515514
516- logger .info ("Namespace '%s': + %s-%s" , namespace , pod , container )
515+ logger .info ("Namespace '%s': + %s-%s" , namespace , pod , container )
517516
518517
519518def get_pod_names (namespace , selector = "" ):
0 commit comments