From 7be70a0391dc1e3cac723a33b48a59159e798d2c Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Thu, 13 Jun 2024 21:33:06 +0200 Subject: [PATCH 1/3] Make log messages more explicit Signed-off-by: Johannes Bornhold --- operator/backupcontroller/executor.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/backupcontroller/executor.go b/operator/backupcontroller/executor.go index 3744e58f3..d6371403b 100644 --- a/operator/backupcontroller/executor.go +++ b/operator/backupcontroller/executor.go @@ -91,7 +91,7 @@ func (b *BackupExecutor) listAndFilterPVCs(ctx context.Context, annotation strin for _, pvc := range claimlist.Items { if pvc.Status.Phase != corev1.ClaimBound { - log.Info("PVC is not bound", "pvc", pvc.GetName()) + log.Info("PVC is not bound, skipping PVC", "pvc", pvc.GetName()) continue } @@ -99,7 +99,7 @@ func (b *BackupExecutor) listAndFilterPVCs(ctx context.Context, annotation strin isRWO := containsAccessMode(pvc.Spec.AccessModes, corev1.ReadWriteOnce) if !containsAccessMode(pvc.Spec.AccessModes, corev1.ReadWriteMany) && !isRWO && !hasBackupAnnotation { - log.Info("PVC is neither RWX nor RWO and has no backup annotation", "pvc", pvc.GetName()) + log.Info("PVC is neither RWX nor RWO and has no backup annotation, skipping PVC", "pvc", pvc.GetName()) continue } From 18e11b81220a46a1982c1869565b05295d767fa7 Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Thu, 13 Jun 2024 22:20:02 +0200 Subject: [PATCH 2/3] Add integration test for RWO PVC without NodeAffinity Signed-off-by: Johannes Bornhold --- .../controller_integration_test.go | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/operator/backupcontroller/controller_integration_test.go b/operator/backupcontroller/controller_integration_test.go index 755f88b39..1aaaad1c3 100644 --- a/operator/backupcontroller/controller_integration_test.go +++ b/operator/backupcontroller/controller_integration_test.go @@ -14,6 +14,7 @@ import ( batchv1 "k8s.io/api/batch/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" + "k8s.io/apimachinery/pkg/api/resource" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/labels" "k8s.io/apimachinery/pkg/types" @@ -457,6 +458,42 @@ func (ts *BackupTestSuite) Test_GivenBackupAndUnmountedRWOPVCOnTwoNodes_ExpectBa ts.assertJobSpecs(&job2, nodeNamePv2, []corev1.Volume{volumePvc2}, nil, []string{}) } +func (ts *BackupTestSuite) Test_GivenBackupAndUnmountedRWOPVC_ExpectBackup() { + pvc1 := ts.newPvc("test-pvc-without-node-affinity", corev1.ReadWriteOnce) + pv1 := &corev1.PersistentVolume{ + ObjectMeta: metav1.ObjectMeta{ + Name: "test-pvc-without-node-affinity", + }, + Spec: corev1.PersistentVolumeSpec{ + AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce}, + Capacity: map[corev1.ResourceName]resource.Quantity{ + corev1.ResourceStorage: resource.MustParse("1Mi"), + }, + PersistentVolumeSource: corev1.PersistentVolumeSource{ + HostPath: &corev1.HostPathVolumeSource{Path: "/tmp/integration-tests"}, + }, + }, + } + volumePvc1 := corev1.Volume{ + Name: "test-pvc-without-node-affinity", + VolumeSource: corev1.VolumeSource{ + PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{ + ClaimName: pvc1.Name, + }, + }, + } + ts.EnsureResources(ts.BackupResource, pvc1, pv1) + + pvc1.Status.Phase = corev1.ClaimBound + ts.UpdateStatus(pvc1) + + ts.whenReconciling(ts.BackupResource) + job := ts.expectABackupJob() + + ts.Assert().Nil(job.Spec.Template.Spec.NodeSelector) + ts.Assert().Equal(volumePvc1.VolumeSource.PersistentVolumeClaim.ClaimName, job.Spec.Template.Spec.Volumes[0].VolumeSource.PersistentVolumeClaim.ClaimName) +} + func (ts *BackupTestSuite) Test_GivenBackupAndRWOPVCWithFinishedPod_ExpectFinishedPodToBeIgnored() { pvc1 := ts.newPvc("test-pvc1", corev1.ReadWriteOnce) nodeNamePod1 := "worker" From fa178ece8221e4b904c8dd18ed265c1eb176bdfd Mon Sep 17 00:00:00 2001 From: Johannes Bornhold Date: Thu, 13 Jun 2024 22:22:28 +0200 Subject: [PATCH 3/3] Also add RWO PVC without NodeAffinity from its PV Signed-off-by: Johannes Bornhold --- operator/backupcontroller/executor.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/operator/backupcontroller/executor.go b/operator/backupcontroller/executor.go index d6371403b..c89553e53 100644 --- a/operator/backupcontroller/executor.go +++ b/operator/backupcontroller/executor.go @@ -143,8 +143,7 @@ func (b *BackupExecutor) listAndFilterPVCs(ctx context.Context, annotation strin bi.node = findNode(pv, pvc) if bi.node == "" { - log.Info("RWO PVC not bound and no PV node affinity set, skipping", "pvc", pvc.GetName(), "affinity", pv.Spec.NodeAffinity) - continue + log.Info("RWO PVC not bound and no PV node affinity set, adding", "pvc", pvc.GetName(), "affinity", pv.Spec.NodeAffinity) } log.V(1).Info("node found in PV or PVC", "pvc", pvc.GetName(), "node", bi.node) } else {