Skip to content

Commit 58c0a79

Browse files
committed
feat(cluster): add CNPG-I plugin support and ObjectStore CRD
Signed-off-by: Bernard Gütermann <bernard.gutermann@sekops.ch>
1 parent f2711f3 commit 58c0a79

11 files changed

Lines changed: 206 additions & 1 deletion

charts/cluster/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ refer to the [CloudNativePG Documentation](https://cloudnative-pg.io/documentati
176176
| cluster.monitoring.podMonitor.relabelings | list | `[]` | The list of relabelings for the PodMonitor. Applied to samples before scraping. |
177177
| cluster.monitoring.prometheusRule.enabled | bool | `true` | Whether to enable the PrometheusRule automated alerts |
178178
| cluster.monitoring.prometheusRule.excludeRules | list | `[]` | Exclude specified rules |
179+
| cluster.plugins | list | `[]` | List of CNPG-I plugins to be loaded by the cluster |
179180
| cluster.podSecurityContext | object | `{}` | Configure the Pod Security Context. See: https://cloudnative-pg.io/documentation/preview/security/ |
180181
| cluster.postgresGID | int | `-1` | The GID of the postgres user inside the image, defaults to 26 |
181182
| cluster.postgresUID | int | `-1` | The UID of the postgres user inside the image, defaults to 26 |

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/_external_clusters.tpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,20 @@ externalClusters:
1010
- name: importSource
1111
{{- include "cluster.externalSourceCluster" .Values.recovery.import.source | nindent 4 }}
1212
{{- else if eq .Values.recovery.method "object_store" }}
13+
{{- if eq (include "cluster.useBarmanCloudPlugin" .) "true" }}
14+
- name: objectStoreRecoveryCluster
15+
plugin:
16+
name: barman-cloud.cloudnative-pg.io
17+
parameters:
18+
barmanObjectName: {{ include "cluster.barmanCloudObjectStoreName" . }}
19+
serverName: {{ .Values.recovery.clusterName | default (include "cluster.fullname" .) }}
20+
{{- else }}
1321
- name: objectStoreRecoveryCluster
1422
barmanObjectStore:
1523
serverName: {{ .Values.recovery.clusterName }}
1624
{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.recovery "secretPrefix" "recovery" -}}
1725
{{- include "cluster.barmanObjectStoreConfig" $d | nindent 4 }}
26+
{{- end }}
1827
{{- end }}
1928
{{- else if eq .Values.mode "replica" }}
2029
- name: originCluster

charts/cluster/templates/_helpers.tpl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,39 @@ Postgres GID
144144
{{- 26 -}}
145145
{{- end -}}
146146
{{- end -}}
147+
148+
149+
{{/*
150+
Returns true if the barman-cloud plugin is present and not explicitly disabled.
151+
*/}}
152+
{{- define "cluster.useBarmanCloudPlugin" -}}
153+
{{- $hasPlugin := false }}
154+
{{- if .Values.cluster.plugins }}
155+
{{- range .Values.cluster.plugins }}
156+
{{- if eq .name "barman-cloud.cloudnative-pg.io" }}
157+
{{- if not (eq (toString (default true .enabled)) "false") }}
158+
{{- $hasPlugin = true }}
159+
{{- end }}
160+
{{- end }}
161+
{{- end }}
162+
{{- end }}
163+
{{- $hasPlugin }}
164+
{{- end }}
165+
166+
167+
{{/*
168+
ObjectStore name for the barman-cloud plugin, auto-derived or from plugin parameters.
169+
*/}}
170+
{{- define "cluster.barmanCloudObjectStoreName" -}}
171+
{{- $name := printf "%s-object-store" (include "cluster.fullname" .) }}
172+
{{- if .Values.cluster.plugins }}
173+
{{- range .Values.cluster.plugins }}
174+
{{- if eq .name "barman-cloud.cloudnative-pg.io" }}
175+
{{- if and .parameters .parameters.barmanObjectName }}
176+
{{- $name = .parameters.barmanObjectName }}
177+
{{- end }}
178+
{{- end }}
179+
{{- end }}
180+
{{- end }}
181+
{{- $name }}
182+
{{- end }}

charts/cluster/templates/cluster.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,32 @@ spec:
6767
name: {{ . }}
6868
{{ end }}
6969
enablePDB: {{ .Values.cluster.enablePDB }}
70+
{{- if .Values.cluster.plugins }}
71+
plugins:
72+
{{- range .Values.cluster.plugins }}
73+
- name: {{ .name }}
74+
{{- if hasKey . "enabled" }}
75+
enabled: {{ .enabled }}
76+
{{- end }}
77+
{{- if .isWALArchiver }}
78+
isWALArchiver: {{ .isWALArchiver }}
79+
{{- end }}
80+
{{- if and (eq .name "barman-cloud.cloudnative-pg.io") $.Values.backups.enabled }}
81+
parameters:
82+
barmanObjectName: {{ include "cluster.barmanCloudObjectStoreName" $ }}
83+
{{- with .parameters }}
84+
{{- range $k, $v := . }}
85+
{{- if ne $k "barmanObjectName" }}
86+
{{ $k }}: {{ $v | quote }}
87+
{{- end }}
88+
{{- end }}
89+
{{- end }}
90+
{{- else if .parameters }}
91+
parameters:
92+
{{- toYaml .parameters | nindent 8 }}
93+
{{- end }}
94+
{{- end }}
95+
{{- end }}
7096
postgresql:
7197
{{- if or (eq .Values.type "timescaledb") (not (empty .Values.cluster.postgresql.shared_preload_libraries)) }}
7298
shared_preload_libraries:
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{{- if and .Values.backups.enabled (eq (include "cluster.useBarmanCloudPlugin" .) "true") }}
2+
apiVersion: barmancloud.cnpg.io/v1
3+
kind: ObjectStore
4+
metadata:
5+
name: {{ include "cluster.barmanCloudObjectStoreName" . }}
6+
namespace: {{ include "cluster.namespace" $ }}
7+
labels:
8+
{{- include "cluster.labels" . | nindent 4 }}
9+
spec:
10+
{{- with .Values.backups.retentionPolicy }}
11+
retentionPolicy: {{ . }}
12+
{{- end }}
13+
configuration:
14+
{{- if .Values.backups.endpointURL }}
15+
endpointURL: {{ .Values.backups.endpointURL | quote }}
16+
{{- end }}
17+
{{- if or (.Values.backups.endpointCA.create) (.Values.backups.endpointCA.name) }}
18+
endpointCA:
19+
name: {{ .Values.backups.endpointCA.name }}
20+
key: {{ .Values.backups.endpointCA.key }}
21+
{{- end }}
22+
{{- if eq .Values.backups.provider "s3" }}
23+
{{- if empty .Values.backups.endpointURL }}
24+
endpointURL: "https://s3.{{ required "You need to specify S3 region if endpointURL is not specified." .Values.backups.s3.region }}.amazonaws.com"
25+
{{- end }}
26+
destinationPath: {{ default (printf "s3://%s%s" (required "You need to specify S3 bucket." .Values.backups.s3.bucket) .Values.backups.s3.path) .Values.backups.destinationPath }}
27+
{{- $secretName := coalesce .Values.backups.secret.name (printf "%s-backup-s3-creds" (include "cluster.fullname" .)) }}
28+
s3Credentials:
29+
{{- if .Values.backups.s3.inheritFromIAMRole }}
30+
inheritFromIAMRole: true
31+
{{- else }}
32+
accessKeyId:
33+
name: {{ $secretName }}
34+
key: ACCESS_KEY_ID
35+
secretAccessKey:
36+
name: {{ $secretName }}
37+
key: ACCESS_SECRET_KEY
38+
{{- end }}
39+
{{- else if eq .Values.backups.provider "azure" }}
40+
destinationPath: {{ default (printf "https://%s.%s.core.windows.net/%s%s" (required "You need to specify Azure storageAccount." .Values.backups.azure.storageAccount) .Values.backups.azure.serviceName .Values.backups.azure.containerName .Values.backups.azure.path) .Values.backups.destinationPath }}
41+
{{- $secretName := coalesce .Values.backups.secret.name (printf "%s-backup-azure-creds" (include "cluster.fullname" .)) }}
42+
azureCredentials:
43+
{{- if .Values.backups.azure.inheritFromAzureAD }}
44+
inheritFromAzureAD: true
45+
{{- else if .Values.backups.azure.connectionString }}
46+
connectionString:
47+
name: {{ $secretName }}
48+
key: AZURE_CONNECTION_STRING
49+
{{- else }}
50+
storageAccount:
51+
name: {{ $secretName }}
52+
key: AZURE_STORAGE_ACCOUNT
53+
{{- if .Values.backups.azure.storageKey }}
54+
storageKey:
55+
name: {{ $secretName }}
56+
key: AZURE_STORAGE_KEY
57+
{{- else }}
58+
storageSasToken:
59+
name: {{ $secretName }}
60+
key: AZURE_STORAGE_SAS_TOKEN
61+
{{- end }}
62+
{{- end }}
63+
{{- else if eq .Values.backups.provider "google" }}
64+
destinationPath: {{ default (printf "gs://%s%s" (required "You need to specify Google storage bucket." .Values.backups.google.bucket) .Values.backups.google.path) .Values.backups.destinationPath }}
65+
{{- $secretName := coalesce .Values.backups.secret.name (printf "%s-backup-google-creds" (include "cluster.fullname" .)) }}
66+
googleCredentials:
67+
gkeEnvironment: {{ .Values.backups.google.gkeEnvironment }}
68+
{{- if not .Values.backups.google.gkeEnvironment }}
69+
applicationCredentials:
70+
name: {{ $secretName }}
71+
key: APPLICATION_CREDENTIALS
72+
{{- end }}
73+
{{- end }}
74+
wal:
75+
compression: {{ .Values.backups.wal.compression }}
76+
{{- if .Values.backups.wal.encryption }}
77+
encryption: {{ .Values.backups.wal.encryption }}
78+
{{- end }}
79+
maxParallel: {{ .Values.backups.wal.maxParallel }}
80+
data:
81+
compression: {{ .Values.backups.data.compression }}
82+
{{- if .Values.backups.data.encryption }}
83+
encryption: {{ .Values.backups.data.encryption }}
84+
{{- end }}
85+
jobs: {{ .Values.backups.data.jobs }}
86+
{{- 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 and (eq (include "cluster.useBarmanCloudPlugin" $context) "true") (ne (default "" .method) "volumeSnapshot") }}
18+
method: plugin
19+
pluginConfiguration:
20+
name: barman-cloud.cloudnative-pg.io
21+
{{- else }}
22+
method: {{ default "barmanObjectStore" .method }}
23+
{{- end }}
1824
{{ end -}}
1925
{{ end }}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ spec:
4949
name: supersecret-secret
5050
enableSuperuserAccess: true
5151
enablePDB: false
52+
plugins:
53+
- name: cnpg-i-plugin-example.my-org.io
54+
enabled: true
55+
parameters:
56+
key1: value1
57+
key2: value2
5258
certificates:
5359
serverCASecret: ca-secret
5460
serverTLSSecret: tls-secret

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
@@ -281,6 +281,27 @@
281281
}
282282
}
283283
},
284+
"plugins": {
285+
"type": "array",
286+
"items": {
287+
"type": "object",
288+
"properties": {
289+
"name": {
290+
"type": "string"
291+
},
292+
"enabled": {
293+
"type": "boolean"
294+
},
295+
"isWALArchiver": {
296+
"type": "boolean"
297+
},
298+
"parameters": {
299+
"type": "object"
300+
}
301+
},
302+
"required": ["name"]
303+
}
304+
},
284305
"podSecurityContext": {
285306
"type": "object"
286307
},

0 commit comments

Comments
 (0)