diff --git a/pkg/controller/clone/csi-clone.go b/pkg/controller/clone/csi-clone.go index c47bcec6aa..cbaff4c0d5 100644 --- a/pkg/controller/clone/csi-clone.go +++ b/pkg/controller/clone/csi-clone.go @@ -108,10 +108,10 @@ func (p *CSIClonePhase) createClaim(ctx context.Context) (*corev1.PersistentVolu desiredClaim.Spec.Resources.Requests[corev1.ResourceStorage] = sourceSize cc.AddAnnotation(desiredClaim, cc.AnnPopulatorKind, cdiv1.VolumeCloneSourceRef) - cc.AddAnnotation(desiredClaim, cc.AnnExcludeFromVeleroBackup, "true") if p.OwnershipLabel != "" { AddOwnershipLabel(p.OwnershipLabel, desiredClaim, p.Owner) } + cc.AddLabel(desiredClaim, cc.LabelExcludeFromVeleroBackup, "true") if err := p.Client.Create(ctx, desiredClaim); err != nil { checkQuotaExceeded(p.Recorder, p.Owner, err) diff --git a/pkg/controller/clone/csi-clone_test.go b/pkg/controller/clone/csi-clone_test.go index 38a9c9ffd9..f755d86273 100644 --- a/pkg/controller/clone/csi-clone_test.go +++ b/pkg/controller/clone/csi-clone_test.go @@ -156,10 +156,10 @@ var _ = Describe("CSIClonePhase test", func() { Expect(pvc.Spec.DataSourceRef.Namespace).To(BeNil()) Expect(pvc.Spec.DataSourceRef.Name).To(Equal(sourceClaim.Name)) Expect(pvc.Annotations[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeCloneSourceRef)) - Expect(pvc.Annotations[cc.AnnExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvc.Spec.Resources.Requests[corev1.ResourceStorage]). To(Equal(sourceClaim.Status.Capacity[corev1.ResourceStorage])) Expect(pvc.Labels[p.OwnershipLabel]).To(Equal("uid")) + Expect(pvc.Labels[cc.LabelExcludeFromVeleroBackup]).To(Equal("true")) }) Context("with desired claim created", func() { diff --git a/pkg/controller/clone/host-clone.go b/pkg/controller/clone/host-clone.go index e5b43a7b19..11546ee44f 100644 --- a/pkg/controller/clone/host-clone.go +++ b/pkg/controller/clone/host-clone.go @@ -182,7 +182,6 @@ func (p *HostClonePhase) createClaim(ctx context.Context) (*corev1.PersistentVol cc.AddAnnotation(claim, cc.AnnPodRestarts, "0") cc.AddAnnotation(claim, cc.AnnCloneRequest, fmt.Sprintf("%s/%s", p.Namespace, p.SourceName)) cc.AddAnnotation(claim, cc.AnnPopulatorKind, cdiv1.VolumeCloneSourceRef) - cc.AddAnnotation(claim, cc.AnnExcludeFromVeleroBackup, "true") cc.AddAnnotation(claim, cc.AnnEventSourceKind, p.Owner.GetObjectKind().GroupVersionKind().Kind) cc.AddAnnotation(claim, cc.AnnEventSource, fmt.Sprintf("%s/%s", p.Owner.GetNamespace(), p.Owner.GetName())) if p.OwnershipLabel != "" { @@ -194,6 +193,7 @@ func (p *HostClonePhase) createClaim(ctx context.Context) (*corev1.PersistentVol if p.PriorityClassName != "" { cc.AddAnnotation(claim, cc.AnnPriorityClassName, p.PriorityClassName) } + cc.AddLabel(claim, cc.LabelExcludeFromVeleroBackup, "true") if err := p.Client.Create(ctx, claim); err != nil { checkQuotaExceeded(p.Recorder, p.Owner, err) diff --git a/pkg/controller/clone/host-clone_test.go b/pkg/controller/clone/host-clone_test.go index 7bd9dc0fce..ce6b5fa8ff 100644 --- a/pkg/controller/clone/host-clone_test.go +++ b/pkg/controller/clone/host-clone_test.go @@ -106,8 +106,8 @@ var _ = Describe("HostClonePhase test", func() { Expect(pvc.Annotations[cc.AnnPodRestarts]).To(Equal("0")) Expect(pvc.Annotations[cc.AnnCloneRequest]).To(Equal("ns/source")) Expect(pvc.Annotations[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeCloneSourceRef)) - Expect(pvc.Annotations[cc.AnnExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvc.Labels[p.OwnershipLabel]).To(Equal("uid")) + Expect(pvc.Labels[cc.LabelExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvc.Annotations[cc.AnnImmediateBinding]).To(Equal("")) _, ok := pvc.Annotations[cc.AnnPriorityClassName] Expect(ok).To(BeFalse()) diff --git a/pkg/controller/clone/snap-clone.go b/pkg/controller/clone/snap-clone.go index 98374d37ce..785ac77316 100644 --- a/pkg/controller/clone/snap-clone.go +++ b/pkg/controller/clone/snap-clone.go @@ -102,10 +102,10 @@ func (p *SnapshotClonePhase) createClaim(ctx context.Context, snapshot *snapshot } cc.AddAnnotation(claim, cc.AnnPopulatorKind, cdiv1.VolumeCloneSourceRef) - cc.AddAnnotation(claim, cc.AnnExcludeFromVeleroBackup, "true") if p.OwnershipLabel != "" { AddOwnershipLabel(p.OwnershipLabel, claim, p.Owner) } + cc.AddLabel(claim, cc.LabelExcludeFromVeleroBackup, "true") if err := p.Client.Create(ctx, claim); err != nil { checkQuotaExceeded(p.Recorder, p.Owner, err) diff --git a/pkg/controller/clone/snap-clone_test.go b/pkg/controller/clone/snap-clone_test.go index 83dc6d2527..4388aa02af 100644 --- a/pkg/controller/clone/snap-clone_test.go +++ b/pkg/controller/clone/snap-clone_test.go @@ -177,9 +177,9 @@ var _ = Describe("SnapshotClonePhase test", func() { Expect(pvc.Spec.DataSourceRef.Namespace).To(BeNil()) Expect(pvc.Spec.DataSourceRef.Name).To(Equal(sourceName)) Expect(pvc.Annotations[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeCloneSourceRef)) - Expect(pvc.Annotations[cc.AnnExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvc.Spec.Resources.Requests[corev1.ResourceStorage]).To(Equal(restoreSize)) Expect(pvc.Labels[p.OwnershipLabel]).To(Equal("uid")) + Expect(pvc.Labels[cc.LabelExcludeFromVeleroBackup]).To(Equal("true")) }) Context("with desired claim created", func() { diff --git a/pkg/controller/common/util.go b/pkg/controller/common/util.go index 9a7ce6d82a..48c73628dd 100644 --- a/pkg/controller/common/util.go +++ b/pkg/controller/common/util.go @@ -252,9 +252,6 @@ const ( // AnnImmediateBinding provides a const to indicate whether immediate binding should be performed on the PV (overrides global config) AnnImmediateBinding = AnnAPIGroup + "/storage.bind.immediate.requested" - //AnnExcludeFromVeleroBackup provides a const to indicate whether an object should be excluded from velero backup - AnnExcludeFromVeleroBackup = "velero.io/exclude-from-backup" - // AnnSelectedNode annotation is added to a PVC that has been triggered by scheduler to // be dynamically provisioned. Its value is the name of the selected node. AnnSelectedNode = "volume.kubernetes.io/selected-node" @@ -331,6 +328,9 @@ const ( //nolint:gosec // These are not credentials LabelDynamicCredentialSupport = "kubevirt.io/dynamic-credentials-support" + // LabelExcludeFromVeleroBackup provides a const to indicate whether an object should be excluded from velero backup + LabelExcludeFromVeleroBackup = "velero.io/exclude-from-backup" + // ProgressDone this means we are DONE ProgressDone = "100.0%" diff --git a/pkg/controller/populators/import-populator_test.go b/pkg/controller/populators/import-populator_test.go index ed3cd8df06..b9c952dbb4 100644 --- a/pkg/controller/populators/import-populator_test.go +++ b/pkg/controller/populators/import-populator_test.go @@ -268,11 +268,11 @@ var _ = Describe("Import populator tests", func() { Expect(pvcPrime.GetAnnotations()[AnnImmediateBinding]).To(Equal("")) Expect(pvcPrime.GetAnnotations()[AnnUploadRequest]).To(Equal("")) Expect(pvcPrime.GetAnnotations()[AnnPopulatorKind]).To(Equal(cdiv1.VolumeImportSourceRef)) - Expect(pvcPrime.GetAnnotations()[AnnExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvcPrime.GetAnnotations()[AnnPreallocationRequested]).To(Equal("true")) Expect(pvcPrime.GetAnnotations()[AnnEndpoint]).To(Equal("http://example.com/data")) Expect(pvcPrime.GetAnnotations()[AnnSource]).To(Equal(SourceHTTP)) Expect(pvcPrime.Annotations[key]).To(Equal(expectedValue)) + Expect(pvcPrime.GetLabels()[LabelExcludeFromVeleroBackup]).To(Equal("true")) }, Entry("No extra annotations", "", "", ""), Entry("Invalid extra annotation is not passed", "invalid", "test", ""), diff --git a/pkg/controller/populators/populator-base.go b/pkg/controller/populators/populator-base.go index 8b4364af73..6c6fd8f8aa 100644 --- a/pkg/controller/populators/populator-base.go +++ b/pkg/controller/populators/populator-base.go @@ -172,8 +172,8 @@ func (r *ReconcilerBase) getPVCPrime(pvc *corev1.PersistentVolumeClaim) (*corev1 func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, source client.Object, waitForFirstConsumer bool, updatePVCForPopulation pvcModifierFunc) (*corev1.PersistentVolumeClaim, error) { labels := make(map[string]string) labels[common.CDILabelKey] = common.CDILabelValue + labels[cc.LabelExcludeFromVeleroBackup] = "true" annotations := make(map[string]string) - annotations[cc.AnnExcludeFromVeleroBackup] = "true" annotations[cc.AnnImmediateBinding] = "" if waitForFirstConsumer { annotations[cc.AnnSelectedNode] = pvc.Annotations[cc.AnnSelectedNode] diff --git a/pkg/controller/populators/upload-populator_test.go b/pkg/controller/populators/upload-populator_test.go index 6ab29000b6..60f509d671 100644 --- a/pkg/controller/populators/upload-populator_test.go +++ b/pkg/controller/populators/upload-populator_test.go @@ -80,7 +80,7 @@ var _ = Describe("Datavolume controller reconcile loop", func() { Expect(pvcPrime.GetAnnotations()[cc.AnnContentType]).To(Equal(contentType)) Expect(pvcPrime.GetAnnotations()[cc.AnnPreallocationRequested]).To(Equal(strconv.FormatBool(preallocation))) Expect(pvcPrime.GetAnnotations()[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeUploadSourceRef)) - Expect(pvcPrime.GetAnnotations()[cc.AnnExcludeFromVeleroBackup]).To(Equal("true")) + Expect(pvcPrime.GetLabels()[cc.LabelExcludeFromVeleroBackup]).To(Equal("true")) _, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}}) Expect(err).ToNot(HaveOccurred()) @@ -329,8 +329,8 @@ var _ = Describe("Datavolume controller reconcile loop", func() { Expect(pvcPrime.GetAnnotations()[cc.AnnImmediateBinding]).To(Equal("")) Expect(pvcPrime.GetAnnotations()[cc.AnnUploadRequest]).To(Equal("")) Expect(pvcPrime.GetAnnotations()[cc.AnnPopulatorKind]).To(Equal(cdiv1.VolumeUploadSourceRef)) - Expect(pvcPrime.GetAnnotations()[cc.AnnExcludeFromVeleroBackup]).To(Equal("true")) Expect(pvcPrime.Annotations[key]).To(Equal(expectedValue)) + Expect(pvcPrime.GetLabels()[cc.LabelExcludeFromVeleroBackup]).To(Equal("true")) }, Entry("No extra annotations", "", "", ""), Entry("Invalid extra annotation is not passed", "invalid", "test", ""),