summaryrefslogtreecommitdiffstats
path: root/kubernetes/vid/templates
diff options
context:
space:
mode:
authorMandeep Khinda <Mandeep.Khinda@amdocs.com>2018-06-04 18:30:08 +0000
committerGerrit Code Review <gerrit@onap.org>2018-06-04 18:30:08 +0000
commit71e6b72212beb946305ca3e9c17b8898a5378923 (patch)
tree62bb22b8b64ae03182b75c675867a71fa8279d89 /kubernetes/vid/templates
parent71bf8ec6164c9c083346fe51d8a4048e65724510 (diff)
parent2dda01daf2e5c2053221bf4eac81e2585f2b2c7f (diff)
Merge "VID Resiliency & Scalability"
Diffstat (limited to 'kubernetes/vid/templates')
-rw-r--r--kubernetes/vid/templates/check-job-completion-configmap.yaml83
-rw-r--r--kubernetes/vid/templates/cluster-ready-configmap.yaml89
-rw-r--r--kubernetes/vid/templates/dbcmd-configmap.yaml11
-rw-r--r--kubernetes/vid/templates/deployment.yaml30
-rw-r--r--kubernetes/vid/templates/galera-sql-configmap.yaml21
-rw-r--r--kubernetes/vid/templates/vid-galera-config-job.yaml70
6 files changed, 296 insertions, 8 deletions
diff --git a/kubernetes/vid/templates/check-job-completion-configmap.yaml b/kubernetes/vid/templates/check-job-completion-configmap.yaml
new file mode 100644
index 0000000000..b9c4488338
--- /dev/null
+++ b/kubernetes/vid/templates/check-job-completion-configmap.yaml
@@ -0,0 +1,83 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "common.fullname" . }}-check-job-completion
+ namespace: {{ include "common.namespace" . }}
+data:
+ vid_check_job_completion.py: |
+ #!/usr/bin/python
+ from __future__ import print_function
+ import time, argparse, logging, sys, os
+ import kubernetes.client
+ from kubernetes import client, config
+ from pprint import pprint
+
+ #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.api_key['authorization'] = token
+ client.configuration.api_key_prefix['authorization'] = 'Bearer'
+ client.configuration.host = "https://" + str(host)
+ client.configuration.ssl_ca_cert = cert
+
+ api_instance = client.BatchV1Api()
+
+ #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(job_name):
+ log.info( "[INFO] Checking if " + job_name + " is completed")
+ pretty = True
+ job_status = False
+
+ try:
+ api_response = api_instance.read_namespaced_job_status(job_name, namespace, pretty=pretty)
+ except Exception as e:
+ print("Exception when calling BatchV1Api->read_namespaced_job_status: %s\n" % e)
+
+ pprint(api_response)
+ if api_response.status.succeeded == 1:
+ job_status_type = api_response.status.conditions[0].type
+ if job_status_type == "Complete":
+ job_status = True
+
+ print("[DBG] jobStatus: " + unicode(job_status))
+ return job_status
+
+
+ def main(args):
+ for job_name in args:
+ timeout = time.time() + 60 * 10
+ while True:
+ ready = is_ready(job_name)
+ if ready is True :
+ break
+ elif time.time() > timeout:
+ log.warning( "timed out waiting for '" + job_name + "' to be ready")
+ exit(1)
+ else:
+ time.sleep(5)
+
+
+ if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Process some names.')
+ parser.add_argument('--job-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)
+
+
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)
+
+
+
diff --git a/kubernetes/vid/templates/dbcmd-configmap.yaml b/kubernetes/vid/templates/dbcmd-configmap.yaml
new file mode 100644
index 0000000000..7c06e748f4
--- /dev/null
+++ b/kubernetes/vid/templates/dbcmd-configmap.yaml
@@ -0,0 +1,11 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "common.fullname" . }}-dbcmd-configmap
+ namespace: {{ include "common.namespace" . }}
+data:
+ db_cmd.sh : |-
+ #!/bin/sh
+ #mysql -uroot -p${MYSQL_ROOT_PASSWORD} -h${MYSQL_HOST} -P3306 < /db-config/vid-pre-init.sql
+ mysql -uvidadmin -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -P3306 < /db-config/vid-pre-init.sql
+
diff --git a/kubernetes/vid/templates/deployment.yaml b/kubernetes/vid/templates/deployment.yaml
index 6da8dd2e3f..8d490fbc4d 100644
--- a/kubernetes/vid/templates/deployment.yaml
+++ b/kubernetes/vid/templates/deployment.yaml
@@ -31,11 +31,18 @@ spec:
release: {{ .Release.Name }}
spec:
initContainers:
+#dd775k: This container checks if the job that wait for all db instances to be up and initializes the db had finished.
+# - command:
+# - /bin/sh
+# args:
+# - "-c"
+# - "sleep 1000000000m"
- command:
- - /root/ready.py
+ - python
args:
- - --container-name
- - {{ .Values.mariadb.nameOverride }}
+ - /tmp/vid-check-job-completion/vid_check_job_completion.py
+ - --job-name
+ - vid-config-galera
env:
- name: NAMESPACE
valueFrom:
@@ -45,6 +52,9 @@ spec:
image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
name: {{ include "common.name" . }}-readiness
+ volumeMounts:
+ - mountPath: /tmp/vid-check-job-completion
+ name: vid-check-job-completion
containers:
- name: {{ include "common.name" . }}
image: "{{ include "common.repository" . }}/{{ .Values.image }}"
@@ -83,7 +93,7 @@ spec:
- name: VID_ECOMP_SHARED_CONTEXT_REST_URL
value: http://portal-app.{{ include "common.namespace" . }}:{{ .Values.config.onapport }}/ONAPPORTAL/context
- name: VID_MSO_SERVER_URL
- value: http://so.{{ include "common.namespace" . }}:{{ .Values.config.msoport }}
+ value: http://mso.{{ include "common.namespace" . }}:{{ .Values.config.msoport }}
- name: VID_MSO_PASS
value: "{{ .Values.config.vidmsopass }}"
- name: MSO_DME2_SERVER_URL
@@ -107,10 +117,9 @@ spec:
- name: VID_MYSQL_USER
value: "{{ .Values.config.vidmysqluser }}"
- name: VID_MYSQL_PASS
- valueFrom:
- secretKeyRef:
- name: {{ template "common.fullname" . }}
- key: vid-password
+ value: "{{ .Values.config.vidmysqlpassword }}"
+ #valueFrom:
+ # secretKeyRef: {name: {{ include "common.fullname" . }}, key: vid-password}
- name: VID_MYSQL_MAXCONNECTIONS
value: "{{ .Values.config.vidmysqlmaxconnections }}"
volumeMounts:
@@ -158,5 +167,10 @@ spec:
- name: vid-logback
configMap:
name: {{ include "common.fullname" . }}-log-configmap
+ - name: vid-check-job-completion
+ configMap:
+ name: {{ include "common.fullname" . }}-check-job-completion
imagePullSecrets:
- name: "{{ include "common.namespace" . }}-docker-registry-key"
+
+
diff --git a/kubernetes/vid/templates/galera-sql-configmap.yaml b/kubernetes/vid/templates/galera-sql-configmap.yaml
new file mode 100644
index 0000000000..ccda497887
--- /dev/null
+++ b/kubernetes/vid/templates/galera-sql-configmap.yaml
@@ -0,0 +1,21 @@
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: {{ include "common.fullname" . }}-galera-sql-configmap
+ namespace: "{{ include "common.namespace" . }}"
+data:
+ vid-pre-init.sql: |-
+ CREATE TABLE IF NOT EXISTS `vid_openecomp_epsdk`.`schema_info` (
+ `SCHEMA_ID` VARCHAR(25) NOT NULL,
+ `SCHEMA_DESC` VARCHAR(75) NOT NULL,
+ `DATASOURCE_TYPE` VARCHAR(100) NULL DEFAULT NULL,
+ `CONNECTION_URL` VARCHAR(200) NOT NULL,
+ `USER_NAME` VARCHAR(45) NOT NULL,
+ `PASSWORD` VARCHAR(45) NULL DEFAULT NULL,
+ `DRIVER_CLASS` VARCHAR(100) NOT NULL,
+ `MIN_POOL_SIZE` INT(11) NOT NULL,
+ `MAX_POOL_SIZE` INT(11) NOT NULL,
+ `IDLE_CONNECTION_TEST_PERIOD` INT(11) NOT NULL)
+ ENGINE = InnoDB
+ DEFAULT CHARACTER SET = utf8;
+
diff --git a/kubernetes/vid/templates/vid-galera-config-job.yaml b/kubernetes/vid/templates/vid-galera-config-job.yaml
new file mode 100644
index 0000000000..b02d5b4913
--- /dev/null
+++ b/kubernetes/vid/templates/vid-galera-config-job.yaml
@@ -0,0 +1,70 @@
+apiVersion: batch/v1
+kind: Job
+metadata:
+ name: vid-config-galera
+ namespace: {{ include "common.namespace" . }}
+ labels:
+ app: vid-config-galera
+ release: {{ .Release.Name }}
+spec:
+ template:
+ metadata:
+ name: vid-galera-init
+ spec:
+ initContainers:
+#dd775k: This container checks that all galera instances are up before initializing it.
+ - name: vid-init-galera-readiness
+ image: "{{ .Values.global.readinessRepository }}/{{ .Values.global.readinessImage }}"
+ imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+# - /bin/sh
+# args:
+# - "-c"
+# - "sleep 1000000000m"
+ command:
+ - python
+ args:
+ - /root/vid_ready.py
+ - --container-name
+ - {{ include "common.fullname" . }}-mariadb-galera-0
+ env:
+ - name: NAMESPACE
+ value: {{ include "common.namespace" . }}
+ volumeMounts:
+ - name: init-config
+ mountPath: /root/
+ containers:
+ - name: vid-config-galeradb
+ image: {{ .Values.mariadb_image }}
+ imagePullPolicy: "{{ .Values.pullPolicy }}"
+ volumeMounts:
+ - name: vid-db-config
+ mountPath: /db-config
+ - name: dbcmd-config
+ mountPath: /dbcmd-config
+ command:
+ - /bin/sh
+ args:
+ - -x
+ - /dbcmd-config/db_cmd.sh
+ env:
+ - name: MYSQL_PASSWORD
+ value: "{{ .Values.config.vidmysqlpassword }}"
+# valueFrom:
+# secretKeyRef:
+# name: {{ template "common.fullname" . }}
+# key: vid-password
+ - name: MYSQL_HOST
+ value: "{{ .Values.config.vidmysqlhost }}"
+ volumes:
+ - name: vid-db-config
+ configMap:
+ name: {{ include "common.fullname" . }}-galera-sql-configmap
+ - name: dbcmd-config
+ configMap:
+ name: {{ include "common.fullname" . }}-dbcmd-configmap
+ - name: init-config
+ configMap:
+ name: {{ include "common.fullname" . }}-cluster-ready-configmap
+ restartPolicy: Never
+
+