CHART NAME: {{ .Chart.Name }}
CHART VERSION: {{ .Chart.Version }}
APP VERSION: {{ .Chart.AppVersion }}

Did you know there are enterprise versions of the Bitnami catalog? For enhanced secure software supply chain features, unlimited pulls from Docker, LTS support, or application customization, see Bitnami Premium or Tanzu Application Catalog. See https://www.arrow.com/globalecs/na/vendors/bitnami for more information.

** Please be patient while the chart is being deployed **

{{- if .Values.diagnosticMode.enabled }}
The chart has been deployed in diagnostic mode. All probes have been disabled and the command has been overwritten with:

  command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 4 }}
  args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 4 }}

Get the list of pods by executing:

  kubectl get pods --namespace {{ include "common.names.namespace" . }} -l app.kubernetes.io/instance={{ .Release.Name }}

Access the pod you want to debug by executing

  kubectl exec --namespace {{ include "common.names.namespace" . }} -ti <NAME OF THE POD> -- bash

In order to replicate the container startup scripts execute this command:

    /opt/bitnami/scripts/mariadb-galera/entrypoint.sh /opt/bitnami/scripts/mariadb-galera/run.sh

{{- else }}
Tip:

  Watch the deployment status using the command:

    kubectl get sts -w --namespace {{ include "common.names.namespace" . }} -l app.kubernetes.io/instance={{ .Release.Name }}

MariaDB can be accessed via port "{{ .Values.service.ports.mysql }}" on the following DNS name from within your cluster:

    {{ template "common.names.fullname" . }}.{{ include "common.names.namespace" . }}.svc.{{ .Values.clusterDomain }}

To obtain the password for the MariaDB admin user run the following command:

    echo "$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d)"

To connect to your database run the following command:

    kubectl run {{ template "common.names.fullname" . }}-client --rm --tty -i --restart='Never' --namespace {{ include "common.names.namespace" . }} --image {{ template "mariadb-galera.image" . }} --command \
      -- mysql -h {{ template "common.names.fullname" . }} -P {{ .Values.service.ports.mysql }} -u{{ if .Values.db.user }}{{ .Values.db.user }}{{ else }}{{ .Values.rootUser.user }}{{ end }} -p{{ if .Values.db.user }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-password}" | base64 -d){{ else }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d){{ end }} {{ .Values.db.name }}

To connect to your database from outside the cluster execute the following commands:

{{- if contains "NodePort" .Values.service.type }}

    export NODE_IP=$(kubectl get nodes --namespace {{ include "common.names.namespace" . }} -o jsonpath="{.items[0].status.addresses[0].address}")
    export NODE_PORT=$(kubectl get --namespace {{ include "common.names.namespace" . }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "common.names.fullname" . }})
    mysql -h $NODE_IP -P $NODE_PORT -u{{ if .Values.db.user }}{{ .Values.db.user }}{{ else }}{{ .Values.rootUser.user }}{{ end }} -p{{ if .Values.db.user }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-password}" | base64 -d){{ else }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d){{ end }} {{ .Values.db.name }}

{{- else if contains "LoadBalancer" .Values.service.type }}

  NOTE: It may take a few minutes for the LoadBalancer IP to be available.
        Watch the status with: 'kubectl get svc --namespace {{ include "common.names.namespace" . }} -w {{ template "common.names.fullname" . }}'

    export SERVICE_IP=$(kubectl get svc --namespace {{ include "common.names.namespace" . }} {{ template "common.names.fullname" . }} --template "{{ "{{ range (index .status.loadBalancer.ingress 0) }}{{ . }}{{ end }}" }}")
    mysql -h $SERVICE_IP -P {{ .Values.service.ports.mysql }} -u{{ if .Values.db.user }}{{ .Values.db.user }}{{ else }}{{ .Values.rootUser.user }}{{ end }} -p{{ if .Values.db.user }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-password}" | base64 -d){{ else }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d){{ end }} {{ .Values.db.name }}

{{- else if contains "ClusterIP" .Values.service.type }}

    kubectl port-forward --namespace {{ include "common.names.namespace" . }} svc/{{ template "common.names.fullname" . }} {{ .Values.service.ports.mysql }}:{{ .Values.service.ports.mysql }} &
    mysql -h 127.0.0.1 -P {{ .Values.service.ports.mysql }} -u{{ if .Values.db.user }}{{ .Values.db.user }}{{ else }}{{ .Values.rootUser.user }}{{ end }} -p{{ if .Values.db.user }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-password}" | base64 -d){{ else }}$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d){{ end }} {{ .Values.db.name }}

{{- end }}

{{- if .Values.metrics.enabled }}

To access the MariaDB Prometheus metrics from outside the cluster execute the following commands:

    kubectl port-forward --namespace {{ include "common.names.namespace" . }} svc/{{ template "common.names.fullname" . }}-metrics {{ .Values.metrics.service.port }}:{{ .Values.metrics.service.port }} &
    curl 127.0.0.1:{{ .Values.metrics.service.port }}/metrics

{{- end }}

To upgrade this helm chart:

    helm upgrade --namespace {{ include "common.names.namespace" . }} {{ .Release.Name }} oci://registry-1.docker.io/bitnamicharts/mariadb-galera \
      --set rootUser.password=$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-root-password}" | base64 -d) \
      {{ if .Values.db.user }}--set db.user={{ .Values.db.user }} --set db.password=$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-password}" | base64 -d) {{ end }}--set db.name={{ .Values.db.name }} \
      --set galera.mariabackup.password=$(kubectl get secret --namespace {{ include "common.names.namespace" . }} {{ if .Values.existingSecret }}{{ .Values.existingSecret }}{{ else }}{{ template "common.names.fullname" . }}{{ end }} -o jsonpath="{.data.mariadb-galera-mariabackup-password}" | base64 -d)

{{- end }}

{{ include "mariadb-galera.validateValues" . }}
{{ include "mariadb-galera.checkRollingTags" . }}
{{- $requiredPasswords := list -}}
{{- $secretName := include "mariadb-galera.secretName" . -}}
{{- if not .Values.existingSecret -}}
  {{- $requiredRootPassword := dict "valueKey" "rootUser.password" "secret" $secretName "field" "mariadb-root-password" -}}
  {{- $requiredPasswords = append $requiredPasswords $requiredRootPassword -}}
  {{- $requiredMariaBackupPassword := dict "valueKey" "galera.mariabackup.password" "secret" $secretName "field" "mariadb-galera-mariabackup-password" -}}
  {{- $requiredPasswords = append $requiredPasswords $requiredMariaBackupPassword -}}
  {{- if .Values.db.user }}
    {{- $requiredUserPassword := dict "valueKey" "db.password" "secret" $secretName "field" "mariadb-password" -}}
    {{- $requiredPasswords = append $requiredPasswords $requiredUserPassword -}}
  {{- end -}}
{{- end -}}
{{- $requiredRedisPasswordErrors := include "common.validations.values.multiple.empty" (dict "required" $requiredPasswords "context" $) -}}
{{- include "common.errors.upgrade.passwords.empty" (dict "validationErrors" (list $requiredRedisPasswordErrors) "context" $) -}}
{{- include "common.warnings.resources" (dict "sections" (list "metrics" "") "context" $) }}
{{- include "common.warnings.modifiedImages" (dict "images" (list .Values.image .Values.metrics.image) "context" $) }}
{{- include "common.errors.insecureImages" (dict "images" (list .Values.image .Values.metrics.image) "context" $) }}
