diff options
author | Mandeep Khinda <Mandeep.Khinda@amdocs.com> | 2017-06-24 11:49:37 -0400 |
---|---|---|
committer | Mandeep Khinda <Mandeep.Khinda@amdocs.com> | 2017-06-24 11:49:37 -0400 |
commit | d6ea987caed84a9f36030a5a1516df7c6186362d (patch) | |
tree | 265dda9cfb43a78542e4b2ccac382a8a5583bc56 /kubernetes/readiness | |
parent | 43d96ac929c93d0aa2a55d860e0425a39118f7b4 (diff) |
onap on kubernetes source files
Change-Id: I4de34baf90979651223a28323010deb7aef21946
Signed-off-by: Mandeep Khinda <Mandeep.Khinda@amdocs.com>
Diffstat (limited to 'kubernetes/readiness')
-rw-r--r-- | kubernetes/readiness/dep-health-init.yaml | 33 | ||||
-rw-r--r-- | kubernetes/readiness/docker/init/Dockerfile | 20 | ||||
-rw-r--r-- | kubernetes/readiness/docker/init/ready.py | 76 |
3 files changed, 129 insertions, 0 deletions
diff --git a/kubernetes/readiness/dep-health-init.yaml b/kubernetes/readiness/dep-health-init.yaml new file mode 100644 index 0000000000..d77127b201 --- /dev/null +++ b/kubernetes/readiness/dep-health-init.yaml @@ -0,0 +1,33 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + labels: + app: healthy + version: 1.0.0 + name: healthy +spec: + selector: + matchLabels: + app: healthy + version: 1.0.0 + template: + metadata: + labels: + app: healthy + version: 1.0.0 + name: healthy + spec: + containers: + - args: + - --container-name + - hbase + command: + - /root/ready.py + image: oomk8s/readiness-check:1.0.0 + imagePullPolicy: Always + name: healthy + env: + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace diff --git a/kubernetes/readiness/docker/init/Dockerfile b/kubernetes/readiness/docker/init/Dockerfile new file mode 100644 index 0000000000..b0fd68b44e --- /dev/null +++ b/kubernetes/readiness/docker/init/Dockerfile @@ -0,0 +1,20 @@ +from ubuntu:16.04 + +ENV no_proxy "localhost,127.0.0.1,.cluster.local,$KUBERNETES_SERVICE_HOST" +# Setup Corporate proxy +ENV https_proxy http://genproxy.amdocs.com:8080/ +ENV http_proxy http://genproxy.amdocs.com:8080/ + +# Additional packages +RUN apt-get update +RUN apt-get install -y apt-utils git wget curl dnsutils python python-pip jq net-tools coreutils vim + +RUN pip install requests pyyaml kubernetes + + +ENV CERT="/var/run/secrets/kubernetes.io/serviceaccount/ca.crt" +ENV TOKEN="/var/run/secrets/kubernetes.io/serviceaccount/token" + +COPY ready.py /root/ready.py +RUN chmod a+x /root/ready.py +ENTRYPOINT /root/ready.py diff --git a/kubernetes/readiness/docker/init/ready.py b/kubernetes/readiness/docker/init/ready.py new file mode 100644 index 0000000000..c5b55eef18 --- /dev/null +++ b/kubernetes/readiness/docker/init/ready.py @@ -0,0 +1,76 @@ +#!/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: + for s in i.status.container_statuses: + if s.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) |