[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/common/mariadb-galera/templates/backup/cronjob.yaml b/kubernetes/common/mariadb-galera/templates/backup/cronjob.yaml
index e2a9ca6..4548626 100644
--- a/kubernetes/common/mariadb-galera/templates/backup/cronjob.yaml
+++ b/kubernetes/common/mariadb-galera/templates/backup/cronjob.yaml
@@ -15,6 +15,9 @@
 # limitations under the License.
 */}}
 
+{{- if and .Values.backup.enabled .Values.global.mariadbGalera.useOperator }}
+{{ include "common.mariadbOpBackup" . }}
+{{ else }}
 {{- if and .Values.backup.enabled .Values.persistence.enabled }}
 apiVersion: batch/v1beta1
 kind: CronJob
@@ -180,3 +183,4 @@
             - name: tmp
               emptyDir: {}
 {{- end }}
+{{- end }}
diff --git a/kubernetes/common/mariadb-galera/templates/backup/pv.yaml b/kubernetes/common/mariadb-galera/templates/backup/pv.yaml
index 30eb74b..d5e2610 100644
--- a/kubernetes/common/mariadb-galera/templates/backup/pv.yaml
+++ b/kubernetes/common/mariadb-galera/templates/backup/pv.yaml
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 */}}
+
+{{- if not .Values.global.mariadbGalera.useOperator }}
 {{- if .Values.backup.enabled }}
 {{- if and .Values.backup.persistence.enabled (not .Values.backup.persistence.existingClaim) -}}
 {{- if eq "True" (include "common.needPV" .) -}}
@@ -41,3 +43,4 @@
 {{- end -}}
 {{- end -}}
 {{- end -}}
+{{- end -}}
diff --git a/kubernetes/common/mariadb-galera/templates/backup/pvc.yaml b/kubernetes/common/mariadb-galera/templates/backup/pvc.yaml
index 5dd8a3f..4c2bfcd 100644
--- a/kubernetes/common/mariadb-galera/templates/backup/pvc.yaml
+++ b/kubernetes/common/mariadb-galera/templates/backup/pvc.yaml
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 */}}
+
+{{- if not .Values.global.mariadbGalera.useOperator }}
 {{- if .Values.backup.enabled }}
 {{- if and .Values.persistence.enabled (not .Values.persistence.existingClaim) }}
 ---
@@ -45,3 +47,4 @@
 {{- end -}}
 {{- end -}}
 {{- end -}}
+{{- end -}}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/configmap.yaml b/kubernetes/common/mariadb-galera/templates/configmap.yaml
index c95a234..0aa0a63 100644
--- a/kubernetes/common/mariadb-galera/templates/configmap.yaml
+++ b/kubernetes/common/mariadb-galera/templates/configmap.yaml
@@ -15,7 +15,20 @@
 # limitations under the License.
 */}}
 
-{{ if .Values.mariadbConfiguration }}
+{{- if .Values.global.mariadbGalera.useOperator }}
+{{    if .Values.mariadbOpConfiguration }}
+apiVersion: v1
+kind: ConfigMap
+metadata:
+  name: {{ printf "%s-configuration" (include "common.fullname" .) }}
+  namespace: {{ include "common.namespace" . }}
+  labels: {{- include "common.labels" . | nindent 4 }}
+data:
+  my.cnf: |
+{{ .Values.mariadbOpConfiguration | indent 4 }}
+{{-   end }}
+{{- else }}
+{{    if .Values.mariadbConfiguration }}
 apiVersion: v1
 kind: ConfigMap
 metadata:
@@ -25,4 +38,5 @@
 data:
   my.cnf: |
 {{ .Values.mariadbConfiguration | indent 4 }}
+{{-   end }}
 {{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/mariadb.yaml b/kubernetes/common/mariadb-galera/templates/mariadb.yaml
new file mode 100644
index 0000000..ce09c9f
--- /dev/null
+++ b/kubernetes/common/mariadb-galera/templates/mariadb.yaml
@@ -0,0 +1,19 @@
+{{/*
+# Copyright © 2023 Deutsche Telekom AG
+#
+# 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.
+*/}}
+
+{{- if .Values.global.mariadbGalera.useOperator }}
+{{ include "common.mariadbOpInstance" . }}
+{{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/metrics-svc.yaml b/kubernetes/common/mariadb-galera/templates/metrics-svc.yaml
index 841aab3..d37aeb1 100644
--- a/kubernetes/common/mariadb-galera/templates/metrics-svc.yaml
+++ b/kubernetes/common/mariadb-galera/templates/metrics-svc.yaml
@@ -14,7 +14,9 @@
 # limitations under the License.
 */}}
 
-{{- if default false .Values.global.metrics.enabled }}
+{{- if not .Values.global.mariadbGalera.useOperator }}
+{{-   if default false .Values.global.metrics.enabled }}
+---
 apiVersion: v1
 kind: Service
 metadata:
@@ -31,4 +33,5 @@
       port: {{ .Values.metrics.service.port }}
       targetPort: tcp-metrics
   selector: {{- include "common.matchLabels" . | nindent 4 }}
-{{- end }}
+{{-   end }}
+{{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/pdb.yaml b/kubernetes/common/mariadb-galera/templates/pdb.yaml
index 1d9d414..734f03f 100644
--- a/kubernetes/common/mariadb-galera/templates/pdb.yaml
+++ b/kubernetes/common/mariadb-galera/templates/pdb.yaml
@@ -14,17 +14,19 @@
 # limitations under the License.
 */}}
 
-{{- if .Values.podDisruptionBudget.create }}
+{{- if not .Values.global.mariadbGalera.useOperator }}
+{{-   if .Values.podDisruptionBudget.create }}
 apiVersion: policy/v1
 kind: PodDisruptionBudget
 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
 spec:
-{{- if .Values.podDisruptionBudget.minAvailable }}
+{{-     if .Values.podDisruptionBudget.minAvailable }}
   minAvailable: {{ .Values.podDisruptionBudget.minAvailable }}
-{{- end }}
-{{- if .Values.podDisruptionBudget.maxUnavailable }}
+{{-     end }}
+{{-     if .Values.podDisruptionBudget.maxUnavailable }}
   maxUnavailable: {{ .Values.podDisruptionBudget.maxUnavailable }}
-{{- end }}
+{{-     end }}
   selector:
     matchLabels: {{- include "common.matchLabels" . | nindent 6 }}
-{{- end }}
+{{-   end }}
+{{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/pv.yaml b/kubernetes/common/mariadb-galera/templates/pv.yaml
index 54a02cf..129b5b2 100644
--- a/kubernetes/common/mariadb-galera/templates/pv.yaml
+++ b/kubernetes/common/mariadb-galera/templates/pv.yaml
@@ -15,4 +15,6 @@
 # limitations under the License.
 */}}
 
+{{- if not .Values.global.mariadbGalera.useOperator }}
 {{ include "common.replicaPV" . }}
+{{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/service.yaml b/kubernetes/common/mariadb-galera/templates/service.yaml
index 6af9135..4cabde1 100644
--- a/kubernetes/common/mariadb-galera/templates/service.yaml
+++ b/kubernetes/common/mariadb-galera/templates/service.yaml
@@ -15,11 +15,13 @@
 # limitations under the License.
 */}}
 
+{{- if not .Values.global.mariadbGalera.useOperator }}
 {{ include "common.service" . }}
 ---
 {{ include "common.headlessService" . }}
+{{- end }}
 {{- if (include "common.onServiceMesh" .) }}
-{{- if eq (default "istio" .Values.global.serviceMesh.engine) "istio" }}
+{{-   if eq (default "istio" .Values.global.serviceMesh.engine) "istio" }}
 ---
 apiVersion: security.istio.io/v1beta1
 kind: PeerAuthentication
@@ -29,9 +31,9 @@
 spec:
   selector:
     matchLabels:
-      app.kubernetes.io/name: {{ include "common.servicename" . }}
+      app: {{ include "common.servicename" . }}
   portLevelMtls:
     '{{ .Values.service.internalPort }}':
       mode: DISABLE
-{{- end}}
-{{- end}}
+{{-   end }}
+{{- end }}
diff --git a/kubernetes/common/mariadb-galera/templates/servicemonitor.yaml b/kubernetes/common/mariadb-galera/templates/servicemonitor.yaml
index 6d1ed40..4cbf7b3 100644
--- a/kubernetes/common/mariadb-galera/templates/servicemonitor.yaml
+++ b/kubernetes/common/mariadb-galera/templates/servicemonitor.yaml
@@ -14,6 +14,8 @@
 # limitations under the License.
 */}}
 
-{{- if .Values.metrics.serviceMonitor.enabled }}
+{{- if not .Values.global.mariadbGalera.useOperator }}
+{{-   if .Values.metrics.serviceMonitor.enabled }}
 {{  include "common.serviceMonitor" . }}
-{{- end }}
+{{-   end }}
+{{- end }}
\ No newline at end of file
diff --git a/kubernetes/common/mariadb-galera/templates/statefulset.yaml b/kubernetes/common/mariadb-galera/templates/statefulset.yaml
index c95b572..2f5b33f 100644
--- a/kubernetes/common/mariadb-galera/templates/statefulset.yaml
+++ b/kubernetes/common/mariadb-galera/templates/statefulset.yaml
@@ -18,6 +18,7 @@
 # limitations under the License.
 */}}
 
+{{- if not .Values.global.mariadbGalera.useOperator }}
 apiVersion: apps/v1
 kind: StatefulSet
 metadata: {{- include "common.resourceMetadata" . | nindent 2 }}
@@ -266,3 +267,4 @@
   volumeClaimTemplates:
     - {{ include "common.PVCTemplate" (dict "dot" . "suffix" "data" "persistenceInfos" .Values.persistence) | indent 6 | trim }}
 {{- end }}
+{{- end }}
\ No newline at end of file