{{- /* Copyright VMware, Inc. SPDX-License-Identifier: APACHE-2.0 */}} {{- if .Values.backup.enabled }} {{- $customUser := include "postgresql.username" . }} apiVersion: batch/v1 kind: CronJob metadata: name: {{ include "postgresql.primary.fullname" . }}-pgdumpall namespace: {{ .Release.Namespace | quote }} labels: {{- include "common.labels.standard" . | nindent 4 }} app.kubernetes.io/component: pg_dumpall {{- if .Values.backup.cronjob.labels }} {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.labels "context" $) | nindent 4 }} {{- end }} {{- if .Values.commonLabels }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }} {{- end }} {{- if or .Values.backup.cronjob.annotations .Values.commonAnnotations }} annotations: {{- if .Values.backup.cronjob.annotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.backup.cronjob.annotations "context" $) | nindent 4 }} {{- end }} {{- if .Values.commonAnnotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }} {{- end }} {{- end }} spec: schedule: {{ quote .Values.backup.cronjob.schedule }} concurrencyPolicy: {{ .Values.backup.cronjob.concurrencyPolicy }} failedJobsHistoryLimit: {{ .Values.backup.cronjob.failedJobsHistoryLimit }} successfulJobsHistoryLimit: {{ .Values.backup.cronjob.successfulJobsHistoryLimit }} {{- if .Values.backup.cronjob.startingDeadlineSeconds }} startingDeadlineSeconds: {{ .Values.backup.cronjob.startingDeadlineSeconds }} {{- end }} jobTemplate: spec: {{- if .Values.backup.cronjob.ttlSecondsAfterFinished }} ttlSecondsAfterFinished: {{ .Values.backup.cronjob.ttlSecondsAfterFinished }} {{- end }} template: metadata: labels: {{- include "common.labels.standard" . | nindent 12 }} app.kubernetes.io/component: pg_dumpall {{- if .Values.backup.cronjob.labels }} {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.labels "context" $) | nindent 12 }} {{- end }} {{- if .Values.commonLabels }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 12 }} {{- end }} {{- if or .Values.annotations .Values.commonAnnotations }} annotations: {{- if .Values.backup.cronjob.annotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.backup.cronjob.annotations "context" $) | nindent 12 }} {{- end }} {{- if .Values.commonAnnotations }} {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 12 }} {{- end }} {{- end }} spec: containers: - name: {{ include "postgresql.primary.fullname" . }}-pgdumpall image: {{ include "postgresql.image" . }} env: - name: PGUSER {{- if .Values.auth.enablePostgresUser }} value: postgres {{- else }} value: {{ $customUser | quote }} {{- end }} {{- if .Values.auth.usePasswordFiles }} - name: PGPASSFILE value: {{ printf "/opt/bitnami/postgresql/secrets/%s" (include "postgresql.adminPasswordKey" .) }} {{- else }} - name: PGPASSWORD valueFrom: secretKeyRef: name: {{ include "postgresql.secretName" . }} key: {{ include "postgresql.adminPasswordKey" . }} {{- end }} - name: PGHOST value: {{ include "postgresql.primary.fullname" . }} - name: PGPORT value: {{ .Values.containerPorts.postgresql | quote }} - name: PGDUMP_DIR value: {{ .Values.backup.cronjob.storage.mountPath }} {{- if .Values.tls.enabled }} - name: PGSSLROOTCERT {{- if .Values.tls.autoGenerated -}} value: /tmp/certs/ca.crt {{- else }} value: {{- printf "/tmp/certs/%s" .Values.tls.certCAFilename -}} {{- end }} {{- end }} command: {{- range .Values.backup.cronjob.command }} - {{ . }} {{- end }} volumeMounts: {{- if .Values.tls.enabled }} - name: certs mountPath: /certs {{- end }} - name: datadir mountPath: {{ .Values.backup.cronjob.storage.mountPath }} subPath: {{ .Values.backup.cronjob.storage.subPath }} securityContext: {{- include "common.tplvalues.render" ( dict "value" .Values.backup.cronjob.containerSecurityContext "context" $) | nindent 14 }} restartPolicy: {{ .Values.backup.cronjob.restartPolicy }} volumes: {{- if .Values.tls.enabled }} - name: raw-certificates emptyDir: /tmp/certs {{- end }} {{- if .Values.backup.cronjob.storage.existingClaim }} - name: datadir persistentVolumeClaim: claimName: {{ printf "%s" (tpl .Values.backup.cronjob.storage.existingClaim .) }} {{- else }} - name: datadir persistentVolumeClaim: claimName: {{ include "postgresql.primary.fullname" . }}-pgdumpall {{- end }} {{- end }}