cronjob.yaml 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {{- /*
  2. Copyright VMware, Inc.
  3. SPDX-License-Identifier: APACHE-2.0
  4. */}}
  5. {{- if .Values.backup.enabled }}
  6. {{- $customUser := include "postgresql.v1.username" . }}
  7. apiVersion: batch/v1
  8. kind: CronJob
  9. metadata:
  10. name: {{ include "postgresql.v1.primary.fullname" . }}-pgdumpall
  11. namespace: {{ .Release.Namespace | quote }}
  12. {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.backup.cronjob.labels .Values.commonLabels ) "context" . ) }}
  13. labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
  14. app.kubernetes.io/component: pg_dumpall
  15. {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.backup.cronjob.annotations .Values.commonAnnotations ) "context" . ) }}
  16. {{- if $annotations }}
  17. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  18. {{- end }}
  19. spec:
  20. schedule: {{ quote .Values.backup.cronjob.schedule }}
  21. {{- if .Values.backup.cronjob.timezone }}
  22. timeZone: {{ .Values.backup.cronjob.timezone | quote }}
  23. {{- end }}
  24. concurrencyPolicy: {{ .Values.backup.cronjob.concurrencyPolicy }}
  25. failedJobsHistoryLimit: {{ .Values.backup.cronjob.failedJobsHistoryLimit }}
  26. successfulJobsHistoryLimit: {{ .Values.backup.cronjob.successfulJobsHistoryLimit }}
  27. {{- if .Values.backup.cronjob.startingDeadlineSeconds }}
  28. startingDeadlineSeconds: {{ .Values.backup.cronjob.startingDeadlineSeconds }}
  29. {{- end }}
  30. jobTemplate:
  31. spec:
  32. {{- if .Values.backup.cronjob.ttlSecondsAfterFinished }}
  33. ttlSecondsAfterFinished: {{ .Values.backup.cronjob.ttlSecondsAfterFinished }}
  34. {{- end }}
  35. template:
  36. metadata:
  37. labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 12 }}
  38. app.kubernetes.io/component: pg_dumpall
  39. {{- if $annotations }}
  40. annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 12 }}
  41. {{- end }}
  42. spec:
  43. {{- include "postgresql.v1.imagePullSecrets" . | nindent 10 }}
  44. {{- if .Values.backup.cronjob.nodeSelector }}
  45. nodeSelector: {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.nodeSelector "context" $) | nindent 12 }}
  46. {{- end }}
  47. containers:
  48. - name: {{ include "postgresql.v1.primary.fullname" . }}-pgdumpall
  49. image: {{ include "postgresql.v1.image" . }}
  50. imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
  51. env:
  52. - name: PGUSER
  53. {{- if .Values.auth.enablePostgresUser }}
  54. value: postgres
  55. {{- else }}
  56. value: {{ $customUser | quote }}
  57. {{- end }}
  58. {{- if .Values.auth.usePasswordFiles }}
  59. - name: PGPASSFILE
  60. value: {{ printf "/opt/bitnami/postgresql/secrets/%s" (include "postgresql.v1.adminPasswordKey" .) }}
  61. {{- else }}
  62. - name: PGPASSWORD
  63. valueFrom:
  64. secretKeyRef:
  65. name: {{ include "postgresql.v1.secretName" . }}
  66. key: {{ include "postgresql.v1.adminPasswordKey" . }}
  67. {{- end }}
  68. - name: PGHOST
  69. value: {{ include "postgresql.v1.primary.fullname" . }}
  70. - name: PGPORT
  71. value: {{ include "postgresql.v1.service.port" . | quote }}
  72. - name: PGDUMP_DIR
  73. value: {{ .Values.backup.cronjob.storage.mountPath }}
  74. {{- if .Values.tls.enabled }}
  75. - name: PGSSLROOTCERT
  76. {{- if .Values.tls.autoGenerated }}
  77. value: /tmp/certs/ca.crt
  78. {{- else }}
  79. value: {{- printf "/tmp/certs/%s" .Values.tls.certCAFilename -}}
  80. {{- end }}
  81. {{- end }}
  82. command: {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.command "context" $) | nindent 14 }}
  83. volumeMounts:
  84. {{- if .Values.tls.enabled }}
  85. - name: certs
  86. mountPath: /certs
  87. {{- end }}
  88. - name: datadir
  89. mountPath: {{ .Values.backup.cronjob.storage.mountPath }}
  90. subPath: {{ .Values.backup.cronjob.storage.subPath }}
  91. {{- if .Values.backup.cronjob.containerSecurityContext.enabled }}
  92. securityContext: {{- omit .Values.backup.cronjob.containerSecurityContext "enabled" | toYaml | nindent 14 }}
  93. {{- end }}
  94. restartPolicy: {{ .Values.backup.cronjob.restartPolicy }}
  95. {{- if .Values.backup.cronjob.podSecurityContext.enabled }}
  96. securityContext:
  97. fsGroup: {{ .Values.backup.cronjob.podSecurityContext.fsGroup }}
  98. {{- end }}
  99. volumes:
  100. {{- if .Values.tls.enabled }}
  101. - name: raw-certificates
  102. emptyDir: /tmp/certs
  103. {{- end }}
  104. {{- if .Values.backup.cronjob.storage.existingClaim }}
  105. - name: datadir
  106. persistentVolumeClaim:
  107. claimName: {{ printf "%s" (tpl .Values.backup.cronjob.storage.existingClaim .) }}
  108. {{- else }}
  109. - name: datadir
  110. persistentVolumeClaim:
  111. claimName: {{ include "postgresql.v1.primary.fullname" . }}-pgdumpall
  112. {{- end }}
  113. {{- end }}