From 96d5ebd4b4e9a398ade8eddac24c8d9ffe84ed59 Mon Sep 17 00:00:00 2001 From: wgrzelak Date: Mon, 11 Feb 2019 22:42:54 +0100 Subject: [PATCH] Wait for Pod & Job to be ready (#312) --- marketplace/deployer_util/wait_for_ready.py | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/marketplace/deployer_util/wait_for_ready.py b/marketplace/deployer_util/wait_for_ready.py index 7e5c0eb8..5fa89e33 100755 --- a/marketplace/deployer_util/wait_for_ready.py +++ b/marketplace/deployer_util/wait_for_ready.py @@ -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": @@ -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 @@ -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