Skip to content

Commit

Permalink
Wait for Pod & Job to be ready (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
wgrzelak authored and huyhg committed Feb 11, 2019
1 parent 60afa3f commit 96d5ebd
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions marketplace/deployer_util/wait_for_ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ def is_healthy(resource):
return is_deployment_ready(resource)
if resource['kind'] == "StatefulSet":
return is_sts_ready(resource)
if resource['kind'] == "Pod":
return is_pod_ready(resource)
if resource['kind'] == "Job":
return is_job_ready(resource)
if resource['kind'] == "PersistentVolumeClaim":
return is_pvc_ready(resource)
if resource['kind'] == "Service":
Expand Down Expand Up @@ -133,6 +137,26 @@ def is_sts_ready(resource):
return False


def is_pod_ready(resource):
if status_condition_is_true('Ready', resource):
return True

log("INFO Pod/{} is not ready.".format(name(resource)))
return False


def is_job_ready(resource):
# Don't wait for Deployer.
if is_deployer_job(resource):
return True

if status_condition_is_true('Complete', resource):
return True

log("INFO Job/{} is not ready.".format(name(resource)))
return False


def is_pvc_ready(resource):
if phase(resource) == "Bound":
return True
Expand Down Expand Up @@ -161,14 +185,32 @@ def is_ingress_ready(resource):
return False


def is_deployer_job(resource):
if 'app.kubernetes.io/component' in labels(resource):
return (labels(resource)['app.kubernetes.io/component'] ==
'deployer.marketplace.cloud.google.com')
return False


def name(resource):
return resource['metadata']['name']


def labels(resource):
return resource['metadata']['labels']


def total_replicas(resource):
return resource['spec']['replicas']


def status_condition_is_true(condition_type, resource):
for condition in resource.get('status', {}).get('conditions', []):
if condition['type'] == condition_type:
return condition['status'] == 'True'
return False


def ready_replicas(resource):
if not 'readyReplicas' in resource['status']:
return 0
Expand Down

0 comments on commit 96d5ebd

Please sign in to comment.