def __produce_log_file(self, job_state): pod_r = Pod.objects(self._pykube_api).filter(selector="app=" + job_state.job_id) log_string = "" for pod_obj in pod_r.response['items']: try: pod = Pod(self._pykube_api, pod_obj) log_string += "\n\n==== Pod " + pod.name + " log start ====\n\n" log_string += pod.logs(timestamps=True) log_string += "\n\n==== Pod " + pod.name + " log end ====" except Exception as detail: log.info( "Could not write log file for pod %s due to HTTPError %s", pod_obj['metadata']['name'], detail) if isinstance(log_string, text_type): log_string = log_string.encode('utf8') logs_file_path = job_state.output_file try: with open(logs_file_path, mode="w") as logs_file: logs_file.write(log_string) except IOError as e: log.error("Couldn't produce log files for %s", job_state.job_id) log.exception(e) return logs_file_path
def __produce_log_file(self, job_state): pod_r = Pod.objects(self._pykube_api).filter(selector="app=" + job_state.job_id) logs = "" for pod_obj in pod_r.response['items']: try: pod = Pod(self._pykube_api, pod_obj) logs += "\n\n==== Pod " + pod.name + " log start ====\n\n" logs += pod.logs(timestamps=True) logs += "\n\n==== Pod " + pod.name + " log end ====" except Exception as detail: log.info("Could not write pod\'s " + pod_obj['metadata']['name'] + " log file due to HTTPError " + str(detail)) logs_file_path = job_state.output_file logs_file = open(logs_file_path, mode="w") if isinstance(logs, text_type): logs = logs.encode('utf8') logs_file.write(logs) logs_file.close() return logs_file_path