blob: 8ab2d1bc12491021be28c17137e04f19ddd2a0bf [file] [log] [blame]
gio07eb1082024-10-25 14:35:56 +04001{{- /*
2Copyright Broadcom, Inc. All Rights Reserved.
3SPDX-License-Identifier: APACHE-2.0
4*/}}
5
6{{- if .Values.backup.enabled }}
7apiVersion: batch/v1
8kind: CronJob
9metadata:
10 name: {{ include "mongodb.fullname" . }}-mongodump
11 namespace: {{ include "mongodb.namespace" . | quote }}
12 labels: {{- include "common.labels.standard" . | nindent 4 }}
13 app.kubernetes.io/component: mongodump
14 {{- if .Values.backup.cronjob.labels }}
15 {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.labels "context" $) | nindent 4 }}
16 {{- end }}
17 {{- if .Values.commonLabels }}
18 {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
19 {{- end }}
20 {{- if or .Values.backup.cronjob.annotations .Values.commonAnnotations }}
21 annotations:
22 {{- if .Values.backup.cronjob.annotations }}
23 {{- include "common.tplvalues.render" ( dict "value" .Values.backup.cronjob.annotations "context" $) | nindent 4 }}
24 {{- end }}
25 {{- if .Values.commonAnnotations }}
26 {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
27 {{- end }}
28 {{- end }}
29spec:
30 schedule: {{ quote .Values.backup.cronjob.schedule }}
31 concurrencyPolicy: {{ .Values.backup.cronjob.concurrencyPolicy }}
32 failedJobsHistoryLimit: {{ .Values.backup.cronjob.failedJobsHistoryLimit }}
33 successfulJobsHistoryLimit: {{ .Values.backup.cronjob.successfulJobsHistoryLimit }}
34 {{- if .Values.backup.cronjob.startingDeadlineSeconds }}
35 startingDeadlineSeconds: {{ .Values.backup.cronjob.startingDeadlineSeconds }}
36 {{- end }}
37 jobTemplate:
38 spec:
39 {{- if .Values.backup.cronjob.backoffLimit }}
40 backoffLimit: {{ .Values.backup.cronjob.backoffLimit }}
41 {{- end }}
42 {{- if .Values.backup.cronjob.ttlSecondsAfterFinished }}
43 ttlSecondsAfterFinished: {{ .Values.backup.cronjob.ttlSecondsAfterFinished }}
44 {{- end }}
45 template:
46 metadata:
47 labels: {{- include "common.labels.standard" . | nindent 12 }}
48 app.kubernetes.io/component: mongodump
49 {{- if .Values.backup.cronjob.labels }}
50 {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.labels "context" $) | nindent 12 }}
51 {{- end }}
52 {{- if .Values.commonLabels }}
53 {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 12 }}
54 {{- end }}
55 {{- if or .Values.backup.cronjob.annotations .Values.commonAnnotations }}
56 annotations:
57 {{- if .Values.backup.cronjob.annotations }}
58 {{- include "common.tplvalues.render" ( dict "value" .Values.backup.cronjob.annotations "context" $) | nindent 12 }}
59 {{- end }}
60 {{- if .Values.commonAnnotations }}
61 {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 12 }}
62 {{- end }}
63 {{- end }}
64 spec:
65 {{- include "mongodb.imagePullSecrets" . | nindent 10 }}
66 {{- if .Values.podSecurityContext.enabled }}
67 securityContext: {{- include "common.compatibility.renderSecurityContext" (dict "secContext" .Values.podSecurityContext "context" $) | nindent 12 }}
68 {{- end }}
69 enableServiceLinks: {{ .Values.enableServiceLinks }}
70 {{- if .Values.tls.enabled }}
71 initContainers:
72 - name: generate-tls-certs
73 image: {{ include "mongodb.tls.image" . }}
74 imagePullPolicy: {{ .Values.tls.image.pullPolicy | quote }}
75 env:
76 - name: MY_POD_NAMESPACE
77 valueFrom:
78 fieldRef:
79 fieldPath: metadata.namespace
80 - name: MY_POD_HOST_IP
81 valueFrom:
82 fieldRef:
83 fieldPath: status.hostIP
84 volumeMounts:
85 - name: empty-dir
86 mountPath: /tmp
87 subPath: tmp-dir
88 {{- if (include "mongodb.autoGenerateCerts" .) }}
89 - name: certs-volume
90 mountPath: /certs/CAs
91 {{- else }}
92 - name: mongodb-certs-0
93 mountPath: /certs-0
94 {{- end }}
95 - name: certs
96 mountPath: /certs
97 - name: common-scripts
98 mountPath: /bitnami/scripts
99 command:
100 - /bitnami/scripts/generate-certs.sh
101 args:
102 - -s {{ include "mongodb.service.nameOverride" . }}
103 {{- if .Values.externalAccess.service.loadBalancerIPs }}
104 - -i {{ join "," .Values.externalAccess.service.loadBalancerIPs }}
105 {{- end }}
106 {{- if or .Values.tls.extraDnsNames .Values.externalAccess.service.publicNames }}
107 - -n {{ join "," ( concat .Values.tls.extraDnsNames .Values.externalAccess.service.publicNames ) }}
108 {{- end }}
109 {{- if .Values.tls.resources }}
110 resources: {{- include "common.tplvalues.render" (dict "value" .Values.tls.resources "context" $) | nindent 12 }}
111 {{- else if ne .Values.tls.resourcesPreset "none" }}
112 resources: {{- include "common.resources.preset" (dict "type" .Values.tls.resourcesPreset) | nindent 16 }}
113 {{- end }}
114 {{- end }}
115 containers:
116 - name: {{ include "mongodb.fullname" . }}-mongodump
117 image: {{ include "mongodb.image" . }}
118 imagePullPolicy: {{ .Values.image.pullPolicy | quote }}
119 env:
120 {{- if .Values.auth.enabled }}
121 - name: MONGODB_ROOT_USER
122 value: {{ .Values.auth.rootUser | quote }}
123 - name: MONGODB_ROOT_PASSWORD
124 valueFrom:
125 secretKeyRef:
126 name: {{ include "mongodb.secretName" . }}
127 key: mongodb-root-password
128 {{- end }}
129 - name: MONGODB_SERVICE_NAME
130 value: {{ include "mongodb.service.nameOverride" . }}
131 - name: MONGODB_PORT_NUMBER
132 value: {{ .Values.containerPorts.mongodb | quote }}
133 - name: MONGODUMP_DIR
134 value: {{ .Values.backup.cronjob.storage.mountPath }}
135 {{- if .Values.tls.enabled }}
136 - name: MONGODB_CLIENT_EXTRA_FLAGS
137 value: --ssl --sslPEMKeyFile=/certs/mongodb.pem --sslCAFile=/certs/mongodb-ca-cert
138 {{- end }}
139 {{- if .Values.backup.cronjob.command }}
140 command: {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.command "context" $) | nindent 14 }}
141 {{- else }}
142 command:
143 - /bin/sh
144 - -c
145 - "mongodump {{- if .Values.auth.enabled }} --username=${MONGODB_ROOT_USER} --password=${MONGODB_ROOT_PASSWORD} --authenticationDatabase=admin {{- end }} --host=${MONGODB_SERVICE_NAME} --port=${MONGODB_PORT_NUMBER} ${MONGODB_CLIENT_EXTRA_FLAGS} {{- if (eq $.Values.architecture "replicaset") }}--oplog{{- end }} --gzip --archive=${MONGODUMP_DIR}/mongodump-$(date '+%Y-%m-%d-%H-%M').gz"
146 {{- end }}
147 {{- if .Values.backup.cronjob.resources }}
148 resources: {{- include "common.tplvalues.render" (dict "value" .Values.backup.cronjob.resources "context" $) | nindent 14 }}
149 {{- else if ne .Values.backup.cronjob.resourcesPreset "none" }}
150 resources: {{- include "common.resources.preset" (dict "type" .Values.backup.cronjob.resourcesPreset) | nindent 14 }}
151 {{- end }}
152 volumeMounts:
153 - name: empty-dir
154 mountPath: /tmp
155 subPath: tmp-dir
156 {{- if .Values.tls.enabled }}
157 - name: certs
158 mountPath: /certs
159 {{- if (include "mongodb.autoGenerateCerts" .) }}
160 - name: certs-volume
161 mountPath: /certs/CAs
162 {{- else }}
163 - name: mongodb-certs-0
164 mountPath: /certs-0
165 {{- end }}
166 {{- end }}
167 - name: datadir
168 mountPath: {{ .Values.backup.cronjob.storage.mountPath }}
169 subPath: {{ .Values.backup.cronjob.storage.subPath }}
170 {{- if .Values.backup.cronjob.containerSecurityContext.enabled }}
171 securityContext:
172 {{- include "common.tplvalues.render" ( dict "value" ( omit .Values.backup.cronjob.containerSecurityContext "enabled" ) "context" $) | nindent 14 }}
173 {{- end }}
174 restartPolicy: {{ .Values.backup.cronjob.restartPolicy }}
175 volumes:
176 - name: empty-dir
177 emptyDir: {}
178 - name: common-scripts
179 configMap:
180 name: {{ printf "%s-common-scripts" (include "mongodb.fullname" .) }}
181 defaultMode: 0550
182 {{- if .Values.tls.enabled }}
183 - name: certs
184 emptyDir: {}
185 {{- if (include "mongodb.autoGenerateCerts" .) }}
186 - name: certs-volume
187 secret:
188 secretName: {{ template "mongodb.tlsSecretName" . }}
189 items:
190 - key: mongodb-ca-cert
191 path: mongodb-ca-cert
192 mode: 0600
193 - key: mongodb-ca-key
194 path: mongodb-ca-key
195 mode: 0600
196 {{- else }}
197 - name: mongodb-certs-0
198 secret:
199 secretName: {{ include "common.tplvalues.render" ( dict "value" .Values.tls.standalone.existingSecret "context" $) }}
200 defaultMode: 256
201 {{- end }}
202 {{- end }}
203 {{- if .Values.backup.cronjob.storage.existingClaim }}
204 - name: datadir
205 persistentVolumeClaim:
206 claimName: {{ printf "%s" (tpl .Values.backup.cronjob.storage.existingClaim .) }}
207 {{- else }}
208 - name: datadir
209 persistentVolumeClaim:
210 claimName: {{ include "mongodb.fullname" . }}-mongodump
211 {{- end }}
212{{- end }}