123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- {{- if eq .Values.architecture "replication" }}
- apiVersion: {{ include "common.capabilities.statefulset.apiVersion" . }}
- kind: StatefulSet
- metadata:
- name: {{ include "mysql.secondary.fullname" . }}
- namespace: {{ include "common.names.namespace" . | quote }}
- labels: {{- include "common.labels.standard" . | nindent 4 }}
- app.kubernetes.io/component: secondary
- {{- if .Values.commonLabels }}
- {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
- {{- end }}
- {{- if .Values.commonAnnotations }}
- annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
- {{- end }}
- spec:
- replicas: {{ .Values.secondary.replicaCount }}
- podManagementPolicy: {{ .Values.secondary.podManagementPolicy | quote }}
- selector:
- matchLabels: {{ include "common.labels.matchLabels" . | nindent 6 }}
- app.kubernetes.io/component: secondary
- serviceName: {{ include "mysql.secondary.fullname" . }}
- {{- if .Values.secondary.updateStrategy }}
- updateStrategy: {{- toYaml .Values.secondary.updateStrategy | nindent 4 }}
- {{- end }}
- template:
- metadata:
- annotations:
- {{- if (include "mysql.secondary.createConfigmap" .) }}
- checksum/configuration: {{ include (print $.Template.BasePath "/secondary/configmap.yaml") . | sha256sum }}
- {{- end }}
- {{- if .Values.secondary.podAnnotations }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.podAnnotations "context" $) | nindent 8 }}
- {{- end }}
- labels: {{- include "common.labels.standard" . | nindent 8 }}
- app.kubernetes.io/component: secondary
- {{- if .Values.secondary.podLabels }}
- {{- include "common.tplvalues.render" ( dict "value" .Values.secondary.podLabels "context" $ ) | nindent 8 }}
- {{- end }}
- spec:
- serviceAccountName: {{ include "mysql.serviceAccountName" . }}
- {{- include "mysql.imagePullSecrets" . | nindent 6 }}
- {{- if .Values.secondary.hostAliases }}
- hostAliases: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.hostAliases "context" $) | nindent 8 }}
- {{- end }}
- {{- if .Values.secondary.affinity }}
- affinity: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.affinity "context" $) | nindent 8 }}
- {{- else }}
- affinity:
- podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.secondary.podAffinityPreset "context" $) | nindent 10 }}
- podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.secondary.podAntiAffinityPreset "context" $) | nindent 10 }}
- nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.secondary.nodeAffinityPreset.type "key" .Values.secondary.nodeAffinityPreset.key "values" .Values.secondary.nodeAffinityPreset.values) | nindent 10 }}
- {{- end }}
- {{- if .Values.secondary.nodeSelector }}
- nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.nodeSelector "context" $) | nindent 8 }}
- {{- end }}
- {{- if .Values.secondary.tolerations }}
- tolerations: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.tolerations "context" $) | nindent 8 }}
- {{- end }}
- {{- if .Values.secondary.priorityClassName }}
- priorityClassName: {{ .Values.secondary.priorityClassName | quote }}
- {{- end }}
- {{- if .Values.secondary.runtimeClassName }}
- runtimeClassName: {{ .Values.secondary.runtimeClassName | quote }}
- {{- end }}
- {{- if .Values.secondary.schedulerName }}
- schedulerName: {{ .Values.secondary.schedulerName | quote }}
- {{- end }}
- {{- if .Values.secondary.topologySpreadConstraints }}
- topologySpreadConstraints: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.topologySpreadConstraints "context" .) | nindent 8 }}
- {{- end }}
- {{- if .Values.secondary.podSecurityContext.enabled }}
- securityContext: {{- omit .Values.secondary.podSecurityContext "enabled" | toYaml | nindent 8 }}
- {{- end }}
- {{- if .Values.secondary.terminationGracePeriodSeconds }}
- terminationGracePeriodSeconds: {{ .Values.secondary.terminationGracePeriodSeconds }}
- {{- end }}
- initContainers:
- {{- if and .Values.secondary.podSecurityContext.enabled .Values.volumePermissions.enabled .Values.secondary.persistence.enabled }}
- - name: volume-permissions
- image: {{ include "mysql.volumePermissions.image" . }}
- imagePullPolicy: {{ .Values.volumePermissions.image.pullPolicy | quote }}
- command:
- - /bin/bash
- - -ec
- - |
- mkdir -p "/bitnami/mysql"
- chown "{{ .Values.secondary.containerSecurityContext.runAsUser }}:{{ .Values.secondary.podSecurityContext.fsGroup }}" "/bitnami/mysql"
- find "/bitnami/mysql" -mindepth 1 -maxdepth 1 -not -name ".snapshot" -not -name "lost+found" | xargs -r chown -R "{{ .Values.secondary.containerSecurityContext.runAsUser }}:{{ .Values.secondary.podSecurityContext.fsGroup }}"
- securityContext:
- runAsUser: 0
- {{- if .Values.volumePermissions.resources }}
- resources: {{- toYaml .Values.volumePermissions.resources | nindent 12 }}
- {{- end }}
- volumeMounts:
- - name: data
- mountPath: /bitnami/mysql
- {{- if .Values.secondary.persistence.subPath }}
- subPath: {{ .Values.secondary.persistence.subPath }}
- {{- end }}
- {{- end }}
- {{- if .Values.secondary.initContainers }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.initContainers "context" $) | nindent 8 }}
- {{- end }}
- containers:
- - name: mysql
- image: {{ include "mysql.image" . }}
- imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
- {{- if .Values.secondary.containerSecurityContext.enabled }}
- securityContext: {{- omit .Values.secondary.containerSecurityContext "enabled" | toYaml | nindent 12 }}
- {{- end }}
- {{- if .Values.diagnosticMode.enabled }}
- command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
- {{- else if .Values.secondary.command }}
- command: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.command "context" $) | nindent 12 }}
- {{- end }}
- {{- if .Values.diagnosticMode.enabled }}
- args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
- {{- else if .Values.secondary.args }}
- args: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.args "context" $) | nindent 12 }}
- {{- end }}
- {{- if .Values.secondary.lifecycleHooks }}
- lifecycle: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.lifecycleHooks "context" $) | nindent 12 }}
- {{- end }}
- env:
- - name: BITNAMI_DEBUG
- value: {{ ternary "true" "false" (or .Values.image.debug .Values.diagnosticMode.enabled) | quote }}
- - name: MYSQL_REPLICATION_MODE
- value: "slave"
- - name: MYSQL_MASTER_HOST
- value: {{ include "mysql.primary.fullname" . }}
- - name: MYSQL_MASTER_PORT_NUMBER
- value: {{ .Values.primary.service.ports.mysql | quote }}
- - name: MYSQL_MASTER_ROOT_USER
- value: "root"
- - name: MYSQL_REPLICATION_USER
- value: {{ .Values.auth.replicationUser | quote }}
- {{- if .Values.auth.usePasswordFiles }}
- - name: MYSQL_MASTER_ROOT_PASSWORD_FILE
- value: {{ default "/opt/bitnami/mysql/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
- - name: MYSQL_REPLICATION_PASSWORD_FILE
- value: {{ default "/opt/bitnami/mysql/secrets/mysql-replication-password" .Values.auth.customPasswordFiles.replicator }}
- {{- else }}
- - name: MYSQL_MASTER_ROOT_PASSWORD
- valueFrom:
- secretKeyRef:
- name: {{ template "mysql.secretName" . }}
- key: mysql-root-password
- - name: MYSQL_REPLICATION_PASSWORD
- valueFrom:
- secretKeyRef:
- name: {{ template "mysql.secretName" . }}
- key: mysql-replication-password
- {{- end }}
- {{- if .Values.secondary.extraFlags }}
- - name: MYSQL_EXTRA_FLAGS
- value: "{{ .Values.secondary.extraFlags }}"
- {{- end }}
- {{- if .Values.secondary.extraEnvVars }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVars "context" $) | nindent 12 }}
- {{- end }}
- envFrom:
- {{- if .Values.secondary.extraEnvVarsCM }}
- - configMapRef:
- name: {{ include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVarsCM "context" $) }}
- {{- end }}
- {{- if .Values.secondary.extraEnvVarsSecret }}
- - secretRef:
- name: {{ include "common.tplvalues.render" (dict "value" .Values.secondary.extraEnvVarsSecret "context" $) }}
- {{- end }}
- ports:
- - name: mysql
- containerPort: 3306
- {{- if .Values.secondary.extraPorts }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraPorts "context" $) | nindent 12 }}
- {{- end }}
- {{- if not .Values.diagnosticMode.enabled }}
- {{- if .Values.secondary.customLivenessProbe }}
- livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customLivenessProbe "context" $) | nindent 12 }}
- {{- else if .Values.secondary.livenessProbe.enabled }}
- livenessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.livenessProbe "enabled") "context" $) | nindent 12 }}
- exec:
- command:
- - /bin/bash
- - -ec
- - |
- password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
- if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
- password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
- fi
- mysqladmin status -uroot -p"${password_aux}"
- {{- end }}
- {{- if .Values.secondary.customReadinessProbe }}
- readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customReadinessProbe "context" $) | nindent 12 }}
- {{- else if .Values.secondary.readinessProbe.enabled }}
- readinessProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.readinessProbe "enabled") "context" $) | nindent 12 }}
- exec:
- command:
- - /bin/bash
- - -ec
- - |
- password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
- if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
- password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
- fi
- mysqladmin status -uroot -p"${password_aux}"
- {{- end }}
- {{- if .Values.secondary.customStartupProbe }}
- startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.customStartupProbe "context" $) | nindent 12 }}
- {{- else if .Values.secondary.startupProbe.enabled }}
- startupProbe: {{- include "common.tplvalues.render" (dict "value" (omit .Values.secondary.startupProbe "enabled") "context" $) | nindent 12 }}
- exec:
- command:
- - /bin/bash
- - -ec
- - |
- password_aux="${MYSQL_MASTER_ROOT_PASSWORD:-}"
- if [[ -f "${MYSQL_MASTER_ROOT_PASSWORD_FILE:-}" ]]; then
- password_aux=$(cat "$MYSQL_MASTER_ROOT_PASSWORD_FILE")
- fi
- mysqladmin status -uroot -p"${password_aux}"
- {{- end }}
- {{- end }}
- {{- if .Values.secondary.resources }}
- resources: {{ toYaml .Values.secondary.resources | nindent 12 }}
- {{- end }}
- volumeMounts:
- - name: data
- mountPath: /bitnami/mysql
- {{- if .Values.secondary.persistence.subPath }}
- subPath: {{ .Values.secondary.persistence.subPath }}
- {{- end }}
- {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
- - name: custom-init-scripts
- mountPath: /docker-entrypoint-initdb.d
- {{- end }}
- {{- if or .Values.secondary.configuration .Values.secondary.existingConfigmap }}
- - name: config
- mountPath: /opt/bitnami/mysql/conf/my.cnf
- subPath: my.cnf
- {{- end }}
- {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
- - name: mysql-credentials
- mountPath: /opt/bitnami/mysql/secrets/
- {{- end }}
- {{- if .Values.secondary.extraVolumeMounts }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraVolumeMounts "context" $) | nindent 12 }}
- {{- end }}
- {{- if .Values.metrics.enabled }}
- - name: metrics
- image: {{ include "mysql.metrics.image" . }}
- imagePullPolicy: {{ .Values.metrics.image.pullPolicy | quote }}
- {{- if .Values.metrics.containerSecurityContext.enabled }}
- securityContext: {{- omit .Values.metrics.containerSecurityContext "enabled" | toYaml | nindent 12 }}
- {{- end }}
- env:
- {{- if .Values.auth.usePasswordFiles }}
- - name: MYSQL_ROOT_PASSWORD_FILE
- value: {{ default "/opt/bitnami/mysqld-exporter/secrets/mysql-root-password" .Values.auth.customPasswordFiles.root }}
- {{- else }}
- - name: MYSQL_ROOT_PASSWORD
- valueFrom:
- secretKeyRef:
- name: {{ template "mysql.secretName" . }}
- key: mysql-root-password
- {{- end }}
- {{- if .Values.diagnosticMode.enabled }}
- command: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.command "context" $) | nindent 12 }}
- args: {{- include "common.tplvalues.render" (dict "value" .Values.diagnosticMode.args "context" $) | nindent 12 }}
- {{- else }}
- command:
- - /bin/bash
- - -ec
- - |
- password_aux="${MYSQL_ROOT_PASSWORD:-}"
- if [[ -f "${MYSQL_ROOT_PASSWORD_FILE:-}" ]]; then
- password_aux=$(cat "$MYSQL_ROOT_PASSWORD_FILE")
- fi
- DATA_SOURCE_NAME="root:${password_aux}@(localhost:3306)/" /bin/mysqld_exporter {{- range .Values.metrics.extraArgs.secondary }} {{ . }} {{- end }}
- {{- end }}
- ports:
- - name: metrics
- containerPort: 9104
- {{- if not .Values.diagnosticMode.enabled }}
- {{- if .Values.metrics.livenessProbe.enabled }}
- livenessProbe: {{- omit .Values.metrics.livenessProbe "enabled" | toYaml | nindent 12 }}
- httpGet:
- path: /metrics
- port: metrics
- {{- end }}
- {{- if .Values.metrics.readinessProbe.enabled }}
- readinessProbe: {{- omit .Values.metrics.readinessProbe "enabled" | toYaml | nindent 12 }}
- httpGet:
- path: /metrics
- port: metrics
- {{- end }}
- {{- end }}
- {{- if .Values.metrics.resources }}
- resources: {{- toYaml .Values.metrics.resources | nindent 12 }}
- {{- end }}
- {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
- volumeMounts:
- - name: mysql-credentials
- mountPath: /opt/bitnami/mysqld-exporter/secrets/
- {{- end }}
- {{- end }}
- {{- if .Values.secondary.sidecars }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.sidecars "context" $) | nindent 8 }}
- {{- end }}
- volumes:
- {{- if or .Values.initdbScriptsConfigMap .Values.initdbScripts }}
- - name: custom-init-scripts
- configMap:
- name: {{ include "mysql.initdbScriptsCM" . }}
- {{- end }}
- {{- if or .Values.secondary.configuration .Values.secondary.existingConfigmap }}
- - name: config
- configMap:
- name: {{ include "mysql.secondary.configmapName" . }}
- {{- end }}
- {{- if and .Values.auth.usePasswordFiles (not .Values.auth.customPasswordFiles) }}
- - name: mysql-credentials
- secret:
- secretName: {{ template "mysql.secretName" . }}
- items:
- - key: mysql-root-password
- path: mysql-root-password
- - key: mysql-replication-password
- path: mysql-replication-password
- {{- end }}
- {{- if .Values.secondary.extraVolumes }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.extraVolumes "context" $) | nindent 8 }}
- {{- end }}
- {{- if and .Values.secondary.persistence.enabled .Values.secondary.persistence.existingClaim }}
- - name: data
- persistentVolumeClaim:
- claimName: {{ tpl .Values.secondary.persistence.existingClaim . }}
- {{- else if not .Values.secondary.persistence.enabled }}
- - name: data
- emptyDir: {}
- {{- else }}
- volumeClaimTemplates:
- - metadata:
- name: data
- labels: {{ include "common.labels.matchLabels" . | nindent 10 }}
- app.kubernetes.io/component: secondary
- {{- if .Values.commonLabels }}
- {{- include "common.tplvalues.render" (dict "value" .Values.commonLabels "context" $) | nindent 10 }}
- {{- end }}
- annotations:
- {{- if .Values.secondary.persistence.annotations }}
- {{- include "common.tplvalues.render" (dict "value" .Values.secondary.persistence.annotations "context" $) | nindent 10 }}
- {{- end }}
- {{- if .Values.commonAnnotations }}
- {{- include "common.tplvalues.render" (dict "value" .Values.commonAnnotations "context" $) | nindent 10 }}
- {{- end }}
- spec:
- accessModes:
- {{- range .Values.secondary.persistence.accessModes }}
- - {{ . | quote }}
- {{- end }}
- resources:
- requests:
- storage: {{ .Values.secondary.persistence.size | quote }}
- {{- include "common.storage.class" (dict "persistence" .Values.secondary.persistence "global" .Values.global) | nindent 8 }}
- {{- if .Values.secondary.persistence.selector }}
- selector: {{- include "common.tplvalues.render" (dict "value" .Values.secondary.persistence.selector "context" $) | nindent 10 }}
- {{- end -}}
- {{- end }}
- {{- end }}
|