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

Populators: Add to PVC' exclude velero backup annotation #3500

Merged
merged 1 commit into from
Nov 4, 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
1 change: 1 addition & 0 deletions pkg/controller/clone/csi-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ 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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/clone/csi-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ 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"))
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/clone/host-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ 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 != "" {
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/clone/host-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ 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.Annotations[cc.AnnImmediateBinding]).To(Equal(""))
_, ok := pvc.Annotations[cc.AnnPriorityClassName]
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/clone/snap-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ 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)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/clone/snap-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ 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"))
})
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@ 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"
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/populators/import-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ 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))
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/populators/populator-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (r *ReconcilerBase) createPVCPrime(pvc *corev1.PersistentVolumeClaim, sourc
labels := make(map[string]string)
labels[common.CDILabelKey] = common.CDILabelValue
annotations := make(map[string]string)
annotations[cc.AnnExcludeFromVeleroBackup] = "true"
annotations[cc.AnnImmediateBinding] = ""
if waitForFirstConsumer {
annotations[cc.AnnSelectedNode] = pvc.Annotations[cc.AnnSelectedNode]
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/populators/upload-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +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"))

_, err = r.Reconcile(context.TODO(), reconcile.Request{NamespacedName: types.NamespacedName{Name: "test-pvc", Namespace: metav1.NamespaceDefault}})
Expect(err).ToNot(HaveOccurred())
Expand Down Expand Up @@ -328,6 +329,7 @@ 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))
},
Entry("No extra annotations", "", "", ""),
Expand Down