def get_failed_pod_logs(self, failed_pod): for init_container_status in failed_pod['status'].get( 'initContainerStatuses', []): if init_container_status['state'].get( 'terminated', {}).get('reason') == 'ContainerCannotRun': return 'Init container failed! ' + str( init_container_status['state']['terminated']['message']) for container_status in failed_pod['status'].get( 'containerStatuses', []): if container_status['state'].get( 'terminated', {}).get('reason') == 'ContainerCannotRun': return 'Container failed! ' + str( container_status['state']['terminated']['message']) name = failed_pod['metadata']['name'] namespace = failed_pod['metadata'].get('namespace') return api.logs(name, namespace=namespace)[0].decode()
def raise_with_log(self, container_name): stdout, stderr = api.logs(self.definition_name, container_name) raise PodError('Failure in {}'.format(container_name), container_name, stdout, stderr)