summaryrefslogtreecommitdiffstats
path: root/kubernetes/vid/templates/cluster-ready-configmap.yaml
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-05-30 18:41:14 +0300
committerMichael Lando <ml636r@att.com>2018-06-04 15:54:52 +0000
commit2dda01daf2e5c2053221bf4eac81e2585f2b2c7f (patch)
tree8d98d6b99e4bcdadedd150f51f6d1cb75fb6392b /kubernetes/vid/templates/cluster-ready-configmap.yaml
parent5768008d908cb4868652746c6a2aa46437c8c1c2 (diff)
VID Resiliency & Scalability
Change-Id: Ifc593e2e33c3430c74156b4b153263c11127bfa9 Issue-ID: VID-160 Signed-off-by: Michael Lando <ml636r@att.com>
Diffstat (limited to 'kubernetes/vid/templates/cluster-ready-configmap.yaml')
-rw-r--r--kubernetes/vid/templates/cluster-ready-configmap.yaml89
1 files changed, 89 insertions, 0 deletions
diff --git a/kubernetes/vid/templates/cluster-ready-configmap.yaml b/kubernetes/vid/templates/cluster-ready-configmap.yaml
new file mode 100644
index 0000000000..296db335a7
--- /dev/null
+++ b/kubernetes/vid/templates/cluster-ready-configmap.yaml
@@ -0,0 +1,89 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "common.fullname" . }}-cluster-ready-configmap
+ namespace: {{ include "common.namespace" . }}
+data:
+ vid_ready.py : |-
+ #!/usr/bin/python
+ from kubernetes import client, config
+ import time, argparse, logging, sys, os
+
+ #extract env variables.
+ namespace = os.environ['NAMESPACE']
+ cert = os.environ['CERT']
+ host = os.environ['KUBERNETES_SERVICE_HOST']
+ token_path = os.environ['TOKEN']
+
+ with open(token_path, 'r') as token_file:
+ token = token_file.read().replace('\n', '')
+
+ client.configuration.host = "https://" + host
+ client.configuration.ssl_ca_cert = cert
+ client.configuration.api_key['authorization'] = token
+ client.configuration.api_key_prefix['authorization'] = 'Bearer'
+
+ #setup logging
+ log = logging.getLogger(__name__)
+ handler = logging.StreamHandler(sys.stdout)
+ handler.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s'))
+ handler.setLevel(logging.INFO)
+ log.addHandler(handler)
+ log.setLevel(logging.INFO)
+
+
+ def is_ready(container_name):
+ log.info( "Checking if " + container_name + " is ready")
+ # config.load_kube_config() # for local testing
+ # namespace='onap-sdc' # for local testing
+ v1 = client.CoreV1Api()
+
+ ready = False
+
+ try:
+ response = v1.list_namespaced_pod(namespace=namespace, watch=False)
+
+ for i in response.items:
+ #log.info(i.metadata.name)
+ for s in i.status.container_statuses:
+ #log.info(s.name)
+ if i.metadata.name == container_name:
+ ready = s.ready
+ if not ready:
+ log.info( container_name + " is not ready.")
+ else:
+ log.info( container_name + " is ready!")
+ else:
+ continue
+ return ready
+ except Exception as e:
+ log.error("Exception when calling list_namespaced_pod: %s\n" % e)
+
+
+ def main(args):
+ # args are a list of container names
+ for container_name in args:
+ # 5 min, TODO: make configurable
+ timeout = time.time() + 60 * 10
+ while True:
+ ready = is_ready(container_name)
+ if ready is True:
+ break
+ elif time.time() > timeout:
+ log.warning( "timed out waiting for '" + container_name + "' to be ready")
+ exit(1)
+ else:
+ time.sleep(5)
+
+
+ if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Process some names.')
+ parser.add_argument('--container-name', action='append', required=True, help='A container name')
+ args = parser.parse_args()
+ arg_dict = vars(args)
+
+ for arg in arg_dict.itervalues():
+ main(arg)
+
+
+