-
Notifications
You must be signed in to change notification settings - Fork 40
/
cronjob-full.yaml
144 lines (138 loc) · 5.62 KB
/
cronjob-full.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
{{- /* Determine Backup is REST or GraphQL */}}
{{- define "backups.api_type" -}}
{{- $apiType := "graphql" -}}
{{- $safeVersion := include "dgraph.version" . -}}
{{- if semverCompare "< 20.03" $safeVersion -}}
{{- $apiType = "rest" -}}
{{- end -}}
{{- if .Values.backups.override_api_type -}}
{{- printf "%s" .Values.backups.override_api_type -}}
{{- else -}}
{{- printf "%s" $apiType -}}
{{- end -}}
{{- end -}}
{{- if .Values.backups.full.enabled -}}
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ template "dgraph.backups.fullname" . }}-full
namespace: {{ include "dgraph.namespace" . }}
labels:
app: {{ template "dgraph.name" . }}
chart: {{ template "dgraph.chart" . }}
component: {{ .Values.backups.name }}
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
spec:
schedule: "{{ .Values.backups.full.schedule }}"
jobTemplate:
metadata:
labels:
cronjob: {{ template "dgraph.backups.fullname" . }}-full
spec:
template:
metadata:
labels:
cronjob: {{ template "dgraph.backups.fullname" . }}-full
{{- if .Values.backups.podLabels }}
{{ .Values.backups.podLabels | toYaml | indent 12}}
{{- end }}
spec:
{{- if .Values.serviceAccount.create }}
serviceAccountName: {{ .Values.serviceAccount.name }}
{{- end }}
{{- if .Values.backups.schedulerName }}
schedulerName: {{ .Values.backups.schedulerName }}
{{- end }}
containers:
- name: {{ template "dgraph.backups.fullname" . }}-full
image: {{ template "dgraph.backups.image" . }}
imagePullPolicy: {{ .Values.backups.image.pullPolicy | quote }}
command:
- /usr/bin/bash
- "-c"
- |
{{- if .Values.backups.full.debug }}
set -ex
{{- else }}
set -e
{{- end }}
source /scripts/backup.sh
## Use Single Alpha in Cluster to avoid potential issues with concurrent backups
## ref. https://discuss.dgraph.io/t/concurrent-backups-can-lead-to-issues/9934/2
ALPHA_HOST="{{ template "dgraph.alpha.fullname" . }}-0.{{ template "dgraph.alpha.fullname" . }}-headless.${POD_NAMESPACE}.svc"
BACKUP_DESTINATION={{ .Values.backups.destination }}
SUBPATH={{ .Values.backups.subpath }}
API_TYPE={{ template "backups.api_type" . }}
MINIO_SECURE={{ .Values.backups.minioSecure }}
## Get Tokens
{{- if .Values.backups.admin.auth_token }}
AUTH_TOKEN=$(cat /backup_secrets/backup_auth_token)
{{- end }}
{{- if .Values.alpha.acl.enabled }}
ACCESS_TOKEN=$(get_token {{ .Values.backups.admin.user }} $(cat /backup_secrets/backup_admin_password) $AUTH_TOKEN )
{{- end }}
## Full Backup with optional access and auth tokens
FORCE_FULL=true backup "$ACCESS_TOKEN" "$AUTH_TOKEN"
volumeMounts:
- name: backup-config-volume
mountPath: /scripts
{{- if .Values.alpha.tls.enabled }}
- name: tls-volume
mountPath: /dgraph/tls
{{- end }}
{{- if .Values.alpha.acl.enabled }}
- name: backup-secret-volume
mountPath: /backup_secrets
{{- end }}
## Mount NFS Backup volume so that datestamp directories can be created
{{- if .Values.backups.nfs.enabled }}
- name: backups-nfs-volume
mountPath: {{ .Values.backups.nfs.mountPath }}
{{- end }}
## Mount Backup volume so that datestamp directories can be created
{{- if .Values.backups.volume.enabled }}
- name: backups-vol-volume
mountPath: {{ .Values.backups.volume.mountPath }}
{{- end }}
env:
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
{{- if .Values.alpha.tls.enabled }}
- name: CACERT_PATH
value: /dgraph/tls/ca.crt
{{- if .Values.backups.admin.tls_client }}
- name: CLIENT_CERT_PATH
value: /dgraph/tls/client.{{ .Values.backups.admin.tls_client }}.crt
- name: CLIENT_KEY_PATH
value: /dgraph/tls/client.{{ .Values.backups.admin.tls_client }}.key
{{- end }}
{{- end }}
restartPolicy: {{ .Values.backups.incremental.restartPolicy }}
volumes:
- name: backup-config-volume
configMap:
name: {{ template "dgraph.backups.fullname" . }}-config
{{- if .Values.alpha.tls.enabled }}
- name: tls-volume
secret:
secretName: {{ template "dgraph.alpha.fullname" . }}-tls-secret
{{- end }}
{{- if or (.Values.alpha.acl.enabled) (.Values.backups.admin.auth_token) }}
- name: backup-secret-volume
secret:
secretName: {{ template "dgraph.backups.fullname" . }}-secret
{{- end }}
{{- if .Values.backups.nfs.enabled }}
- name: backups-nfs-volume
persistentVolumeClaim:
claimName: {{ template "dgraph.backups.fullname" . }}-claim
{{- end }}
{{- if .Values.backups.volume.enabled }}
- name: backups-vol-volume
persistentVolumeClaim:
claimName: {{ .Values.backups.volume.claim }}
{{- end }}
{{- end }}