Skip to content

Commit

Permalink
Populators: Add to PVC' exclude velero backup label (kubevirt#3524)
Browse files Browse the repository at this point in the history
When backing up with Velero if a PVC is terminating
then the backup is marked as PartiallyFailed, while the
backup is still valid to use and its more of a warning,
PVC' should be transparent to the user so have the backup
partiallyFailed because of PVC' is a bad user experience.
To fix that added to all our PVC' an label so it will be
excluded from the Velero backup.
This is a fix for previous PR
kubevirt#3500
Which added an annotation instead of label by accident.

Signed-off-by: Shelly Kagan <[email protected]>
Co-authored-by: Shelly Kagan <[email protected]>
  • Loading branch information
kubevirt-bot and ShellyKa13 authored Nov 11, 2024
1 parent cb4dded commit 7d62839
Show file tree
Hide file tree
Showing 10 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/clone/csi-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clone/csi-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clone/host-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clone/host-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clone/snap-clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/clone/snap-clone_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -330,6 +327,9 @@ const (
// LabelDynamicCredentialSupport specifies if the OS supports updating credentials at runtime.
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%"

Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/populators/import-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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", ""),
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/populators/populator-base.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,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]
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/populators/upload-populator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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", ""),
Expand Down

0 comments on commit 7d62839

Please sign in to comment.