Skip to content

Commit 91cbadc

Browse files
authored
RED-76192 - Fix log collector previous container fetch logic - unlinking while opened the previous container log file is still inuse. (#234)
1 parent 203225e commit 91cbadc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

log_collector/log_collector.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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

519518
def get_pod_names(namespace, selector=""):

0 commit comments

Comments
 (0)