Skip to content

Commit 3118f67

Browse files
committed
feat(plugins): add pluging including backup logic for barman cloud plugin
Signed-off-by: Philipp Hamann <[email protected]>
1 parent 2f880f1 commit 3118f67

File tree

10 files changed

+93
-2
lines changed

10 files changed

+93
-2
lines changed

charts/cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentat
173173
| cluster.monitoring.podMonitor.relabelings | list | `[]` | The list of relabelings for the PodMonitor. Applied to samples before scraping. |
174174
| cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts |
175175
| cluster.monitoring.prometheusRule.excludeRules | list | `[]` | Exclude specified rules |
176+
| cluster.plugins | list | `[]` | The plugins configuration, containing any plugin to be loaded with the corresponding configuration |
176177
| cluster.postgresGID | int | `-1` | The GID of the postgres user inside the image, defaults to 26 |
177178
| cluster.postgresUID | int | `-1` | The UID of the postgres user inside the image, defaults to 26 |
178179
| cluster.postgresql.ldap | object | `{}` | PostgreSQL LDAP configuration (see https://cloudnative-pg.io/documentation/current/postgresql_conf/#ldap-configuration) |

charts/cluster/templates/_backup.tpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{{- if .Values.backups.enabled }}
33
backup:
44
target: "prefer-standby"
5+
{{ if (eq (include "cluster.useBarmanCloudPlugin" .) "false") }}
56
retentionPolicy: {{ .Values.backups.retentionPolicy }}
67
barmanObjectStore:
78
wal:
@@ -19,5 +20,6 @@ backup:
1920

2021
{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.backups "secretPrefix" "backup" }}
2122
{{- include "cluster.barmanObjectStoreConfig" $d | nindent 2 }}
23+
{{- end}}
2224
{{- end }}
2325
{{- end }}

charts/cluster/templates/_helpers.tpl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,19 @@ Postgres GID
144144
{{- 26 -}}
145145
{{- end -}}
146146
{{- end -}}
147+
148+
149+
{{/*
150+
Check if barman-cloud plugin exists and is enabled
151+
*/}}
152+
{{- define "cluster.useBarmanCloudPlugin" -}}
153+
{{- $hasPlugin := false }}
154+
{{- if .Values.cluster.plugins }}
155+
{{- range .Values.cluster.plugins }}
156+
{{- if and (eq .name "barman-cloud.cloudnative-pg.io") .enabled }}
157+
{{- $hasPlugin = true }}
158+
{{- end }}
159+
{{- end }}
160+
{{- end }}
161+
{{- $hasPlugin }}
162+
{{- end }}

charts/cluster/templates/cluster.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ spec:
6767
name: {{ . }}
6868
{{ end }}
6969
enablePDB: {{ .Values.cluster.enablePDB }}
70+
{{- with .Values.cluster.plugins }}
71+
plugins:
72+
{{- toYaml . | nindent 4}}
73+
{{- end }}
7074
postgresql:
7175
{{- if or (eq .Values.type "timescaledb") (not (empty .Values.cluster.postgresql.shared_preload_libraries)) }}
7276
shared_preload_libraries:
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{{ if and (eq (include "cluster.useBarmanCloudPlugin" .) "true") .Values.backups.enabled }}
2+
apiVersion: barmancloud.cnpg.io/v1
3+
kind: ObjectStore
4+
metadata:
5+
name: {{ include "cluster.fullname" $ }}-object-store
6+
spec:
7+
configuration:
8+
wal:
9+
compression: {{ .Values.backups.wal.compression }}
10+
{{- if .Values.backups.wal.encryption }}
11+
encryption: {{ .Values.backups.wal.encryption }}
12+
{{- end }}
13+
maxParallel: {{ .Values.backups.wal.maxParallel }}
14+
data:
15+
compression: {{ .Values.backups.data.compression }}
16+
{{- if .Values.backups.data.encryption }}
17+
encryption: {{ .Values.backups.data.encryption }}
18+
{{- end }}
19+
jobs: {{ .Values.backups.data.jobs }}
20+
{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.backups "secretPrefix" "backup" -}}
21+
{{- include "cluster.barmanObjectStoreConfig" $d | indent 2 }}
22+
{{- end }}

charts/cluster/templates/scheduled-backups.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,15 @@ metadata:
1111
spec:
1212
immediate: true
1313
schedule: {{ .schedule | quote }}
14-
method: {{ .method }}
1514
backupOwnerReference: {{ .backupOwnerReference }}
1615
cluster:
1716
name: {{ include "cluster.fullname" $context }}
17+
{{- if (eq (include "cluster.useBarmanCloudPlugin" $context ) "true") }}
18+
pluginConfiguration:
19+
name: barman-cloud.cloudnative-pg.io
20+
method: plugin
21+
{{ else }}
22+
method: {{ .method }}
23+
{{- end }}
1824
{{ end -}}
1925
{{ end }}

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster-assert.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,13 @@ spec:
101101
memory: 256Mi
102102
limits:
103103
cpu: 100m
104-
memory: 256Mi
104+
memory: 256Mi
105+
plugins:
106+
- name: cnpg-i-plugin-example.my-org.io
107+
enabled: true
108+
parameters:
109+
key1: value1
110+
key2: value2
105111
priorityClassName: mega-high
106112
primaryUpdateStrategy: supervised
107113
primaryUpdateMethod: restart

charts/cluster/test/postgresql-cluster-configuration/01-non_default_configuration_cluster.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ cluster:
8787
inRoles:
8888
- pg_monitor
8989
- pg_signal_backend
90+
plugins:
91+
- name: cnpg-i-plugin-example.my-org.io
92+
enabled: true
93+
parameters:
94+
key1: value1
95+
key2: value2
9096
postgresql:
9197
ldap:
9298
server: 'openldap.default.svc.cluster.local'

charts/cluster/values.schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,27 @@
262262
}
263263
}
264264
},
265+
"plugins": {
266+
"type": "array",
267+
"items": {
268+
"type": "object",
269+
"properties": {
270+
"name": {
271+
"type": "string"
272+
},
273+
"enabled": {
274+
"type": "boolean"
275+
},
276+
"isWALArchiver": {
277+
"type": "boolean"
278+
},
279+
"parameters": {
280+
"type": "object"
281+
}
282+
},
283+
"required": ["name"]
284+
}
285+
},
265286
"postgresGID": {
266287
"type": "integer"
267288
},

charts/cluster/values.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,13 @@ cluster:
343343
# - name: custom-queries-secret
344344
# key: custom-queries
345345

346+
plugins: []
347+
# - name: cnpg-i-plugin-example.my-org.io
348+
# enabled: true
349+
# parameters:
350+
# key1: value1
351+
# key2: value2
352+
346353
postgresql:
347354
# -- PostgreSQL configuration options (postgresql.conf)
348355
parameters: {}

0 commit comments

Comments
 (0)