From: Mandeep Khinda Date: Thu, 23 Aug 2018 14:08:52 +0000 (+0000) Subject: Vid Template alignment. X-Git-Tag: 3.0.0-ONAP~338^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=561a91cadd2f75c831a3e4743365f58c82e951d3;p=oom.git Vid Template alignment. Moving vid readiness to version 2.0.1 Remove unnecessary config maps as a result of using readiness 2.0.1, 2 configmaps moved to resources. Check if replica instances are up dynamically. Issue-ID: VID-236 Change-Id: Iaf2989f556214f60467f7a1d7a745a95ae421506 Signed-off-by: Mandeep Khinda --- diff --git a/kubernetes/vid/charts/vid-galera/Chart.yaml b/kubernetes/vid/charts/vid-mariadb-galera/Chart.yaml similarity index 87% rename from kubernetes/vid/charts/vid-galera/Chart.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/Chart.yaml index 47f9e7e31d..757d7c5a84 100644 --- a/kubernetes/vid/charts/vid-galera/Chart.yaml +++ b/kubernetes/vid/charts/vid-mariadb-galera/Chart.yaml @@ -13,9 +13,9 @@ # limitations under the License. apiVersion: v1 -description: Chart for MariaDB Galera cluster -name: mariadb-galera -version: 2.0.0 +description: ONAP VID MariaDB Galera cluster +name: vid_mariadb_galera +version: 3.0.0 keywords: - mariadb - mysql diff --git a/kubernetes/vid/charts/vid-galera/templates/NOTES.txt b/kubernetes/vid/charts/vid-mariadb-galera/templates/NOTES.txt similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/NOTES.txt rename to kubernetes/vid/charts/vid-mariadb-galera/templates/NOTES.txt diff --git a/kubernetes/vid/charts/vid-galera/templates/configmap.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/configmap.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/configmap.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/configmap.yaml diff --git a/kubernetes/vid/charts/vid-galera/templates/pv.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/pv.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/pv.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/pv.yaml diff --git a/kubernetes/vid/charts/vid-galera/templates/pvc.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/pvc.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/pvc.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/pvc.yaml diff --git a/kubernetes/vid/charts/vid-galera/templates/secrets.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/secrets.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/secrets.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/secrets.yaml diff --git a/kubernetes/vid/charts/vid-galera/templates/service.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/service.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/service.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/service.yaml diff --git a/kubernetes/vid/charts/vid-galera/templates/statefulset.yaml b/kubernetes/vid/charts/vid-mariadb-galera/templates/statefulset.yaml similarity index 100% rename from kubernetes/vid/charts/vid-galera/templates/statefulset.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/templates/statefulset.yaml diff --git a/kubernetes/vid/charts/vid-galera/values.yaml b/kubernetes/vid/charts/vid-mariadb-galera/values.yaml similarity index 99% rename from kubernetes/vid/charts/vid-galera/values.yaml rename to kubernetes/vid/charts/vid-mariadb-galera/values.yaml index eb715a8b48..e9464b69ee 100644 --- a/kubernetes/vid/charts/vid-galera/values.yaml +++ b/kubernetes/vid/charts/vid-mariadb-galera/values.yaml @@ -126,7 +126,7 @@ resources: memory: 4Gi # Name for mariadb-galera cluster - should be unique accross all projects or other clusters -nameOverride: vid-galera +nameOverride: vid-mariadb-galera # DNS name for mariadb-galera cluster - should be unique accross all projects other clusters #dnsnameOverride: mariadb-galera diff --git a/kubernetes/vid/templates/dbcmd-configmap.yaml b/kubernetes/vid/resources/config/db_cmd.sh similarity index 57% rename from kubernetes/vid/templates/dbcmd-configmap.yaml rename to kubernetes/vid/resources/config/db_cmd.sh index aa088011ea..95b83d4b59 100644 --- a/kubernetes/vid/templates/dbcmd-configmap.yaml +++ b/kubernetes/vid/resources/config/db_cmd.sh @@ -1,4 +1,5 @@ -# Copyright © 2018 Amdocs, Bell Canada +#!/bin/sh +# Copyright © 2018 AT&T # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -12,14 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -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 - +echo "Going to run mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -P${MYSQL_PORT} ..." +mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -h${MYSQL_HOST} -P${MYSQL_PORT} < /db-config/vid-pre-init.sql +if [ $? -ne 0 ];then + echo "ERROR: Failed to run ${cmd} vid-pre-init.sql" + exit 1 +else + echo "INFO: Database initialized successfully" +fi diff --git a/kubernetes/vid/resources/config/vid-pre-init.sql b/kubernetes/vid/resources/config/vid-pre-init.sql new file mode 100644 index 0000000000..2dbbbcce6d --- /dev/null +++ b/kubernetes/vid/resources/config/vid-pre-init.sql @@ -0,0 +1,29 @@ +/* +# Copyright © 2018 AT&T +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +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; \ No newline at end of file diff --git a/kubernetes/vid/templates/check-job-completion-configmap.yaml b/kubernetes/vid/templates/check-job-completion-configmap.yaml deleted file mode 100644 index 270615a04b..0000000000 --- a/kubernetes/vid/templates/check-job-completion-configmap.yaml +++ /dev/null @@ -1,97 +0,0 @@ -# Copyright © 2018 Amdocs, Bell Canada -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 deleted file mode 100644 index 86f8d9129b..0000000000 --- a/kubernetes/vid/templates/cluster-ready-configmap.yaml +++ /dev/null @@ -1,103 +0,0 @@ -# Copyright © 2018 Amdocs, Bell Canada -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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/configmap.yaml b/kubernetes/vid/templates/configmap.yaml index f7dbf07645..cae46b4050 100644 --- a/kubernetes/vid/templates/configmap.yaml +++ b/kubernetes/vid/templates/configmap.yaml @@ -27,3 +27,16 @@ metadata: namespace: {{ include "common.namespace" . }} data: {{ tpl (.Files.Glob "resources/config/log/filebeat/*").AsConfig . | indent 2 }} +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "common.fullname" . }} + namespace: {{ include "common.namespace" . }} + labels: + app: {{ include "common.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +data: +{{ tpl (.Files.Glob "resources/config/*").AsConfig . | indent 2 }} \ No newline at end of file diff --git a/kubernetes/vid/templates/deployment.yaml b/kubernetes/vid/templates/deployment.yaml index c8545df689..c20ba10a87 100644 --- a/kubernetes/vid/templates/deployment.yaml +++ b/kubernetes/vid/templates/deployment.yaml @@ -31,16 +31,9 @@ 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: - - python + - /root/job_complete.py args: - - /tmp/vid-check-job-completion/vid_check_job_completion.py - --job-name - vid-config-galera env: @@ -52,9 +45,6 @@ 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 }}" @@ -167,10 +157,6 @@ 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 deleted file mode 100644 index 7f05af56a9..0000000000 --- a/kubernetes/vid/templates/galera-sql-configmap.yaml +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright © 2018 Amdocs, Bell Canada -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -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 index b893dbf617..2bcf64749d 100644 --- a/kubernetes/vid/templates/vid-galera-config-job.yaml +++ b/kubernetes/vid/templates/vid-galera-config-job.yaml @@ -28,35 +28,34 @@ spec: name: vid-galera-init spec: initContainers: -#dd775k: This container checks that all galera instances are up before initializing it. +#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 + - /root/ready.py +{{- $fullname := include "common.fullname" . -}} +{{- range $i,$t := until (int .Values.vid_mariadb_galera.replicaCount)}} - --container-name - - {{ include "common.fullname" . }}-mariadb-galera-0 + - {{ $fullname }}-mariadb-galera-{{$i}} +{{- end }} env: - name: NAMESPACE - value: {{ include "common.namespace" . }} - volumeMounts: - - name: init-config - mountPath: /root/ + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace 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 + - mountPath: /dbcmd-config/db_cmd.sh + name: {{ include "common.fullname" . }}-config + subPath: db_cmd.sh + - mountPath: /db-config/vid-pre-init.sql + name: {{ include "common.fullname" . }}-config + subPath: vid-pre-init.sql command: - /bin/sh args: @@ -65,22 +64,20 @@ spec: env: - name: MYSQL_PASSWORD value: "{{ .Values.config.vidmysqlpassword }}" -# valueFrom: -# secretKeyRef: -# name: {{ template "common.fullname" . }} -# key: vid-password - name: MYSQL_HOST value: "{{ .Values.config.vidmysqlhost }}" + - name: MYSQL_USER + value: "{{ .Values.config.vidmysqluser }}" + - name: MYSQL_PORT + value: "{{ .Values.config.vidmysqlport }}" + restartPolicy: Never volumes: - - name: vid-db-config - configMap: - name: {{ include "common.fullname" . }}-galera-sql-configmap - - name: dbcmd-config + - name: {{ include "common.fullname" . }}-config configMap: - name: {{ include "common.fullname" . }}-dbcmd-configmap - - name: init-config - configMap: - name: {{ include "common.fullname" . }}-cluster-ready-configmap - restartPolicy: Never - + name: {{ include "common.fullname" . }} + items: + - key: db_cmd.sh + path: db_cmd.sh + - key: vid-pre-init.sql + path: vid-pre-init.sql diff --git a/kubernetes/vid/values.yaml b/kubernetes/vid/values.yaml index 8487743177..63726df07a 100644 --- a/kubernetes/vid/values.yaml +++ b/kubernetes/vid/values.yaml @@ -17,9 +17,8 @@ # Declare variables to be passed into your templates. global: nodePortPrefix: 302 - repositorySecret: eyJuZXh1czMub25hcC5vcmc6MTAwMDEiOnsidXNlcm5hbWUiOiJkb2NrZXIiLCJwYXNzd29yZCI6ImRvY2tlciIsImVtYWlsIjoiQCIsImF1dGgiOiJaRzlqYTJWeU9tUnZZMnRsY2c9PSJ9fQ== readinessRepository: oomk8s - readinessImage: readiness-check:1.0.0 + readinessImage: readiness-check:2.0.1 loggingRepository: docker.elastic.co loggingImage: beats/filebeat:5.5.0 @@ -54,8 +53,9 @@ config: logstashPort: 5044 # subchart configuration -mariadb-galera: - nameOverride: vid-mariadb-galera +vid_mariadb_galera: +# nameOverride: vid-mariadb-galera + replicaCount: 1 # default number of instances replicaCount: 1