Skip to content

feat(cluster): extend backup configuration for volumesnapshot and plugin #521

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/tests-cluster-chainsaw.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ jobs:
- name: Setup kind
uses: ./.github/actions/setup-kind

- name: Install VolumeSnapShot CRDs
run: |
kubectl apply -f \
https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-5.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotclasses.yaml
kubectl apply -f \
https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-5.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshotcontents.yaml
kubectl apply -f \
https://raw.githubusercontent.com/kubernetes-csi/external-snapshotter/release-5.0/client/config/crd/snapshot.storage.k8s.io_volumesnapshots.yaml

- name: Deploy the operator
uses: ./.github/actions/deploy-operator

Expand Down
2 changes: 2 additions & 0 deletions charts/cloudnative-pg/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ CloudNativePG Operator Helm Chart
| updateStrategy | object | `{}` | Update strategy for the operator. ref: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/#strategy For example: type: RollingUpdate rollingUpdate: maxSurge: 25% maxUnavailable: 25% |
| webhook | object | `{"livenessProbe":{"initialDelaySeconds":3},"mutating":{"create":true,"failurePolicy":"Fail"},"port":9443,"readinessProbe":{"initialDelaySeconds":3},"startupProbe":{"failureThreshold":6,"periodSeconds":5},"validating":{"create":true,"failurePolicy":"Fail"}}` | The webhook configuration. |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)
2 changes: 1 addition & 1 deletion charts/cluster/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ name: cluster
description: Deploys and manages a CloudNativePG cluster and its associated resources.
icon: https://raw.githubusercontent.com/cloudnative-pg/artwork/main/cloudnativepg-logo.svg
type: application
version: 0.2.1
version: 0.2.2
sources:
- https://github.com/cloudnative-pg/charts
keywords:
Expand Down
100 changes: 62 additions & 38 deletions charts/cluster/README.md

Large diffs are not rendered by default.

27 changes: 24 additions & 3 deletions charts/cluster/README.md.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ The chart has three modes of operation. These are configured via the `mode` para

### Backup configuration

#### Barman Object Store

CNPG implements disaster recovery via [Barman](https://pgbarman.org/). The following section configures the barman object
store where backups will be stored. Barman performs backups of the cluster filesystem base backup and WALs. Both are
stored in the specified location. The backup provider is configured via the `backups.provider` parameter. The following
Expand All @@ -101,10 +103,29 @@ backups:
backupOwnerReference: self
```

Each backup adapter takes it's own set of parameters, listed in the [Configuration options](#Configuration-options) section
below. Refer to the table for the full list of parameters and place the configuration under the appropriate key: `backup.s3`,
`backup.azure`, or `backup.google`.
Each backup adapter takes its own set of parameters, listed in the [Configuration options](#Configuration-options) section
below. Refer to the table for the full list of parameters and place the configuration under the appropriate key: `backup.barmanObjectStore.s3`,
`backup.barmanObjectStore.azure`, or `backup.barmanObjectStore.google`.

#### Volume Snapshots

You can also configure backup using Volume Snapshots. See the [example](.examples/volumesnapshot.yml) to learn how to do that.

Volume snapshots can be used as a backup method by setting the `backups.method` parameter to `volumeSnapshot`. The following parameters can be configured:
* `backups.volumeSnapshot.className` - Snapshot Class to be used for PG_DATA PersistentVolumeClaim.
* `backups.volumeSnapshot.walClassName` - Snapshot Class to be used for the PG_WAL PersistentVolumeClaim.
* `backups.volumeSnapshot.tablespaceClassName` - Snapshot Class to be used for the tablespaces. Defaults to the PGDATA Snapshot Class, if set.
* `backups.volumeSnapshot.snapshotOwnerReference` - Type of owner reference the snapshot should have. Available options are `none`, `cluster`, and `backup`.
* `backups.volumeSnapshot.online` - Define if the backup shall be online or offline.
* `backups.volumeSnapshot.onlineConfiguration` - Configuration for online backups, including `waitForArchive` and `immediateCheckpoint`.

#### Plugin Backups

Another backup option are plugin backups. See the [example](.examples/pluginbackup.yml) to learn how to do that.

Plugin backups can be used by setting the `backups.method` parameter to `plugin`. The following parameters can be configured:
* `backups.pluginConfiguration.name` - Name of the plugin to use.
* `backups.pluginConfiguration.parameters` - Configuration parameters for the plugin.

Recovery
--------
Expand Down
14 changes: 14 additions & 0 deletions charts/cluster/examples/pluginbackup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type: postgresql
mode: standalone
version:
postgresql: "16"
cluster:
instances: 1
backups:
enabled: true
method: plugin
pluginConfiguration:
name: testplugin
parameters:
param1: value1
param2: value2
26 changes: 14 additions & 12 deletions charts/cluster/examples/recovery-backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ cluster:
instances: 1

backups:
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1-restore"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
enabled: true
barmanObjectStore:
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1-restore"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
28 changes: 15 additions & 13 deletions charts/cluster/examples/recovery-object_store.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ cluster:
instances: 1

backups:
endpointURL: "https://cm-db-chart-test.ams3.digitaloceanspaces.com"
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1-restore"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
enabled: true
barmanObjectStore:
endpointURL: "https://cm-db-chart-test.ams3.digitaloceanspaces.com"
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1-restore"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
25 changes: 13 additions & 12 deletions charts/cluster/examples/standalone-s3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ cluster:

backups:
enabled: true
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
barmanObjectStore:
provider: s3
s3:
region: "eu-west-1"
bucket: "db-backups"
path: "/v1"
accessKey: "AWS_S3_ACCESS_KEY"
secretKey: "AWS_S3_SECRET_KEY"
scheduledBackups:
- name: daily-backup # Daily at midnight
schedule: "0 0 0 * * *" # Daily at midnight
backupOwnerReference: self
retentionPolicy: "30d"
22 changes: 22 additions & 0 deletions charts/cluster/examples/volumesnapshot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
type: postgresql
mode: standalone
version:
postgresql: "16"
cluster:
instances: 1
backups:
enabled: true
method: volumeSnapshot
volumeSnapshot:
labels:
testlabel: abc
annotations:
testannotation: def
className: snapclass
snapshotOwnerReference: backup
online: true
scheduledBackups:
- name: daily-backup
schedule: "0 0 0 * * *"
backupOwnerReference: self
method: volumeSnapshot
5 changes: 4 additions & 1 deletion charts/cluster/templates/NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ Configuration
│ Instances │ {{ include (printf "%s%s" "cluster.color-" $redundancyColor) (printf "%-56s" (toString .Values.cluster.instances)) }} │
│ Backups │ {{ include (printf "%s%s" "cluster.color-" (ternary "ok" "error" .Values.backups.enabled)) (printf "%-56s" (ternary "Enabled" "Disabled" .Values.backups.enabled)) }} │
{{- if .Values.backups.enabled }}
│ Backup Provider │ {{ printf "%-56s" (title .Values.backups.provider) }} │
| Backup Method | {{ printf "%-56s" .Values.backups.method }} |
{{- if eq .Values.backups.method "barmanObjectStore" }}
│ Backup Provider │ {{ printf "%-56s" (title .Values.backups.barmanObjectStore.provider) }} │
{{- end }}
│ Scheduled Backups │ {{ printf "%-56s" $scheduledBackups }} │
{{- end }}
│ Storage │ {{ printf "%-56s" .Values.cluster.storage.size }} │
Expand Down
41 changes: 32 additions & 9 deletions charts/cluster/templates/_backup.tpl
Original file line number Diff line number Diff line change
@@ -1,19 +1,42 @@
{{- define "cluster.backup" -}}
{{- if .Values.backups.enabled }}
backup:
target: "prefer-standby"
target: {{ .Values.backups.target }}
retentionPolicy: {{ .Values.backups.retentionPolicy }}
{{- if eq .Values.backups.method "plugin" }}
pluginConfiguration:
name: {{ .Values.backups.pluginConfiguration.name }}
parameters:
{{ .Values.backups.pluginConfiguration.parameters | toYaml | nindent 6 }}
{{- end }}
{{- if eq .Values.backups.method "volumeSnapshot" }}
volumeSnapshot:
labels:
{{ .Values.backups.volumeSnapshot.labels | toYaml | nindent 6 }}
annotations:
{{ .Values.backups.volumeSnapshot.annotations | toYaml | nindent 6 }}
className: {{ .Values.backups.volumeSnapshot.className }}
walClassName: {{ .Values.backups.volumeSnapshot.walClassName }}
tablespaceClassName:
{{ .Values.backups.volumeSnapshot.tablespaceClassName | toYaml | nindent 6 }}
snapshotOwnerReference: {{ .Values.backups.volumeSnapshot.snapshotOwnerReference }}
online: {{ .Values.backups.volumeSnapshot.online }}
onlineConfiguration:
waitForArchive: {{ .Values.backups.volumeSnapshot.onlineConfiguration.waitForArchive }}
immediateCheckpoint: {{ .Values.backups.volumeSnapshot.onlineConfiguration.immediateCheckpoint }}
{{- end }}
{{- if eq .Values.backups.method "barmanObjectStore" }}
barmanObjectStore:
wal:
compression: {{ .Values.backups.wal.compression }}
encryption: {{ .Values.backups.wal.encryption }}
maxParallel: {{ .Values.backups.wal.maxParallel }}
compression: {{ .Values.backups.barmanObjectStore.wal.compression }}
encryption: {{ .Values.backups.barmanObjectStore.wal.encryption }}
maxParallel: {{ .Values.backups.barmanObjectStore.wal.maxParallel }}
data:
compression: {{ .Values.backups.data.compression }}
encryption: {{ .Values.backups.data.encryption }}
jobs: {{ .Values.backups.data.jobs }}

{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.backups "secretPrefix" "backup" }}
compression: {{ .Values.backups.barmanObjectStore.data.compression }}
encryption: {{ .Values.backups.barmanObjectStore.data.encryption }}
jobs: {{ .Values.backups.barmanObjectStore.data.jobs }}
{{- $d := dict "chartFullname" (include "cluster.fullname" .) "scope" .Values.backups.barmanObjectStore "secretPrefix" "backup" }}
{{- include "cluster.barmanObjectStoreConfig" $d | nindent 2 }}
{{- end }}
{{- end }}
{{- end }}
12 changes: 6 additions & 6 deletions charts/cluster/templates/backup-azure-creds.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- if and .Values.backups.enabled (eq .Values.backups.provider "azure") .Values.backups.secret.create }}
{{- if and .Values.backups.enabled (eq .Values.backups.method "barmanObjectStore") (eq .Values.backups.barmanObjectStore.provider "azure") .Values.backups.barmanObjectStore.secret.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ default (printf "%s-backup-azure-creds" (include "cluster.fullname" .)) .Values.backups.secret.name }}
name: {{ default (printf "%s-backup-azure-creds" (include "cluster.fullname" .)) .Values.backups.barmanObjectStore.secret.name }}
namespace: {{ include "cluster.namespace" . }}
data:
AZURE_CONNECTION_STRING: {{ .Values.backups.azure.connectionString | b64enc | quote }}
AZURE_STORAGE_ACCOUNT: {{ .Values.backups.azure.storageAccount | b64enc | quote }}
AZURE_STORAGE_KEY: {{ .Values.backups.azure.storageKey | b64enc | quote }}
AZURE_STORAGE_SAS_TOKEN: {{ .Values.backups.azure.storageSasToken | b64enc | quote }}
AZURE_CONNECTION_STRING: {{ .Values.backups.barmanObjectStore.azure.connectionString | b64enc | quote }}
AZURE_STORAGE_ACCOUNT: {{ .Values.backups.barmanObjectStore.azure.storageAccount | b64enc | quote }}
AZURE_STORAGE_KEY: {{ .Values.backups.barmanObjectStore.azure.storageKey | b64enc | quote }}
AZURE_STORAGE_SAS_TOKEN: {{ .Values.backups.barmanObjectStore.azure.storageSasToken | b64enc | quote }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/cluster/templates/backup-google-creds.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{- if and .Values.backups.enabled (eq .Values.backups.provider "google") .Values.backups.secret.create }}
{{- if and .Values.backups.enabled (eq .Values.backups.method "barmanObjectStore") (eq .Values.backups.barmanObjectStore.provider "google") .Values.backups.barmanObjectStore.secret.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ default (printf "%s-backup-google-creds" (include "cluster.fullname" .)) .Values.backups.secret.name }}
name: {{ default (printf "%s-backup-google-creds" (include "cluster.fullname" .)) .Values.backups.barmanObjectStore.secret.name }}
namespace: {{ include "cluster.namespace" . }}
data:
APPLICATION_CREDENTIALS: {{ .Values.backups.google.applicationCredentials | b64enc | quote }}
APPLICATION_CREDENTIALS: {{ .Values.backups.barmanObjectStore.google.applicationCredentials | b64enc | quote }}
{{- end }}
8 changes: 4 additions & 4 deletions charts/cluster/templates/backup-s3-creds.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{- if and .Values.backups.enabled (eq .Values.backups.provider "s3") (not .Values.backups.s3.inheritFromIAMRole) .Values.backups.secret.create }}
{{- if and .Values.backups.enabled (eq .Values.backups.method "barmanObjectStore") (eq .Values.backups.barmanObjectStore.provider "s3") (not .Values.backups.barmanObjectStore.s3.inheritFromIAMRole) .Values.backups.barmanObjectStore.secret.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ default (printf "%s-backup-s3-creds" (include "cluster.fullname" .)) .Values.backups.secret.name }}
name: {{ default (printf "%s-backup-s3-creds" (include "cluster.fullname" .)) .Values.backups.barmanObjectStore.secret.name }}
namespace: {{ include "cluster.namespace" . }}
data:
ACCESS_KEY_ID: {{ required ".Values.backups.s3.accessKey is required, but not specified." .Values.backups.s3.accessKey | b64enc | quote }}
ACCESS_SECRET_KEY: {{ required ".Values.backups.s3.secretKey is required, but not specified." .Values.backups.s3.secretKey | b64enc | quote }}
ACCESS_KEY_ID: {{ required ".Values.backups.barmanObjectStore.s3.accessKey is required, but not specified." .Values.backups.barmanObjectStore.s3.accessKey | b64enc | quote }}
ACCESS_SECRET_KEY: {{ required ".Values.backups.barmanObjectStore.s3.secretKey is required, but not specified." .Values.backups.barmanObjectStore.s3.secretKey | b64enc | quote }}
{{- end }}
6 changes: 3 additions & 3 deletions charts/cluster/templates/ca-bundle.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{{- if .Values.backups.endpointCA.create }}
{{- if .Values.backups.barmanObjectStore.endpointCA.create }}
apiVersion: v1
kind: Secret
metadata:
name: {{ .Values.backups.endpointCA.name | default (printf "%s-ca-bundle" (include "cluster.fullname" .)) | quote }}
name: {{ .Values.backups.barmanObjectStore.endpointCA.name | default (printf "%s-ca-bundle" (include "cluster.fullname" .)) | quote }}
namespace: {{ include "cluster.namespace" . }}
data:
{{ .Values.backups.endpointCA.key | default "ca-bundle.crt" | quote }}: {{ .Values.backups.endpointCA.value }}
{{ .Values.backups.barmanObjectStore.endpointCA.key | default "ca-bundle.crt" | quote }}: {{ .Values.backups.barmanObjectStore.endpointCA.value }}

{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@ cluster:

backups:
enabled: true
provider: s3
endpointURL: "https://minio.minio.svc.cluster.local"
endpointCA:
name: kube-root-ca.crt
key: ca.crt
wal:
encryption: ""
data:
encryption: ""
s3:
bucket: "mybucket"
path: "/postgresql-minio-backup-restore/v1"
accessKey: "minio"
secretKey: "minio123"
region: "local"
scheduledBackups: []
retentionPolicy: "30d"
barmanObjectStore:
provider: s3
endpointURL: "https://minio.minio.svc.cluster.local"
endpointCA:
name: kube-root-ca.crt
key: ca.crt
wal:
encryption: ""
data:
encryption: ""
s3:
bucket: "mybucket"
path: "/postgresql-minio-backup-restore/v1"
accessKey: "minio"
secretKey: "minio123"
region: "local"
scheduledBackups: []
retentionPolicy: "30d"
Loading