diff options
author | Andreas Geissler <andreas-geissler@telekom.de> | 2023-08-16 17:18:49 +0200 |
---|---|---|
committer | Andreas Geissler <andreas-geissler@telekom.de> | 2023-09-29 13:42:29 +0200 |
commit | cfd8434fe9484b9219560159094b174421d6d6a2 (patch) | |
tree | 0825b2650bb861444f18444f0279479e4dcbf7c4 /kubernetes/common/common | |
parent | 533403925a6b60f4113c4d9e54cd99be36dc9cc5 (diff) |
[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>
Diffstat (limited to 'kubernetes/common/common')
-rw-r--r-- | kubernetes/common/common/Chart.yaml | 2 | ||||
-rw-r--r-- | kubernetes/common/common/templates/_cassOp.tpl | 20 | ||||
-rw-r--r-- | kubernetes/common/common/templates/_mariadb.tpl | 254 |
3 files changed, 274 insertions, 2 deletions
diff --git a/kubernetes/common/common/Chart.yaml b/kubernetes/common/common/Chart.yaml index e134fe8048..4025924f80 100644 --- a/kubernetes/common/common/Chart.yaml +++ b/kubernetes/common/common/Chart.yaml @@ -16,4 +16,4 @@ apiVersion: v2 description: Common templates for inclusion in other charts name: common -version: 13.0.1 +version: 13.0.2 diff --git a/kubernetes/common/common/templates/_cassOp.tpl b/kubernetes/common/common/templates/_cassOp.tpl index c360a0f626..d0f23877a4 100644 --- a/kubernetes/common/common/templates/_cassOp.tpl +++ b/kubernetes/common/common/templates/_cassOp.tpl @@ -1,3 +1,19 @@ +{{/* +# Copyright © 2022 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. +*/}} + {{/* Cassandra Data Center. */}} {{- define "common.k8ssandraCluster" -}} {{- $global := .Values.global }} @@ -10,7 +26,6 @@ spec: reaper: containerImage: registry: {{ include "repositoryGenerator.dockerHubRepository" . }} - heapSize: 512Mi autoScheduling: enabled: true stargate: @@ -67,5 +82,8 @@ spec: pods: annotations: {{ toYaml .Values.podAnnotations | nindent 10 }} + commonLabels: + app: {{ .Values.k8ssandraOperator.config.clusterName }} + version: {{ .Values.k8ssandraOperator.cassandraVersion }} {{- end }} {{ end }} diff --git a/kubernetes/common/common/templates/_mariadb.tpl b/kubernetes/common/common/templates/_mariadb.tpl index 5021c500b0..7e127e2437 100644 --- a/kubernetes/common/common/templates/_mariadb.tpl +++ b/kubernetes/common/common/templates/_mariadb.tpl @@ -59,6 +59,17 @@ {{- end -}} {{/* + Choose the name of the mariadb app label to use. +*/}} +{{- define "common.mariadbAppName" -}} + {{- if .Values.global.mariadbGalera.localCluster -}} + {{- index .Values "mariadb-galera" "nameOverride" -}} + {{- else -}} + {{- .Values.global.mariadbGalera.nameOverride -}} + {{- end -}} +{{- end -}} + +{{/* Choose the name of the mariadb service to use. */}} {{- define "common.mariadbService" -}} @@ -97,3 +108,246 @@ {{- define "common.mariadbSecretParam" -}} {{ printf "password" -}} {{- end -}} + +{{/* + Create MariDB Database via mariadb-operator +*/}} +{{- define "common.mariadbOpDatabase" -}} +{{- $dot := default . .dot -}} +{{- $dbname := (required "'dbame' param, is required." .dbname) -}} +{{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}} +--- +apiVersion: mariadb.mmontes.io/v1alpha1 +kind: Database +metadata: + name: {{ $dbname }} +spec: + mariaDbRef: + name: {{ $dbinst }} + characterSet: utf8 + collate: utf8_general_ci +{{- end -}} + +{{/* + Create MariaDB User via mariadb-operator +*/}} +{{- define "common.mariadbOpUser" -}} +{{- $dot := default . .dot -}} +{{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}} +{{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}} +{{- $dbsecret := (required "'dbsecret' param, is required." .dbsecret) -}} +--- +apiVersion: mariadb.mmontes.io/v1alpha1 +kind: User +metadata: + name: {{ $dbuser }} +spec: + # If you want the user to be created with a different name than the resource name + # name: user-custom + mariaDbRef: + name: {{ $dbinst }} + passwordSecretKeyRef: + name: {{ $dbsecret }} + key: password + # This field is immutable and defaults to 10 + maxUserConnections: 100 +{{- end -}} + +{{/* + Grant rights to a MariaDB User via mariadb-operator +*/}} +{{- define "common.mariadbOpGrants" -}} +{{- $dot := default . .dot -}} +{{- $dbuser := (required "'dbuser' param, is required." .dbuser) -}} +{{- $dbname := (required "'dbame' param, is required." .dbname) -}} +{{- $dbinst := (required "'dbinst' param, is required." .dbinst) -}} +--- +apiVersion: mariadb.mmontes.io/v1alpha1 +kind: Grant +metadata: + name: {{ $dbuser }}-{{ $dbname }}-{{ $dbinst }} +spec: + mariaDbRef: + name: {{ $dbinst }} + privileges: + - "ALL" + database: {{ $dbname }} + table: "*" + username: {{ $dbuser }} + grantOption: true +{{- end -}} + +{{/* + MariaDB Backup via mariadb-operator +*/}} +{{- define "common.mariadbOpBackup" -}} +{{- $dot := default . .dot -}} +{{- $dbinst := include "common.name" $dot -}} +kind: Backup +metadata: + name: backup-scheduled +spec: + mariaDbRef: + name: {{ $dbinst }} + schedule: + cron: "*/1 * * * *" + suspend: false + maxRetentionDays: 30 + storage: + persistentVolumeClaim: + resources: + requests: + storage: 100Mi + {{- if .Values.mariadbOperator.storageClassName }} + storageClassName: {{ .Values.mariadbOperator.storageClassName }} + {{- end }} + accessModes: + - ReadWriteOnce + resources: + requests: + cpu: 100m + memory: 128Mi + limits: + cpu: 300m + memory: 512Mi +{{- end -}} + +{{/* + Create a MariaDB instance via mariadb-operator +*/}} +{{- define "common.mariadbOpInstance" -}} +{{- $dot := default . .dot -}} +{{- $global := $dot.Values.global -}} +{{- $dbinst := include "common.name" $dot -}} +{{- $dbrootsecret := tpl (default (include "common.mariadb.secret.rootPassSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.rootUser.externalSecret) $dot -}} +{{- $dbusersecret := tpl (default (include "common.mariadb.secret.userCredentialsSecretName" (dict "dot" $dot "chartName" "")) $dot.Values.db.externalSecret) $dot -}} +--- +apiVersion: mariadb.mmontes.io/v1alpha1 +kind: MariaDB +metadata: + name: {{ $dbinst }} +spec: + podSecurityContext: + runAsUser: 10001 + runAsGroup: 10001 + fsGroup: 10001 + inheritMetadata: + {{ if .Values.podAnnotations -}} + annotations: {{ toYaml .Values.podAnnotations | nindent 6 }} + {{- end }} + labels: + app: {{ $dbinst }} + version: {{ .Values.mariadbOperator.appVersion }} + rootPasswordSecretKeyRef: + name: {{ $dbrootsecret }} + key: password + image: + repository: {{ include "repositoryGenerator.dockerHubRepository" . }}/{{ .Values.mariadbOperator.image }} + tag: {{ $dot.Values.mariadbOperator.appVersion }} + pullPolicy: IfNotPresent + imagePullSecrets: + - name: {{ include "common.namespace" . }}-docker-registry-key + port: 3306 + replicas: {{ $dot.Values.replicaCount }} + galera: + {{- if eq (int $dot.Values.replicaCount) 1 }} + enabled: false + {{- else }} + enabled: {{ $dot.Values.mariadbOperator.galera.enabled }} + {{- end }} + sst: mariabackup + replicaThreads: 1 + agent: + image: + repository: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ .Values.mariadbOperator.galera.agentImage }} + tag: {{ $dot.Values.mariadbOperator.galera.agentVersion }} + pullPolicy: IfNotPresent + port: 5555 + kubernetesAuth: + enabled: true + authDelegatorRoleName: {{ $dbinst }}-auth + gracefulShutdownTimeout: 5s + recovery: + enabled: true + clusterHealthyTimeout: 5m + clusterBootstrapTimeout: 10m + podRecoveryTimeout: 5m + podSyncTimeout: 10m + initContainer: + image: + repository: {{ include "repositoryGenerator.githubContainerRegistry" . }}/{{ $dot.Values.mariadbOperator.galera.initImage }} + tag: {{ $dot.Values.mariadbOperator.galera.initVersion }} + pullPolicy: IfNotPresent + volumeClaimTemplate: + resources: + requests: + storage: 50Mi + accessModes: + - ReadWriteOnce + livenessProbe: + exec: + command: + - bash + - '-c' + - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;" + initialDelaySeconds: 20 + periodSeconds: 10 + timeoutSeconds: 5 + readinessProbe: + exec: + command: + - bash + - '-c' + - mariadb -u root -p"${MARIADB_ROOT_PASSWORD}" -e "SELECT 1;" + initialDelaySeconds: 20 + periodSeconds: 10 + timeoutSeconds: 5 + affinity: + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - topologyKey: kubernetes.io/hostname + tolerations: + - key: mariadb.mmontes.io/ha + operator: Exists + effect: NoSchedule + podDisruptionBudget: + maxUnavailable: 50% + updateStrategy: + type: RollingUpdate + #myCnf: | + # [mysqld] + # bind-address=0.0.0.0 + # default_storage_engine=InnoDB + # binlog_format=row + # innodb_autoinc_lock_mode=2 + # max_allowed_packet=256M + # lower_case_table_names = 1 + + # ## Character set + # collation_server=utf8_unicode_ci + # init_connect='SET NAMES utf8' + # character_set_server=utf8 + + myCnfConfigMapKeyRef: + key: my.cnf + name: {{ printf "%s-configuration" (include "common.fullname" $dot) }} + resources: {{ include "common.resources" . | nindent 4 }} + volumeClaimTemplate: + {{- if $dot.Values.mariadbOperator.storageClassName }} + storageClassName: {{ $dot.Values.k8ssandraOperator.persistence.storageClassName }} + {{- end }} + resources: + requests: + storage: {{ $dot.Values.persistence.size | quote }} + accessModes: + - ReadWriteOnce +{{- if $dot.Values.db.user }} +{{ include "common.mariadbOpUser" (dict "dot" . "dbuser" $dot.Values.db.user "dbinst" $dbinst "dbsecret" $dbusersecret) }} +{{- end }} +{{- if $dot.Values.db.name }} +{{ include "common.mariadbOpDatabase" (dict "dot" . "dbname" $dot.Values.db.name "dbinst" $dbinst) }} +{{- end }} +{{- if and $dot.Values.db.user $dot.Values.db.name }} +{{ include "common.mariadbOpGrants" (dict "dot" . "dbuser" $dot.Values.db.user "dbname" $dot.Values.db.name "dbinst" $dbinst) }} +{{- end }} +{{- end -}} |