Skip to content
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

Bug Fix: namespaceOverride template error in Scheduled Backups #471

Merged
merged 5 commits into from
Dec 17, 2024
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
2 changes: 1 addition & 1 deletion charts/cluster/templates/scheduled-backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: batch/v1
kind: Job
metadata:
name: minio-cleanup
status:
succeeded: 1
16 changes: 16 additions & 0 deletions charts/cluster/test/scheduledbackups/00-minio_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

27 changes: 27 additions & 0 deletions charts/cluster/test/scheduledbackups/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -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