Skip to content

Commit

Permalink
Merge pull request #69 from 2gis/job-status-code-with-show-logs
Browse files Browse the repository at this point in the history
exits with non zero exit code if job failed and show-logs flag provided
  • Loading branch information
dekhtyarev authored Dec 17, 2018
2 parents 13b4f4c + 5dff2fb commit 00799e4
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions k8s/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,17 @@ def _deploy(self, template_body, file_path):
log.warning('Pod not found for showing logs')
return

if self._wait_pod_running(
kube_client,
pod_name,
tries=settings.CHECK_STATUS_TRIES,
timeout=settings.CHECK_STATUS_TIMEOUT):
is_successful = self._wait_pod_running(
kube_client,
pod_name,
tries=settings.CHECK_STATUS_TRIES,
timeout=settings.CHECK_STATUS_TIMEOUT)

for pod_container in pod_containers:
log.info('\n{}'.format(kube_client.read_pod_logs(pod_name, pod_container)))
for pod_container in pod_containers:
log.info('\n{}'.format(kube_client.read_pod_logs(pod_name, pod_container)))

if not is_successful:
raise RuntimeError('Job running failed')

def _destroy_all(self, file_path):
for template_body in get_template_contexts(file_path):
Expand Down Expand Up @@ -389,12 +392,13 @@ def _wait_pod_running(kube_client, pod_name, tries, timeout):
status = kube_client.read_pod_status(pod_name)

log.info('Pod "{}" status: {}'.format(pod_name, status.status.phase))
if status.status.phase in ['Succeeded', 'Failed', 'Unknown']:
if status.status.phase == 'Succeeded':
return True
if status.status.phase in ['Failed', 'Unknown']:
return False
sleep(timeout)

log.error('Pod "{}" not completed for {} tries'.format(pod_name, tries))
return False
raise RuntimeError('Pod "{}" not completed for {} tries'.format(pod_name, tries))

@staticmethod
def _wait_destruction_complete(kube_client, kind, tries, timeout):
Expand Down

0 comments on commit 00799e4

Please sign in to comment.