4 name: {{ include "common.fullname" . }}-cluster-ready-configmap
5 namespace: {{ include "common.namespace" . }}
9 from kubernetes import client, config
10 import time, argparse, logging, sys, os
12 #extract env variables.
13 namespace = os.environ['NAMESPACE']
14 cert = os.environ['CERT']
15 host = os.environ['KUBERNETES_SERVICE_HOST']
16 token_path = os.environ['TOKEN']
18 with open(token_path, 'r') as token_file:
19 token = token_file.read().replace('\n', '')
21 client.configuration.host = "https://" + host
22 client.configuration.ssl_ca_cert = cert
23 client.configuration.api_key['authorization'] = token
24 client.configuration.api_key_prefix['authorization'] = 'Bearer'
27 log = logging.getLogger(__name__)
28 handler = logging.StreamHandler(sys.stdout)
29 handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
30 handler.setLevel(logging.INFO)
31 log.addHandler(handler)
32 log.setLevel(logging.INFO)
35 def is_ready(container_name):
36 log.info( "Checking if " + container_name + " is ready")
37 # config.load_kube_config() # for local testing
38 # namespace='onap-sdc' # for local testing
39 v1 = client.CoreV1Api()
44 response = v1.list_namespaced_pod(namespace=namespace, watch=False)
46 for i in response.items:
47 #log.info(i.metadata.name)
48 for s in i.status.container_statuses:
50 if i.metadata.name == container_name:
53 log.info( container_name + " is not ready.")
55 log.info( container_name + " is ready!")
59 except Exception as e:
60 log.error("Exception when calling list_namespaced_pod: %s\n" % e)
64 # args are a list of container names
65 for container_name in args:
66 # 5 min, TODO: make configurable
67 timeout = time.time() + 60 * 10
69 ready = is_ready(container_name)
72 elif time.time() > timeout:
73 log.warning( "timed out waiting for '" + container_name + "' to be ready")
79 if __name__ == "__main__":
80 parser = argparse.ArgumentParser(description='Process some names.')
81 parser.add_argument('--container-name', action='append', required=True, help='A container name')
82 args = parser.parse_args()
85 for arg in arg_dict.itervalues():