From 3f24feba373e80ecb95e9050ff00305bcdbc272b Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Fri, 1 Apr 2022 14:35:59 +0200 Subject: [PATCH 1/3] Adjust samples, so they work with KIND Signed-off-by: Simon Beck --- config/samples/deployments/mariadb.yaml | 14 +++++++++++++- config/samples/deployments/mongodb.yaml | 11 +++++++++++ config/samples/deployments/pv-example.yaml | 2 +- config/samples/deployments/pvc-example.yaml | 8 +++----- config/samples/k8up_v1_backup.yaml | 8 ++++++-- config/samples/secrets.yaml | 4 ++-- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/config/samples/deployments/mariadb.yaml b/config/samples/deployments/mariadb.yaml index bf0fff508..a532c0891 100644 --- a/config/samples/deployments/mariadb.yaml +++ b/config/samples/deployments/mariadb.yaml @@ -4,7 +4,6 @@ metadata: labels: app: mariadb name: mariadb - namespace: myproject spec: progressDeadlineSeconds: 600 replicas: 1 @@ -49,3 +48,16 @@ spec: - name: mariadb persistentVolumeClaim: claimName: mariadb + +--- + +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: mariadb +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/config/samples/deployments/mongodb.yaml b/config/samples/deployments/mongodb.yaml index cf0f088f2..071a62b1c 100644 --- a/config/samples/deployments/mongodb.yaml +++ b/config/samples/deployments/mongodb.yaml @@ -50,3 +50,14 @@ spec: - name: mongodb persistentVolumeClaim: claimName: mongodb +--- +kind: PersistentVolumeClaim +apiVersion: v1 +metadata: + name: mongodb +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi diff --git a/config/samples/deployments/pv-example.yaml b/config/samples/deployments/pv-example.yaml index adc7dfb55..b203abcd2 100644 --- a/config/samples/deployments/pv-example.yaml +++ b/config/samples/deployments/pv-example.yaml @@ -7,7 +7,7 @@ spec: storage: 5Gi volumeMode: Filesystem accessModes: - - ReadWriteMany + - ReadWriteOnce persistentVolumeReclaimPolicy: Delete storageClassName: slow hostPath: diff --git a/config/samples/deployments/pvc-example.yaml b/config/samples/deployments/pvc-example.yaml index b71db084f..52ab422eb 100644 --- a/config/samples/deployments/pvc-example.yaml +++ b/config/samples/deployments/pvc-example.yaml @@ -1,15 +1,13 @@ kind: PersistentVolumeClaim apiVersion: v1 metadata: - name: myclaim annotations: k8up.io/backup: 'true' - namespace: myproject + name: myclaim spec: accessModes: - - ReadWriteMany - # volumeMode: Filesystem + # So it works in KIND + - ReadWriteOnce resources: requests: storage: 1Gi - # storageClassName: slow diff --git a/config/samples/k8up_v1_backup.yaml b/config/samples/k8up_v1_backup.yaml index 52b3340ff..27b647461 100644 --- a/config/samples/k8up_v1_backup.yaml +++ b/config/samples/k8up_v1_backup.yaml @@ -5,12 +5,16 @@ metadata: spec: failedJobsHistoryLimit: 2 successfulJobsHistoryLimit: 2 + tags: + - test + - dump + - mariadb backend: repoPasswordSecretRef: name: backup-repo key: password s3: - endpoint: http://10.144.1.224:9000 + endpoint: http://10.144.13.4:9000 bucket: k8up accessKeyIDSecretRef: name: backup-credentials @@ -18,4 +22,4 @@ spec: secretAccessKeySecretRef: name: backup-credentials key: password - promURL: http://10.144.1.224:9000 + promURL: http://10.144.13.4:9000 diff --git a/config/samples/secrets.yaml b/config/samples/secrets.yaml index 4333de937..30285caa9 100644 --- a/config/samples/secrets.yaml +++ b/config/samples/secrets.yaml @@ -4,8 +4,8 @@ metadata: name: backup-credentials type: Opaque stringData: - username: 8U0UDNYPNUDTUS1LIAF3 - password: ip3cdrkXcHmH4S7if7erKPNoxDn27V0vrg6CHHem + username: minioadmin + password: minioadmin --- apiVersion: v1 kind: Secret From b9edc548a5ada2e7093107d4626a852274d29324 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Fri, 1 Apr 2022 14:36:34 +0200 Subject: [PATCH 2/3] Add the tags to the argumentlist Signed-off-by: Simon Beck --- operator/executor/backup.go | 1 + operator/executor/prune.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/operator/executor/backup.go b/operator/executor/backup.go index bed5c9773..eb9f18141 100644 --- a/operator/executor/backup.go +++ b/operator/executor/backup.go @@ -126,6 +126,7 @@ func (b *BackupExecutor) startBackup(backupJob *batchv1.Job) error { backupJob.Spec.Template.Spec.Volumes = volumes backupJob.Spec.Template.Spec.ServiceAccountName = cfg.Config.ServiceAccount backupJob.Spec.Template.Spec.Containers[0].VolumeMounts = b.newVolumeMounts(volumes) + backupJob.Spec.Template.Spec.Containers[0].Args = BuildTagArgs(b.backup.Spec.Tags) if err = b.CreateObjectIfNotExisting(backupJob); err == nil { b.SetStarted("the job '%v/%v' was created", backupJob.Namespace, backupJob.Name) diff --git a/operator/executor/prune.go b/operator/executor/prune.go index 605734222..50c3ce0bf 100644 --- a/operator/executor/prune.go +++ b/operator/executor/prune.go @@ -66,7 +66,7 @@ func (p *PruneExecutor) startPrune(pruneJob *batchv1.Job, prune *k8upv1.Prune) { p.RegisterJobSucceededConditionCallback() pruneJob.Spec.Template.Spec.Containers[0].Env = p.setupEnvVars(prune) - pruneJob.Spec.Template.Spec.Containers[0].Args = []string{"-prune"} + pruneJob.Spec.Template.Spec.Containers[0].Args = append([]string{"-prune"}, BuildTagArgs(prune.Spec.Retention.Tags)...) if err := p.Client.Create(p.CTX, pruneJob); err != nil { if !apierrors.IsAlreadyExists(err) { From 1c5e7b5198b199dae83f213c5647a8698dd5f922 Mon Sep 17 00:00:00 2001 From: Simon Beck Date: Wed, 6 Apr 2022 09:31:14 +0200 Subject: [PATCH 3/3] Add integration tests Signed-off-by: Simon Beck --- controllers/backup_integration_test.go | 7 +++++++ controllers/backup_it_utils_test.go | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/controllers/backup_integration_test.go b/controllers/backup_integration_test.go index 2910e63c8..173f60be1 100644 --- a/controllers/backup_integration_test.go +++ b/controllers/backup_integration_test.go @@ -141,3 +141,10 @@ func (ts *BackupTestSuite) Test_GivenFailedBackup_WhenReconciling_ThenIgnore() { result := ts.whenReconciling(ts.BackupResource) ts.Assert().Equal(float64(0), result.RequeueAfter.Seconds()) } + +func (ts *BackupTestSuite) Test_GivenBackupWithTags_WhenCreatingBackupjob_ThenHaveTagArguments() { + ts.EnsureResources(ts.newBackupWithTags()) + ts.whenReconciling(ts.BackupResource) + job := ts.expectABackupJobEventually() + ts.assertJobHasTagArguments(job) +} diff --git a/controllers/backup_it_utils_test.go b/controllers/backup_it_utils_test.go index 203243a8d..411d8e1ba 100644 --- a/controllers/backup_it_utils_test.go +++ b/controllers/backup_it_utils_test.go @@ -24,6 +24,10 @@ import ( k8upObserver "github.com/k8up-io/k8up/operator/observer" ) +const ( + backupTag = "integrationTag" +) + func (ts *BackupTestSuite) newPreBackupPod() *k8upv1.PreBackupPod { return &k8upv1.PreBackupPod{ Spec: k8upv1.PreBackupPodSpec{ @@ -285,3 +289,14 @@ func (ts *BackupTestSuite) notifyObserverOfBackupJobStatusChange(status k8upObse event.Event = status observer.GetUpdateChannel() <- event } + +func (ts *BackupTestSuite) newBackupWithTags() *k8upv1.Backup { + backupWithTags := ts.newBackup() + backupWithTags.Spec.Tags = []string{backupTag} + return backupWithTags +} + +func (ts *BackupTestSuite) assertJobHasTagArguments(job *batchv1.Job) { + jobArguments := job.Spec.Template.Spec.Containers[0].Args + ts.Assert().Contains(jobArguments, backupTag, "backup tag in job args") +}