Skip to content

Commit

Permalink
chore: backups for service-directory
Browse files Browse the repository at this point in the history
  • Loading branch information
f-stibane committed Jul 2, 2021
1 parent f3c5df1 commit 516725e
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 8 deletions.
8 changes: 8 additions & 0 deletions infrastructure/iris-gateway/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ If release name contains chart name it will be used as a full name.
{{ include "iris-gateway.fullname" . }}-service-directory
{{- end }}

{{- define "iris-gateway.service-directory-backup" -}}
{{ include "iris-gateway.fullname" . }}-service-directory-backup
{{- end }}

{{- define "iris-gateway.public-proxy" -}}
{{ include "iris-gateway.fullname" . }}-public-proxy
{{- end }}
Expand Down Expand Up @@ -67,6 +71,10 @@ app.kubernetes.io/name: {{ include "iris-gateway.locations-postgres-backup" . }}
app.kubernetes.io/name: {{ include "iris-gateway.service-directory" . }}
{{- end }}

{{- define "iris-gateway.service-directory-backup-labels" -}}
app.kubernetes.io/name: {{ include "iris-gateway.service-directory-backup" . }}
{{- end }}

{{- define "iris-gateway.public-proxy-labels" -}}
app.kubernetes.io/name: {{ include "iris-gateway.public-proxy" . }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ data:
--column-inserts \
{{ .Values.postgres.dbName }} > "${DEST}/{{ .Values.postgres.dbName }}.sql"
echo 'backup succeeded'
set -x
ls -l "${DEST}/{{ .Values.postgres.dbName }}.sql"
find "${DEST}" -type f -exec ls -lh {} \;
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ data:
settings.yml: |
public:
name: {{ (index .Values.serviceNames .Values.environment).publicProxy }}
database_file: {{ .Values.publicProxy.persistentStoragePath }}/public-proxy-announcements.db
database_file: {{ .Values.publicProxy.storageDir }}/public-proxy-announcements.db
tls_bind_address: 0.0.0.0:{{ .Values.nodePorts.publicProxyTls }}
internal_bind_address: 0.0.0.0:{{ .Values.nodePorts.publicProxyInternal }}
internal_endpoint: {{ .Values.environment }}.iris-gateway.de:{{ .Values.nodePorts.publicProxyInternal }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ spec:
- mountPath: /config
name: config
readOnly: true
- mountPath: {{ .Values.publicProxy.persistentStoragePath }}
- mountPath: {{ .Values.publicProxy.storageDir }}
name: persistent-storage
env:
- name: PROXY_SETTINGS
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "iris-gateway.service-directory-backup" . }}
data:
backup.sh: |
#!/usr/bin/env bash
set -euo pipefail
SRC="{{ .Values.serviceDirectory.storageDir }}"
DIR=$(date +%d-%m-%y)
DEST="{{ .Values.serviceDirectory.backupDir }}/${DIR}"
mkdir -p "${DEST}"
echo 'backup starting'
cp -R "${SRC}" "${DEST}"
echo 'backup succeeded'
find "${DEST}" -type f -exec ls -lh {} \;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: {{ include "iris-gateway.service-directory-backup" . }}
labels:
{{- include "iris-gateway.service-directory-backup-labels" . | nindent 4 }}
spec:
schedule: '@midnight'
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 10
jobTemplate:
spec:
template:
metadata:
labels:
{{- include "iris-gateway.service-directory-backup-labels" . | nindent 12 }}
annotations:
checksum/scripts: {{ include (print $.Template.BasePath "/service-directory-backup/configmap.yaml") . | sha256sum }}
spec:
restartPolicy: OnFailure
containers:
- name: ubuntu
image: ubuntu
imagePullPolicy: {{ include "iris-gateway.pullPolicy" . }}
command: [ /scripts/backup.sh ]
volumeMounts:
- mountPath: {{ .Values.serviceDirectory.storageDir }}
name: backup-from
- mountPath: {{ .Values.serviceDirectory.backupDir }}
name: backup-to
- mountPath: /scripts
name: scripts
readOnly: true
volumes:
- name: backup-from
persistentVolumeClaim:
claimName: {{ include "iris-gateway.service-directory" . }}
- name: backup-to
persistentVolumeClaim:
claimName: {{ include "iris-gateway.service-directory-backup" . }}
- name: scripts
configMap:
name: {{ include "iris-gateway.service-directory-backup" . }}
defaultMode: 0755
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ include "iris-gateway.service-directory-backup" . }}
labels:
{{- include "iris-gateway.service-directory-backup-labels" . | nindent 4 }}
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
volumeName: service-directory-backups
resources:
requests:
storage: 1Gi

# kubectl -n iris-gateway create job --from cronjob/iris-gateway-service-directory-backup sd-backup
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data:
certificate_file: "{{ .Values.tls.mountPath }}/{{ (index .Values.serviceNames .Values.environment).serviceDirectory }}.crt"
key_file: "{{ .Values.tls.mountPath }}/{{ (index .Values.serviceNames .Values.environment).serviceDirectory }}.key"
directory:
database_file: {{ .Values.serviceDirectory.persistentStoragePath }}/service-directory.records
database_file: {{ .Values.serviceDirectory.storageDir }}/service-directory.records
ca_intermediate_certificate_files:
{{- range (index .Values.tls.intermediateCertificates .Values.environment) }}
- "{{ $.Values.tls.mountPath }}/{{ . }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:
- mountPath: /config
name: config
readOnly: true
- mountPath: {{ .Values.serviceDirectory.persistentStoragePath }}
- mountPath: {{ .Values.serviceDirectory.storageDir }}
name: persistent-storage
env:
- name: SD_SETTINGS
Expand Down
5 changes: 3 additions & 2 deletions infrastructure/iris-gateway/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ postgres:
dbName: locations

serviceDirectory:
storageDir: /storage
backupDir: /backups
image: inoeg/sd
configMountPath: /config
persistentStoragePath: /storage

publicProxy:
storageDir: /storage
jsonRpcPort: 6655
image: inoeg/proxy
configMountPath: /config
persistentStoragePath: /storage

publicProxyEps:
jsonRpcPort: 5544
Expand Down

0 comments on commit 516725e

Please sign in to comment.