From 1fe542cb10f93b9642c5224df9145d0fb269ba8c Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Tue, 17 Dec 2024 19:21:37 +0200 Subject: [PATCH 1/5] Added Scheduled Backups test Signed-off-by: Itay Grudev --- .../00-minio_cleanup-assert.yaml | 6 ++++ .../scheduledbackups/00-minio_cleanup.yaml | 16 +++++++++ .../01-scheduledbackups_cluster-assert.yaml | 30 ++++++++++++++++ .../01-scheduledbackups_cluster.yaml | 36 +++++++++++++++++++ .../test/scheduledbackups/chainsaw-test.yaml | 30 ++++++++++++++++ 5 files changed, 118 insertions(+) create mode 100644 charts/cluster/test/scheduledbackups/00-minio_cleanup-assert.yaml create mode 100644 charts/cluster/test/scheduledbackups/00-minio_cleanup.yaml create mode 100644 charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml create mode 100644 charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster.yaml create mode 100644 charts/cluster/test/scheduledbackups/chainsaw-test.yaml 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..b3e09d1e9 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml @@ -0,0 +1,30 @@ +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 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..71bc83ff1 --- /dev/null +++ b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml @@ -0,0 +1,30 @@ +## +# This is a test that verifies that non-default configuration options are correctly propagated to the CNPG cluster. +# P.S. This test is not designed to have a good running configuration, it is designed to test the configuration propagation! +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: postgresql-cluster-configuration +spec: + timeouts: + apply: 1s + assert: 60s + cleanup: 30s + steps: + - name: Install the non-default configuration cluster + 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 From c4965a480f42361df99593fe839e4b12e5f89462 Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Tue, 17 Dec 2024 19:23:30 +0200 Subject: [PATCH 2/5] Bug Fix: Scheduled backups namespace template issue Signed-off-by: Itay Grudev --- charts/cluster/templates/scheduled-backups.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b416eef7a4ef1d51579aa8186fd992375fb4868f Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Tue, 17 Dec 2024 19:29:27 +0200 Subject: [PATCH 3/5] Incorrect test case name and description Signed-off-by: Itay Grudev --- charts/cluster/test/scheduledbackups/chainsaw-test.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/charts/cluster/test/scheduledbackups/chainsaw-test.yaml b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml index 71bc83ff1..66c2200fe 100644 --- a/charts/cluster/test/scheduledbackups/chainsaw-test.yaml +++ b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml @@ -1,17 +1,14 @@ -## -# This is a test that verifies that non-default configuration options are correctly propagated to the CNPG cluster. -# P.S. This test is not designed to have a good running configuration, it is designed to test the configuration propagation! apiVersion: chainsaw.kyverno.io/v1alpha1 kind: Test metadata: - name: postgresql-cluster-configuration + name: scheduledbackups spec: timeouts: apply: 1s assert: 60s cleanup: 30s steps: - - name: Install the non-default configuration cluster + - name: Install the a cluster with ScheduledBackups try: - script: content: | From 45356a471b22f8cd45a45dc35b25b5467b9aa1fb Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Tue, 17 Dec 2024 19:38:13 +0200 Subject: [PATCH 4/5] Testing whether the immediate backup results in creating a Backup resource Signed-off-by: Itay Grudev --- .../01-scheduledbackups_cluster-assert.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml index b3e09d1e9..a3af1a25b 100644 --- a/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml +++ b/charts/cluster/test/scheduledbackups/01-scheduledbackups_cluster-assert.yaml @@ -28,3 +28,10 @@ spec: backupOwnerReference: self cluster: name: scheduledbackups-cluster +--- +apiVersion: postgresql.cnpg.io/v1 +kind: Backup +spec: + method: barmanObjectStore + cluster: + name: scheduledbackups-cluster From ff409bb9de59760a4c7b1f64fd18969e01ed01ac Mon Sep 17 00:00:00 2001 From: Itay Grudev Date: Tue, 17 Dec 2024 19:38:21 +0200 Subject: [PATCH 5/5] Increased cleanup time Signed-off-by: Itay Grudev --- charts/cluster/test/scheduledbackups/chainsaw-test.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/charts/cluster/test/scheduledbackups/chainsaw-test.yaml b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml index 66c2200fe..986e9cea1 100644 --- a/charts/cluster/test/scheduledbackups/chainsaw-test.yaml +++ b/charts/cluster/test/scheduledbackups/chainsaw-test.yaml @@ -5,8 +5,8 @@ metadata: spec: timeouts: apply: 1s - assert: 60s - cleanup: 30s + assert: 1m + cleanup: 1m steps: - name: Install the a cluster with ScheduledBackups try: