Skip to content

Commit 0aff3be

Browse files
Jonathan S. Katzjkatz
Jonathan S. Katz
authored andcommitted
Add support for backups to GCS via Helm chart
This adds both a quickstart for backing up to GCS as well as use of GCS in a multi-repository setup.
1 parent d1ba873 commit 0aff3be

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

Diff for: helm/postgres/templates/_gcs.tpl

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{{/* Allow for GCS secret information to be stored in a Secret */}}
2+
{{- define "postgres.gcs" }}
3+
[global]
4+
{{- if .gcs }}
5+
repo{{ add .index 1 }}-gcs-key=/etc/pgbackrest/conf.d/gcs-key.json
6+
{{- end }}
7+
{{ end }}

Diff for: helm/postgres/templates/pgbackrest-secret.yaml

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{{- if or .Values.multiBackupRepos .Values.s3 }}
1+
{{- if or .Values.multiBackupRepos .Values.s3 .Values.gcs }}
22
apiVersion: v1
33
kind: Secret
44
metadata:
@@ -11,11 +11,23 @@ data:
1111
{{- $args := dict "s3" $repo.s3 "index" $index }}
1212
s3.conf: |-
1313
{{ include "postgres.s3" $args | b64enc }}
14+
{{- else if $repo.gcs }}
15+
{{- $args := dict "gcs" $repo.gcs "index" $index }}
16+
gcs.conf: |-
17+
{{ include "postgres.gcs" $args | b64enc }}
18+
gcs-key.json: |-
19+
{{ $repo.gcs.key | b64enc }}
1420
{{- end }}
1521
{{- end }}
1622
{{- else if .Values.s3 }}
1723
{{- $args := dict "s3" .Values.s3 "index" 0 }}
1824
s3.conf: |-
1925
{{ include "postgres.s3" $args | b64enc }}
26+
{{- else if .Values.gcs }}
27+
{{- $args := dict "gcs" .Values.gcs "index" 0 }}
28+
gcs.conf: |-
29+
{{ include "postgres.gcs" $args | b64enc }}
30+
gcs-key.json: |-
31+
{{ .Values.gcs.key | b64enc }}
2032
{{- end }}
2133
{{- end }}

Diff for: helm/postgres/templates/postgres.yaml

+14-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ spec:
4646
name: {{ default .Release.Name .Values.name }}-pgbackrest-secret
4747
global:
4848
{{- range $index, $repo := .Values.multiBackupRepos }}
49-
{{- if $repo.s3 }}
49+
{{- if or $repo.s3 $repo.gcs }}
5050
repo{{ add $index 1 }}-path: /pgbackrest/{{ $.Release.Namespace }}/{{ default $.Release.Name $.Values.name }}/repo{{ add $index 1 }}
5151
{{- end }}
5252
{{- end }}
@@ -66,6 +66,9 @@ spec:
6666
bucket: {{ $repo.s3.bucket | quote }}
6767
endpoint: {{ $repo.s3.endpoint | quote }}
6868
region: {{ $repo.s3.region | quote }}
69+
{{- else if $repo.gcs }}
70+
gcs:
71+
bucket: {{ $repo.gcs.bucket | quote }}
6972
{{- end }}
7073
{{- end }}
7174
{{- else if .Values.s3 }}
@@ -83,6 +86,16 @@ spec:
8386
bucket: {{ .Values.s3.bucket | quote }}
8487
endpoint: {{ .Values.s3.endpoint | quote }}
8588
region: {{ .Values.s3.region | quote }}
89+
{{- else if .Values.gcs }}
90+
configuration:
91+
- secret:
92+
name: {{ default .Release.Name .Values.name }}-pgbackrest-secret
93+
global:
94+
repo1-path: /pgbackrest/{{ .Release.Namespace }}/{{ default .Release.Name .Values.name }}/repo1
95+
repos:
96+
- name: repo1
97+
gcs:
98+
bucket: {{ .Values.gcs.bucket | quote }}
8699
{{- else }}
87100
repos:
88101
- name: repo1

Diff for: helm/postgres/values.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,17 @@
189189
# # built-in encrpytion system.
190190
# encryptionPassphrase: ""
191191

192+
# gcs allows for Google Cloud Storage (GCS) to be used for backups. This allows
193+
# for a quick setup with GCS; if you need a more advanced setup, use
194+
# "pgBackRestConfig".
195+
# gcs:
196+
# # bucket is the name of the GCS bucket that the backups will be stored in.
197+
# bucket: ""
198+
# # key is a multi-line string that contains the GCS key, which is a JSON
199+
# # structure.
200+
# key: |
201+
# {}
202+
192203
# multiBackupRepos allows for backing up to multiple repositories. This is
193204
# effectively uses the "quickstarts" for each of the backup types (volume, s3,
194205
# gcs, azure). You can have any permutation of these types. You can set up to 4.
@@ -209,6 +220,10 @@
209220
# region: ""
210221
# key: ""
211222
# keySecret: ""
223+
# - gcs:
224+
# bucket: ""
225+
# key: |
226+
# {}
212227

213228
# pgBackRestConfig allows for the configuration of every pgBackRest option
214229
# except for "image", which is set by "pgBackRest".

0 commit comments

Comments
 (0)