Skip to content

Commit

Permalink
Merge pull request #635 from k8up-io/fix/missing_tags
Browse files Browse the repository at this point in the history
Fix tags not being applied to restic snapshots
  • Loading branch information
Kidswiss authored Apr 6, 2022
2 parents 70746ef + 1c5e7b5 commit d2e1d4b
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 12 deletions.
14 changes: 13 additions & 1 deletion config/samples/deployments/mariadb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ metadata:
labels:
app: mariadb
name: mariadb
namespace: myproject
spec:
progressDeadlineSeconds: 600
replicas: 1
Expand Down Expand Up @@ -49,3 +48,16 @@ spec:
- name: mariadb
persistentVolumeClaim:
claimName: mariadb

---

kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mariadb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
11 changes: 11 additions & 0 deletions config/samples/deployments/mongodb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ spec:
- name: mongodb
persistentVolumeClaim:
claimName: mongodb
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mongodb
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
2 changes: 1 addition & 1 deletion config/samples/deployments/pv-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spec:
storage: 5Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
- ReadWriteOnce
persistentVolumeReclaimPolicy: Delete
storageClassName: slow
hostPath:
Expand Down
8 changes: 3 additions & 5 deletions config/samples/deployments/pvc-example.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions config/samples/k8up_v1_backup.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ 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
key: username
secretAccessKeySecretRef:
name: backup-credentials
key: password
promURL: http://10.144.1.224:9000
promURL: http://10.144.13.4:9000
4 changes: 2 additions & 2 deletions config/samples/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ metadata:
name: backup-credentials
type: Opaque
stringData:
username: 8U0UDNYPNUDTUS1LIAF3
password: ip3cdrkXcHmH4S7if7erKPNoxDn27V0vrg6CHHem
username: minioadmin
password: minioadmin
---
apiVersion: v1
kind: Secret
Expand Down
7 changes: 7 additions & 0 deletions controllers/backup_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
15 changes: 15 additions & 0 deletions controllers/backup_it_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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")
}
1 change: 1 addition & 0 deletions operator/executor/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion operator/executor/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d2e1d4b

Please sign in to comment.