[MARIADB][COMMON] Add support for mariadb-operator

Add template functions for the mariadb-operator resources
and update the mariadb-galera chart to support them
Change the flag to "useOperator" in cassandra to the global setup
and additional labels for cassandra resources
Changed Policy DB users to support the new mariadb User
and fixed db.sh script to wait for the DB user creation
Use the new readiness image 5.0.1 with the "app-name" option
Change the MariaDB-Galera Service to the "primary" to avoid Deadlocks
Fix previous SDNC patch (https://gerrit.onap.org/r/c/oom/+/135308) and
temporary disable MariaDB for SDNR, as it is not compatible to
MariaDB 11

Issue-ID: OOM-3236

Change-Id: Ie63fcc9c6d5fa802d38c592b449e7ff8553c2ab9
Signed-off-by: Andreas Geissler <andreas-geissler@telekom.de>
diff --git a/kubernetes/sdnc/components/dmaap-listener/templates/deployment.yaml b/kubernetes/sdnc/components/dmaap-listener/templates/deployment.yaml
index 411dc01..03c5463 100644
--- a/kubernetes/sdnc/components/dmaap-listener/templates/deployment.yaml
+++ b/kubernetes/sdnc/components/dmaap-listener/templates/deployment.yaml
@@ -50,8 +50,8 @@
       - command:
         - /app/ready.py
         args:
-        - --container-name
-        - {{ include "common.mariadbService" . }}
+        - --app-name
+        - {{ include "common.mariadbAppName" . }}
         - --container-name
         - {{ .Values.config.sdncChartName }}
         - --container-name
diff --git a/kubernetes/sdnc/components/dmaap-listener/values.yaml b/kubernetes/sdnc/components/dmaap-listener/values.yaml
index 5741972..db15a7a 100644
--- a/kubernetes/sdnc/components/dmaap-listener/values.yaml
+++ b/kubernetes/sdnc/components/dmaap-listener/values.yaml
@@ -21,7 +21,7 @@
     #This flag allows SO to instantiate its own mariadb-galera cluster
     #If shared instance is used, this chart assumes that DB already exists
     localCluster: false
-    service: mariadb-galera
+    service: mariadb-galera-primary
     internalPort: 3306
     nameOverride: mariadb-galera
 
diff --git a/kubernetes/sdnc/components/sdnc-ansible-server/values.yaml b/kubernetes/sdnc/components/sdnc-ansible-server/values.yaml
index 4a48b64..cb778ae 100644
--- a/kubernetes/sdnc/components/sdnc-ansible-server/values.yaml
+++ b/kubernetes/sdnc/components/sdnc-ansible-server/values.yaml
@@ -21,7 +21,7 @@
     #This flag allows SO to instantiate its own mariadb-galera cluster
     #If shared instance is used, this chart assumes that DB already exists
     localCluster: false
-    service: mariadb-galera
+    service: mariadb-galera-primary
     internalPort: 3306
     nameOverride: mariadb-galera
 
diff --git a/kubernetes/sdnc/components/ueb-listener/templates/deployment.yaml b/kubernetes/sdnc/components/ueb-listener/templates/deployment.yaml
index 9956e06..0ca1601 100644
--- a/kubernetes/sdnc/components/ueb-listener/templates/deployment.yaml
+++ b/kubernetes/sdnc/components/ueb-listener/templates/deployment.yaml
@@ -53,8 +53,8 @@
       - command:
         - /app/ready.py
         args:
-        - --container-name
-        - {{ include "common.mariadbService" . }}
+        - --app-name
+        - {{ include "common.mariadbAppName" . }}
         - --container-name
         - {{ .Values.config.sdncChartName }}
         - --container-name
diff --git a/kubernetes/sdnc/components/ueb-listener/values.yaml b/kubernetes/sdnc/components/ueb-listener/values.yaml
index df559e9..83d0e78 100644
--- a/kubernetes/sdnc/components/ueb-listener/values.yaml
+++ b/kubernetes/sdnc/components/ueb-listener/values.yaml
@@ -21,7 +21,7 @@
     #This flag allows SO to instantiate its own mariadb-galera cluster
     #If shared instance is used, this chart assumes that DB already exists
     localCluster: false
-    service: mariadb-galera
+    service: mariadb-galera-primary
     internalPort: 3306
     nameOverride: mariadb-galera
 
diff --git a/kubernetes/sdnc/templates/job.yaml b/kubernetes/sdnc/templates/job.yaml
index e1d24b1..afe0e72 100755
--- a/kubernetes/sdnc/templates/job.yaml
+++ b/kubernetes/sdnc/templates/job.yaml
@@ -80,8 +80,8 @@
         command:
         - /app/ready.py
         args:
-        - --container-name
-        - {{ include "common.mariadbService" . }}
+        - --app-name
+        - {{ include "common.mariadbAppName" . }}
         env:
         - name: NAMESPACE
           valueFrom:
diff --git a/kubernetes/sdnc/templates/sdnrdb-init-job.yaml b/kubernetes/sdnc/templates/sdnrdb-init-job.yaml
index 4b2f773..e42757e 100755
--- a/kubernetes/sdnc/templates/sdnrdb-init-job.yaml
+++ b/kubernetes/sdnc/templates/sdnrdb-init-job.yaml
@@ -28,9 +28,9 @@
         - /app/ready.py
         args:
         {{- if .Values.config.sdnr.mariadb.enabled }}
-        - --container-name
-        - {{ include "common.mariadbService" . }}
-        {{- else -}}
+        - --app-name
+        - {{ include "common.mariadbAppName" . }}
+        {{- else }}
         - --container-name
         - {{.Values.elasticsearch.nameOverride}}-elasticsearch
         - --container-name
@@ -56,7 +56,7 @@
           - |
             {{- if .Values.config.sdnr.mariadb.enabled }}
             "{{ .Values.config.binDir }}/createSdnrDb.sh";
-            {{- end -}}
+            {{- end }}
             sleep 90; "{{ .Values.config.binDir }}/startODL.sh"
         env:
           - name: SDNC_AAF_ENABLED
@@ -85,12 +85,12 @@
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "login") | indent 12 }}
           - name: SDNRDBPASSWORD
             {{- include "common.secret.envFromSecretFast" (dict "global" . "uid" "sdnrdb-secret" "key" "password") | indent 12 }}
-        {{- else -}}
+          {{- else }}
           - name: SDNRDBURL
             value: "http://{{ .Values.elasticsearch.service.name | default "sdnrdb"}}.{{.Release.Namespace}}:{{.Values.elasticsearch.service.port | default "9200"}}"
           - name: SDNRDBPARAMETER
             value: "-k"
-        {{- end }}
+          {{- end }}
         {{- if .Values.config.sdnr.mariadb.enabled }}
         volumeMounts:
           - mountPath: {{ .Values.config.binDir }}/createSdnrDb.sh
@@ -140,5 +140,4 @@
       restartPolicy: Never
       imagePullSecrets:
       - name: "{{ include "common.namespace" . }}-docker-registry-key"
-
 {{ end -}}
diff --git a/kubernetes/sdnc/templates/statefulset.yaml b/kubernetes/sdnc/templates/statefulset.yaml
index 20f82e0..4607b62 100644
--- a/kubernetes/sdnc/templates/statefulset.yaml
+++ b/kubernetes/sdnc/templates/statefulset.yaml
@@ -138,8 +138,8 @@
         - /app/ready.py
         args:
         {{ if .Values.dgbuilder.enabled -}}
-        - --container-name
-        - {{ include "common.mariadbService" . }}
+        - --app-name
+        - {{ include "common.mariadbAppName" . }}
         - --job-name
         - {{ include "common.fullname" . }}-dbinit-job
         {{ end -}}
@@ -313,7 +313,7 @@
             value: {{ .Values.config.sdnr.mariadb.asyncHandling | default "false" | quote }}
           - name: SDNR_ASYNC_POOLSIZE
             value: {{ .Values.config.sdnr.mariadb.asyncPoolSize | default 200 | quote }}
-          {{- else -}}
+          {{- else }}
           - name: SDNRDBURL
             value: "http://{{ .Values.elasticsearch.service.name | default "sdnrdb"}}.{{.Release.Namespace}}:{{.Values.elasticsearch.service.port | default "9200"}}"
           {{- if .Values.config.sdnr.sdnrdbTrustAllCerts }}
diff --git a/kubernetes/sdnc/values.yaml b/kubernetes/sdnc/values.yaml
index e35dfde..2c6abdd 100644
--- a/kubernetes/sdnc/values.yaml
+++ b/kubernetes/sdnc/values.yaml
@@ -27,9 +27,9 @@
     #This flag allows SO to instantiate its own mariadb-galera cluster
     #If shared instance is used, this chart assumes that DB already exists
     localCluster: false
-    service: mariadb-galera
+    service: &mariadbService mariadb-galera-primary
     internalPort: 3306
-    nameOverride: mariadb-galera
+    nameOverride: &mariadbName mariadb-galera
 
 
 #################################################################
@@ -323,12 +323,12 @@
     sdnrdbTrustAllCerts: true
     elasticsearch:
     ## for legacy eleasticsearch database
-    # enabled: &esdbenabled true
-      enabled: &esdbenabled false
+      enabled: &esdbenabled true
+      # enabled: &esdbenabled false
     mariadb:
       ## for legacy eleasticsearch database
-      # enabled: false
-      enabled: true
+      enabled: false
+      # enabled: true
       databaseName: sdnrdb
       user: sdnrdb
       externalSecret: *sdnrdbSecretName
@@ -425,6 +425,9 @@
     mountSubPath: sdnc/mariadb-galera
     enabled: true
   replicaCount: 1
+  mariadbOperator:
+    galera:
+      enabled: false
   serviceAccount:
     nameOverride: *sdnc-db
 
@@ -485,8 +488,8 @@
           (include "common.mariadb.secret.rootPassSecretName"
             (dict "dot" . "chartName" "mariadb-galera")) }}'
       userCredentialsExternalSecret: *dbSecretName
-    dbPodName: mariadb-galera
-    dbServiceName: mariadb-galera
+    dbPodName: *mariadbName
+    dbServiceName: *mariadbService
     # This should be revisited and changed to plain text
     dgUserPassword: cc03e747a6afbbcbf8be7668acfebee5
   serviceAccount: