Skip to content
Merged
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
8 changes: 8 additions & 0 deletions charts/cnpg-cluster/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog for the 'cnpg-cluster' Helm-Chart

# v0.2.0

> [!CAUTION]
> Upgrading from `0.1.0` needs adjusting Helm-Values, since the Helm-field `backupCronjob.persistentVolumeClaimName` doesn't exist anymore. Please configure the claim-name of the PVC at `backupCronjob.persistentVolumeClaim.claimName`.
> By default, the Chart is creating a **new** PVC-Resource based on the Helm-Values specificed at `backupCronjob.persistentVolumeClaim`. Set `backupCronjob.persistentVolumeClaim.useExisting: true` if you want to use an existing PVC with the provided Claim-Name instead.

- Create new **PVC**-Resource for **CronJob** db-dump by default instead of using an existing PVC

# v0.1.0

- Initial version
Expand Down
2 changes: 1 addition & 1 deletion charts/cnpg-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apiVersion: v2
name: cnpg-cluster
description: Custom Helm-Chart for a CNPG-Cluster with db-dump CronJob functionality
version: 0.1.0
version: 0.2.0
8 changes: 6 additions & 2 deletions charts/cnpg-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Custom Helm-Chart for a CNPG-Cluster with db-dump CronJob functionality
> The chart does not configure or guarantee the backup of the PV - this responsibility remains with the user.
> This chart is tailored to a specific CNPG backup use case. If you try to use it in your cluster, please verify that it fits your environment and requirements (including PV provisioning and backup/retention setup).

![Version: 0.1.0](https://img.shields.io/badge/Version-0.1.0-informational?style=flat-square)
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)

## Values

Expand All @@ -19,7 +19,11 @@ Custom Helm-Chart for a CNPG-Cluster with db-dump CronJob functionality
|-----|------|---------|-------------|
| backupCronjob.containerImage | string | `"postgres:16-alpine"` | Container-Image with 'pg_dumpall'-binary at PATH |
| backupCronjob.enabled | bool | `false` | Whether to enable backups |
| backupCronjob.persistentVolumeClaimName | string | `"cnpg-db-backup-pvc"` | Name of existing PVC where the database-dump is being stored at |
| backupCronjob.persistentVolumeClaim.accessModes | list | `["ReadWriteOnce"]` | Access-modes for new created PVC. Gets ignored when `useExistingPVC: true` |
| backupCronjob.persistentVolumeClaim.claimName | string | `"cnpg-db-backup-pvc"` | Name of PVC where the database-dump is being stored at |
| backupCronjob.persistentVolumeClaim.storageClassName | string | `"local-path"` | Storage request for new created PVC. Gets ignored when `useExistingPVC: true` |
| backupCronjob.persistentVolumeClaim.storageRequest | string | `"10Gi"` | Storage request for new created PVC. Gets ignored when `useExistingPVC: true` |
| backupCronjob.persistentVolumeClaim.useExisting | bool | `false` | Use existing PVC and don't create new PVC-resource with the given `persistentVolumeClaimName`. |
| backupCronjob.restartPolicy | string | `"OnFailure"` | Policy to restart Backup-Cronjob |
| backupCronjob.schedule | string | `"10 * * * *"` | Schedule of the Cronjob (NOTE: Align with the actual PV-Backup-Schedule) |
| backupCronjob.targetDatabaseHost | string | `"cnpg-cluster-app-rw.cnpg-system"` | Target CNPG-database Host |
Expand Down
2 changes: 1 addition & 1 deletion charts/cnpg-cluster/templates/backup-cronjob.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ spec:
volumes:
- name: backup-volume
persistentVolumeClaim:
claimName: {{ $cronjob.persistentVolumeClaimName }}
claimName: {{ $cronjob.persistentVolumeClaim.claimName }}
{{- end -}}
18 changes: 18 additions & 0 deletions charts/cnpg-cluster/templates/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{ include "cnpgdb.validateValues" . }}
{{- $postgresCluster := .Values.postgresCluster -}}
{{- $backupCronjob := .Values.backupCronjob -}}
{{- $pvc := $backupCronjob.persistentVolumeClaim -}}
{{- if and $postgresCluster.enableSuperuserAccess $backupCronjob.enabled (not $pvc.useExisting) -}}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: {{ $pvc.claimName }}
namespace: {{ .Release.Namespace | quote }}
labels: {{- include "cnpgdb.labels" . }}
spec:
storageClassName: {{ $pvc.storageClassName }}
accessModes: {{- toYaml $pvc.accessModes | nindent 4 }}
resources:
requests:
storage: {{ $pvc.storageRequest | quote }}
{{- end -}}
8 changes: 7 additions & 1 deletion charts/cnpg-cluster/tests/backup-cronjob_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ tests:
cnpgSuperUserSecretName: "test-cnpg-superuser-secret"
backupCronjob:
enabled: true
persistentVolumeClaim:
claimName: "1337-test-cronjob-pvc"
schedule: "1337 1337 1337"
timeZone: "EARTH"
restartPolicy: OnFailure
containerImage: "postgres:1337-alpine"
persistentVolumeClaimName: "test-cronjob-backup-pvc"
targetDatabaseHost: "cnpg-db.1337-db-host"
targetDatabasePort: 1337
#
Expand Down Expand Up @@ -94,5 +95,10 @@ tests:
> /backup/cnpg-sqlbkp.sql
ls -lah /backup/cnpg-sqlbkp.sql

- equal:
path: spec.jobTemplate.spec.template.spec.volumes[?(@.name=="backup-volume")].persistentVolumeClaim.claimName
value: "1337-test-cronjob-pvc"




91 changes: 91 additions & 0 deletions charts/cnpg-cluster/tests/pvc_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#------------------------------------------------------------------------------
#
# PVC-Unittests Test-Suite for CNPG-Cluster
#
# > https://github.com/helm-unittest/helm-unittest/blob/main/DOCUMENT.md
#
#------------------------------------------------------------------------------
#
# Test suite name to show on test result output
suite: Test PVC
#
# The template files scope to test in this suite
# Only the selected files will be rendered
templates:
- templates/pvc.yaml
#
tests:
- it: should NOT render new PVC-Resource with disabled superUserAccess
#
set:
postgresCluster:
enableSuperuserAccess: false
cnpgSuperUserSecretName: "test-cnpg-superuser-secret"
backupCronjob.enabled: true
#
asserts:
- failedTemplate:
errorMessage: "VALUES VALIDATION:\ncnpgdb: enableSuperuserAccess\n You have to enable external superUserAccess when enabling Backups"

- it: should NOT render new PVC-Resource with disabled Cronjob
#
set:
postgresCluster:
enableSuperuserAccess: true
cnpgSuperUserSecretName: "test-cnpg-superuser-secret"
backupCronjob.enabled: false
#
asserts:
- notExists:
path: spec

- it: should NOT render new PVC-Resource with useExisting
#
set:
postgresCluster:
enableSuperuserAccess: true
cnpgSuperUserSecretName: "test-cnpg-superuser-secret"
backupCronjob:
enabled: true
persistentVolumeClaim:
useExisting: true
#
asserts:
- notExists:
path: spec

- it: should render new PVC-Resource with adjusted Values
#
set:
postgresCluster:
enableSuperuserAccess: true
cnpgSuperUserSecretName: "test-cnpg-superuser-secret"
backupCronjob:
enabled: true
persistentVolumeClaim:
useExisting: false
claimName: "1337-test-cronjob-pvc"
storageRequest: "1337Gi"
storageClassName: "test-storage-class-name-for-backup-cronjob"
accessModes: ["ReadWriteOnce"]
#
asserts:
- isKind:
of: PersistentVolumeClaim

- equal:
path: metadata.name
value: "1337-test-cronjob-pvc"

- equal:
path: spec.storageClassName
value: "test-storage-class-name-for-backup-cronjob"

- equal:
path: spec.accessModes
value:
- "ReadWriteOnce"

- equal:
path: spec.resources.requests.storage
value: "1337Gi"
13 changes: 11 additions & 2 deletions charts/cnpg-cluster/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@
"timeZone": {"type": "string"},
"restartPolicy": {"type": "string"},
"containerImage": {"type": "string"},
"persistentVolumeClaimName": {"type": "string"},
"targetDatabaseHost": {"type": "string"},
"targetDatabasePort": {"type": "integer"}
"targetDatabasePort": {"type": "integer"},
"persistentVolumeClaim": {
"type": "object",
"properties": {
"useExisting": {"type": "boolean"},
"claimName": {"type": "string"},
"storageRequest": {"type": "string"},
"storageClassName": {"type": "string"},
"accessModes": {"type": "array"}
}
}
}
}
},
Expand Down
32 changes: 27 additions & 5 deletions charts/cnpg-cluster/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,36 @@ backupCronjob:
# @section -- Backup-Cronjob specifications
containerImage: "postgres:16-alpine"
#
# -- Name of existing PVC where the database-dump is being stored at
# @section -- Backup-Cronjob specifications
persistentVolumeClaimName: "cnpg-db-backup-pvc"
#
# -- Target CNPG-database Host
# @section -- Backup-Cronjob specifications
targetDatabaseHost: "cnpg-cluster-app-rw.cnpg-system"
#
# -- Target CNPG-database Port
# @section -- Backup-Cronjob specifications
targetDatabasePort: 5432
targetDatabasePort: 5432
#
persistentVolumeClaim:
#
# -- Use existing PVC and don't create new PVC-resource with the given
# `persistentVolumeClaimName`.
# @section -- Backup-Cronjob specifications
useExisting: false
#
# -- Name of PVC where the database-dump is being stored at
# @section -- Backup-Cronjob specifications
claimName: "cnpg-db-backup-pvc"
#
# -- Storage request for new created PVC.
# Gets ignored when `useExistingPVC: true`
# @section -- Backup-Cronjob specifications
storageRequest: "10Gi"
#
# -- Storage request for new created PVC.
# Gets ignored when `useExistingPVC: true`
# @section -- Backup-Cronjob specifications
storageClassName: "local-path"
#
# -- Access-modes for new created PVC.
# Gets ignored when `useExistingPVC: true`
# @section -- Backup-Cronjob specifications
accessModes: ["ReadWriteOnce"]