def _PrintLogs(pod_name_prefix, job_name):
"""Prints pod logs.
If a pod has been restarted, prints logs from previous run. Otherwise,
prints the logs from current run. We print logs for pods selected
based on pod_name_prefix and job_name.
Args:
pod_name_prefix: value of 'name-prefix' selector.
job_name: value of 'job' selector.
"""
for pod_name in _GetPodNames(pod_name_prefix, job_name):
try:
# Get previous logs.
logs_command = [_KUBECTL, 'logs', '-p', pod_name]
logging.info('Command to get logs: %s', ' '.join(logs_command))
output = subprocess.check_output(logs_command, universal_newlines=True)
except subprocess.CalledProcessError:
# We couldn't get previous logs, so we will try to get current logs.
logs_command = [_KUBECTL, 'logs', pod_name]
logging.info('Command to get logs: %s', ' '.join(logs_command))
output = subprocess.check_output(logs_command, universal_newlines=True)
print('%s logs:' % pod_name)
print(output)
评论列表
文章目录