Skip to content

Commit

Permalink
[postgresql] add scheduledbackup
Browse files Browse the repository at this point in the history
  • Loading branch information
jouve committed May 18, 2023
1 parent ca905ce commit 2906795
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion charts/postgresql/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: postgresql
description: Deploy postgresql using cloudnative-pg operator
type: application
version: 0.1.1
version: 0.1.2
appVersion: "15.3"
sources:
- https://github.com/jouve/charts
Expand Down
4 changes: 4 additions & 0 deletions charts/postgresql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ helm repo add jouve https://jouve.github.io/charts/
| `global.imagePullSecrets` | Global Docker registry secret names as an array | `[]` |
| `global.storageClass` | Global StorageClass for Persistent Volume(s) | `""` |
| `replicaCount` | Number of PostgreSQL replicas | `1` |
| `affinity.podAntiAffinityType` | Allowed values are: "preferred" or "required". | `required` |
| `backup.enabled` | Enable backup | `false` |
| `backup.endpointURL` | Endpoint to be used to upload data to the cloud | `""` |
| `backup.bucketName` | Name of the bucket | `""` |
| `backup.existingSecret` | Name of the secret containing the credentials | `""` |
| `backup.objectBucketClaim.enabled` | Create the bucket from an ObjectBucketClaim | `false` |
| `backup.objectBucketClaim.storageClassName` | StorageClass for the ObjectBucketClaim | `""` |
| `backup.scheduled.enabled` | Enabled creation of a scheduled backup | `false` |
| `backup.scheduled.schedule` | Schedule of the scheduled backup | `0 0 0 * * *` |
| `backup.retentionPolicy` | Retention for backups | `7d` |
| `persistence.storageClass` | PVC Storage Class for PostgreSQL Primary data volume | `""` |
| `persistence.size` | PVC Storage Request for PostgreSQL volume | `8Gi` |
| `networkPolicy.enabled` | Enable network policies | `false` |
Expand Down
19 changes: 19 additions & 0 deletions charts/postgresql/templates/backup/scheduledbackup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- if .Values.backup.scheduled.enabled }}
apiVersion: postgresql.cnpg.io/v1
kind: ScheduledBackup
metadata:
name: {{ template "common.names.fullname" . }}-backup
namespace: {{ include "common.names.namespace" . | quote }}
labels: {{- include "common.labels.standard" . | nindent 4 }}
{{- if .Values.commonLabels }}
{{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
{{- end }}
{{- if .Values.commonAnnotations }}
annotations: {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
{{- end }}
spec:
schedule: {{ .Values.backup.scheduled.schedule }}
backupOwnerReference: self
cluster:
name: {{ template "common.names.fullname" . }}
{{- end }}
3 changes: 3 additions & 0 deletions charts/postgresql/templates/postgresql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ spec:
monitoring:
enablePodMonitor: true
{{- end }}
affinity:
podAntiAffinityType: {{ .Values.affinity.podAntiAffinityType }}
{{- if .Values.backup.enabled }}
backup:
barmanObjectStore:
Expand All @@ -37,4 +39,5 @@ spec:
secretAccessKey:
name: {{ if .Values.backup.objectBucketClaim.enabled }}{{ template "common.names.fullname" . }}-backup{{ else }}{{ .Values.backup.existingSecret }}{{ end }}
key: AWS_SECRET_ACCESS_KEY
retentionPolicy: {{ .Values.backup.retentionPolicy | quote }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/postgresql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ global:
##
replicaCount: 1

affinity:
## @param affinity.podAntiAffinityType Allowed values are: "preferred" or "required".
## ref: https://cloudnative-pg.io/documentation/1.16/api_reference/#AffinityConfiguration
##
podAntiAffinityType: required

# https://cloudnative-pg.io/documentation/current/backup_recovery/
## @param backup.enabled Enable backup
## @param backup.endpointURL Endpoint to be used to upload data to the cloud
## @param backup.bucketName Name of the bucket
## @param backup.existingSecret Name of the secret containing the credentials
## @param backup.objectBucketClaim.enabled Create the bucket from an ObjectBucketClaim
## @param backup.objectBucketClaim.storageClassName StorageClass for the ObjectBucketClaim
## @param backup.scheduled.enabled Enabled creation of a scheduled backup
## @param backup.scheduled.schedule Schedule of the scheduled backup
## @param backup.retentionPolicy Retention for backups
backup:
enabled: false
endpointURL: ""
Expand All @@ -40,6 +49,10 @@ backup:
objectBucketClaim:
enabled: false
storageClassName: ""
scheduled:
enabled: false
schedule: 0 0 0 * * *
retentionPolicy: 7d

## PostgreSQL persistence configuration
##
Expand Down

0 comments on commit 2906795

Please sign in to comment.