@@ -505,15 +505,14 @@ def collect_logs_from_pod(namespace, pod, logs_dir):
505
505
# getting the logs of the containers before the restart can help us with debugging potential bugs
506
506
get_logs_before_restart_cmd = "kubectl logs -c {} -n {} {} -p" \
507
507
.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 :
512
513
file_handle .write (output )
513
- else : # no previous container instance found; did not restart
514
- os .unlink (file_handle .name )
515
514
516
- logger .info ("Namespace '%s': + %s-%s" , namespace , pod , container )
515
+ logger .info ("Namespace '%s': + %s-%s" , namespace , pod , container )
517
516
518
517
519
518
def get_pod_names (namespace , selector = "" ):
0 commit comments