Skip to content

Commit

Permalink
[release-v1.58] Fix DataImportCron PVC GC race and test flakiness (ku…
Browse files Browse the repository at this point in the history
…bevirt#3063)

Manual backport of kubevirt#3057

PVC should be timestamped in creation and not only upon import
completion, as it might be mistakenly GCed. LRU sort will choose
PVC with empty timestamp as the first candidate for deletion.
The PVC will be recreated by the controller and eventually
timestamped, so this bug was hidden for a while.

Fixes CNV-36896

Signed-off-by: Arnon Gilboa <agilboa@redhat.com>
  • Loading branch information
arnongilboa authored Jan 15, 2024
1 parent 782417d commit aace807
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions pkg/controller/dataimportcron-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,7 @@ func (r *DataImportCronReconciler) newSourceDataVolume(cron *cdiv1.DataImportCro
dv.Namespace = cron.Namespace
r.setDataImportCronResourceLabels(cron, dv)
cc.AddAnnotation(dv, cc.AnnImmediateBinding, "true")
cc.AddAnnotation(dv, AnnLastUseTime, time.Now().UTC().Format(time.RFC3339Nano))
passCronAnnotationToDv(cron, dv, cc.AnnPodRetainAfterCompletion)

for _, defaultInstanceTypeLabel := range cc.DefaultInstanceTypeLabels {
Expand Down
8 changes: 5 additions & 3 deletions tests/dataimportcron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,9 +512,11 @@ var _ = Describe("DataImportCron", func() {
_, err = f.K8sClient.CoreV1().PersistentVolumeClaims(pvc.Namespace).Update(context.TODO(), pvc, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred())

pvcList, err := f.K8sClient.CoreV1().PersistentVolumeClaims(ns).List(context.TODO(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(pvcList.Items).To(HaveLen(garbageSources + 1))
Eventually(func() []corev1.PersistentVolumeClaim {
pvcList, err := f.K8sClient.CoreV1().PersistentVolumeClaims(ns).List(context.TODO(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())
return pvcList.Items
}, dataImportCronTimeout, pollingInterval).Should(HaveLen(garbageSources + 1))
case cdiv1.DataImportCronSourceFormatSnapshot:
snapshots := &snapshotv1.VolumeSnapshotList{}
err := f.CrClient.List(context.TODO(), snapshots, &client.ListOptions{Namespace: ns})
Expand Down

0 comments on commit aace807

Please sign in to comment.