diff --git a/charts/cluster/Chart.yaml b/charts/cluster/Chart.yaml index c82d21958..1f686557f 100644 --- a/charts/cluster/Chart.yaml +++ b/charts/cluster/Chart.yaml @@ -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.1.2 +version: 0.1.3 sources: - https://github.com/cloudnative-pg/charts keywords: diff --git a/charts/cluster/README.md b/charts/cluster/README.md index b1d1c66d2..8e8279e66 100644 --- a/charts/cluster/README.md +++ b/charts/cluster/README.md @@ -1,6 +1,6 @@ # cluster -![Version: 0.1.2](https://img.shields.io/badge/Version-0.1.2-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) +![Version: 0.1.3](https://img.shields.io/badge/Version-0.1.3-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) > **Warning** > ### This chart is under active development. diff --git a/charts/cluster/templates/scheduled-backups.yaml b/charts/cluster/templates/scheduled-backups.yaml index 5cd10c043..47a0717d6 100644 --- a/charts/cluster/templates/scheduled-backups.yaml +++ b/charts/cluster/templates/scheduled-backups.yaml @@ -6,7 +6,7 @@ apiVersion: postgresql.cnpg.io/v1 kind: ScheduledBackup metadata: name: {{ include "cluster.fullname" $context }}-{{ .name }} - namespace: {{ include "cluster.namespace" . }} + namespace: {{ include "cluster.namespace" $ }} labels: {{ include "cluster.labels" $context | nindent 4 }} spec: immediate: true diff --git a/charts/cluster/test/scheduledbackups/00-minio_cleanup-assert.yaml b/charts/cluster/test/scheduledbackups/00-minio_cleanup-assert.yaml new file mode 100644 index 000000000..9c0f3eb48 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/00-minio_cleanup-assert.yaml @@ -0,0 +1,6 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: minio-cleanup +status: + succeeded: 1 diff --git a/charts/cluster/test/scheduledbackups/00-minio_cleanup.yaml b/charts/cluster/test/scheduledbackups/00-minio_cleanup.yaml new file mode 100644 index 000000000..90151a964 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/00-minio_cleanup.yaml @@ -0,0 +1,16 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: minio-cleanup +spec: + template: + spec: + restartPolicy: OnFailure + containers: + - name: minio-cleanup + image: minio/mc + command: ['sh', '-c'] + args: + - | + mc alias set myminio https://minio.minio.svc.cluster.local minio minio123 + mc rm --recursive --force myminio/mybucket/scheduledbackups diff --git a/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml new file mode 100644 index 000000000..a3af1a25b --- /dev/null +++ b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml @@ -0,0 +1,37 @@ +apiVersion: postgresql.cnpg.io/v1 +kind: Cluster +metadata: + name: scheduledbackups-cluster +status: + readyInstances: 1 +--- +apiVersion: postgresql.cnpg.io/v1 +kind: ScheduledBackup +metadata: + name: scheduledbackups-cluster-daily-backup +spec: + immediate: true + schedule: "0 0 0 * * *" + method: barmanObjectStore + backupOwnerReference: self + cluster: + name: scheduledbackups-cluster +--- +apiVersion: postgresql.cnpg.io/v1 +kind: ScheduledBackup +metadata: + name: scheduledbackups-cluster-weekly-backup +spec: + immediate: true + schedule: "0 0 0 * * 1" + method: barmanObjectStore + backupOwnerReference: self + cluster: + name: scheduledbackups-cluster +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Backup +spec: + method: barmanObjectStore + cluster: + name: scheduledbackups-cluster diff --git a/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster.yaml b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster.yaml new file mode 100644 index 000000000..c5ea25be6 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster.yaml @@ -0,0 +1,36 @@ +type: postgresql +mode: standalone + +cluster: + instances: 1 + storage: + size: 256Mi + +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: "/scheduledbackups/v1" + accessKey: "minio" + secretKey: "minio123" + region: "local" + retentionPolicy: "30d" + scheduledBackups: + - name: daily-backup + schedule: "0 0 0 * * *" + backupOwnerReference: self + method: barmanObjectStore + - name: weekly-backup + schedule: "0 0 0 * * 1" + backupOwnerReference: self + method: barmanObjectStore + diff --git a/charts/cluster/test/scheduledbackups/chainsaw-test.yaml b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml new file mode 100644 index 000000000..986e9cea1 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml @@ -0,0 +1,27 @@ +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: scheduledbackups +spec: + timeouts: + apply: 1s + assert: 1m + cleanup: 1m + steps: + - name: Install the a cluster with ScheduledBackups + try: + - script: + content: | + helm upgrade \ + --install \ + --namespace $NAMESPACE \ + --values ./01-scheduledbackups_cluster.yaml \ + --wait \ + scheduledbackups ../../ + - assert: + file: ./01-scheduledbackups_cluster-assert.yaml + - name: Cleanup + try: + - script: + content: | + helm uninstall --namespace $NAMESPACE scheduledbackups