[DMAAP] Use the common mariadb-galera instance

Have following updates for DMAAP-DR-PROV:
- Add section under .Values.global for shared mariadb instance default
info with a condition to instantiate local instance
- Add section under .Values for mariadb-init and mariadb-galera projects
- Add condition under requirments.yaml to install local mariadb instance
- Update deployment with DB host parameter and reflect it into resource
file (using the templates defined under templates/_mariadb.tpl)

Issue-ID: OOM-2774
Signed-off-by: Mahmoud Abdelhamid <mahmoud.abdelhamid@orange.com>
Change-Id: I8a8e2c179710680282f4ad686dc44e75356a1b81
diff --git a/kubernetes/dmaap/components/dmaap-dr-prov/requirements.yaml b/kubernetes/dmaap/components/dmaap-dr-prov/requirements.yaml
index 65867f5..3c25c94 100644
--- a/kubernetes/dmaap/components/dmaap-dr-prov/requirements.yaml
+++ b/kubernetes/dmaap/components/dmaap-dr-prov/requirements.yaml
@@ -23,7 +23,10 @@
     version: ~8.x-0
     repository: '@local'
   - name: mariadb-galera
-    alias: mariadb
+    version: ~8.x-0
+    repository: '@local'
+    condition: global.mariadbGalera.localCluster
+  - name: mariadb-init
     version: ~8.x-0
     repository: '@local'
   - name: certInitializer
diff --git a/kubernetes/dmaap/components/dmaap-dr-prov/resources/config/provserver.properties b/kubernetes/dmaap/components/dmaap-dr-prov/resources/config/provserver.properties
index a747238..18ab419 100644
--- a/kubernetes/dmaap/components/dmaap-dr-prov/resources/config/provserver.properties
+++ b/kubernetes/dmaap/components/dmaap-dr-prov/resources/config/provserver.properties
@@ -42,7 +42,7 @@
 
 # Database access
 org.onap.dmaap.datarouter.db.driver   = org.mariadb.jdbc.Driver
-org.onap.dmaap.datarouter.db.url      = jdbc:mariadb://{{.Values.config.dmaapDrDb.mariadbServiceName}}:{{.Values.config.dmaapDrDb.mariadbServicePort}}/{{.Values.mariadb.db.name}}
+org.onap.dmaap.datarouter.db.url      = jdbc:mariadb://{{ include "common.mariadbService" . }}:{{ include "common.mariadbPort" . }}/{{index .Values "mariadb-galera" "db" "name"}}
 org.onap.dmaap.datarouter.db.login    = ${DB_USERNAME}
 org.onap.dmaap.datarouter.db.password = ${DB_PASSWORD}
 
diff --git a/kubernetes/dmaap/components/dmaap-dr-prov/templates/deployment.yaml b/kubernetes/dmaap/components/dmaap-dr-prov/templates/deployment.yaml
index 6167896..a3051ee 100644
--- a/kubernetes/dmaap/components/dmaap-dr-prov/templates/deployment.yaml
+++ b/kubernetes/dmaap/components/dmaap-dr-prov/templates/deployment.yaml
@@ -42,8 +42,8 @@
           command:
           - /app/ready.py
           args:
-          - --container-name
-          - {{ .Values.config.dmaapDrDb.mariadbContName }}
+          - --job-name
+          - {{ include "common.release" . }}-dmaap-dr-mariadb-init-config-job
           env:
           - name: NAMESPACE
             valueFrom:
@@ -81,9 +81,9 @@
             periodSeconds: {{ .Values.readiness.periodSeconds }}
           env:
           - name: DB_USERNAME
-            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "dmaap-dr-db-user-secret" "key" "login") | indent 12 }}
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "dmaap-dr-db-user-credentials" "key" "login") | indent 12 }}
           - name: DB_PASSWORD
-            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "dmaap-dr-db-user-secret" "key" "password") | indent 12 }}
+            {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "dmaap-dr-db-user-credentials" "key" "password") | indent 12 }}
           volumeMounts: {{ include "common.certInitializer.volumeMount" . | nindent 10 }}
           - mountPath: /etc/localtime
             name: localtime
diff --git a/kubernetes/dmaap/components/dmaap-dr-prov/values.yaml b/kubernetes/dmaap/components/dmaap-dr-prov/values.yaml
index 7564ccf..cf25468 100644
--- a/kubernetes/dmaap/components/dmaap-dr-prov/values.yaml
+++ b/kubernetes/dmaap/components/dmaap-dr-prov/values.yaml
@@ -19,17 +19,23 @@
   nodePortPrefix: 302
   loggingDirectory: /opt/app/datartr/logs
   persistence: {}
+  mariadbGalera: &mariadbGalera
+    #This flag allows DMAAP-DR to instantiate its own mariadb-galera cluster
+    localCluster: false
+    service: mariadb-galera
+    internalPort: 3306
+    nameOverride: mariadb-galera
 
 #################################################################
 # Secrets metaconfig
 #################################################################
 secrets:
-  - uid: dmaap-dr-db-user-secret
-    name: &dbSecretName '{{ include "common.release" . }}-dmaap-dr-db-user-secret'
+  - name: &dbUserSecretName '{{ include "common.release" . }}-dmaap-dr-db-user-credentials'
+    uid: 'dmaap-dr-db-user-credentials'
     type: basicAuth
-    externalSecret: '{{ tpl (default "" .Values.config.dmaapDrDb.userCredentialsExternalSecret) . }}'
-    login: '{{ .Values.config.dmaapDrDb.userName }}'
-    password: '{{ .Values.config.dmaapDrDb.userPassword }}'
+    externalSecret: '{{ ternary "" (tpl (default "" (index .Values "mariadb-galera" "db" "externalSecret")) .) (hasSuffix "dmaap-dr-db-user-credentials" (index .Values "mariadb-galera" "db" "externalSecret"))}}'
+    login: '{{ index .Values "mariadb-galera" "db" "user" }}'
+    password: '{{ index .Values "mariadb-galera" "db" "password" }}'
 
 #################################################################
 # Application configuration defaults.
@@ -92,31 +98,29 @@
     # and supports the following log levels: TRACE, DEBUG, INFO, WARN, ERROR, OFF
     logLevel: "INFO"
 
-  # dr-prov db configuration
-  dmaapDrDb:
-    mariadbServiceName: dmaap-dr-db
-    mariadbServicePort: 3306
-    mariadbContName: &dmaap-dr-db dmaap-dr-db
-    userName: datarouter
-#    userPassword: password
-#    userCredentialsExternalSecret: some secret
-
 # mariadb-galera configuration
-mariadb:
-  name: *dmaap-dr-db
-  nameOverride: *dmaap-dr-db
+mariadb-galera:
+  nameOverride: &dbServer dmaap-dr-db
   replicaCount: 1
   db:
-    externalSecret: *dbSecretName
-    name: datarouter
+    name: &mysqlDbName datarouter
+    user: datarouter
+    # password:
+    externalSecret: *dbUserSecretName 
   service:
-    name: dmaap-dr-db
+    name: *dbServer
   nfsprovisionerPrefix: dmaap-dr-db
   persistence:
     size: 1Gi
     mountSubPath: data-router/dr-db-data
   serviceAccount:
-    nameOverride: *dmaap-dr-db
+    nameOverride: *dbServer
+
+mariadb-init:
+  config:
+    userCredentialsExternalSecret: *dbUserSecretName
+    mysqlDatabase: *mysqlDbName
+  nameOverride: dmaap-dr-mariadb-init
 
 #################################################################
 # AAF part